Skip to content

Commit 50b9694

Browse files
Rollup merge of #54299 - snaedis:issue-54246, r=varkor
Issue 54246 I added the option of providing a help message for deprecated features, that takes precedence over the default `help: remove this attribute` message, along with messages for the features that mention replacements in the reason for deprecation. Fixes #54246.
2 parents 5f1a123 + 79da7a0 commit 50b9694

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl EarlyLintPass for DeprecatedAttr {
783783
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
784784
for &&(n, _, ref g) in &self.depr_attrs {
785785
if attr.name() == n {
786-
if let &AttributeGate::Gated(Stability::Deprecated(link),
786+
if let &AttributeGate::Gated(Stability::Deprecated(link, suggestion),
787787
ref name,
788788
ref reason,
789789
_) = g {
@@ -792,7 +792,7 @@ impl EarlyLintPass for DeprecatedAttr {
792792
let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);
793793
err.span_suggestion_short_with_applicability(
794794
attr.span,
795-
"remove this attribute",
795+
suggestion.unwrap_or("remove this attribute"),
796796
String::new(),
797797
Applicability::MachineApplicable
798798
);

src/libsyntax/feature_gate.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ pub enum AttributeGate {
711711
impl AttributeGate {
712712
fn is_deprecated(&self) -> bool {
713713
match *self {
714-
Gated(Stability::Deprecated(_), ..) => true,
714+
Gated(Stability::Deprecated(_, _), ..) => true,
715715
_ => false,
716716
}
717717
}
@@ -720,8 +720,9 @@ impl AttributeGate {
720720
#[derive(Copy, Clone, Debug)]
721721
pub enum Stability {
722722
Unstable,
723-
// Argument is tracking issue link.
724-
Deprecated(&'static str),
723+
// First argument is tracking issue link; second argument is an optional
724+
// help message, which defaults to "remove this attribute"
725+
Deprecated(&'static str, Option<&'static str>),
725726
}
726727

727728
// fn() is not Debug
@@ -1048,7 +1049,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
10481049
("no_builtins", Whitelisted, Ungated),
10491050
("no_mangle", Whitelisted, Ungated),
10501051
("no_debug", Whitelisted, Gated(
1051-
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721"),
1052+
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721", None),
10521053
"no_debug",
10531054
"the `#[no_debug]` attribute was an experimental feature that has been \
10541055
deprecated due to lack of demand",
@@ -1061,7 +1062,8 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
10611062
cfg_fn!(omit_gdb_pretty_printer_section))),
10621063
("unsafe_destructor_blind_to_params",
10631064
Normal,
1064-
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761"),
1065+
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761",
1066+
Some("replace this attribute with `#[may_dangle]`")),
10651067
"dropck_parametricity",
10661068
"unsafe_destructor_blind_to_params has been replaced by \
10671069
may_dangle and will be removed in the future",
@@ -1140,9 +1142,10 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
11401142
("panic_implementation",
11411143
Normal,
11421144
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\
1143-
#issuecomment-415140224"),
1145+
#issuecomment-415140224",
1146+
Some("replace this attribute with `#[panic_handler]`")),
11441147
"panic_implementation",
1145-
"This attribute was renamed to `panic_handler`",
1148+
"this attribute was renamed to `panic_handler`",
11461149
cfg_fn!(panic_implementation))),
11471150

11481151
// RFC 2070

src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: use of deprecated attribute `dropck_parametricity`: unsafe_destructor_bli
22
--> $DIR/feature-gate-dropck-ugeh-2.rs:17:5
33
|
44
LL | #[unsafe_destructor_blind_to_params]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[may_dangle]`
66
|
77
note: lint level defined here
88
--> $DIR/feature-gate-dropck-ugeh-2.rs:11:9

src/test/ui/feature-gates/feature-gate-panic-implementation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use core::panic::PanicInfo;
1717

18-
#[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
18+
#[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489)
1919
fn panic(info: &PanicInfo) -> ! {
2020
loop {}
2121
}

src/test/ui/feature-gates/feature-gate-panic-implementation.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error[E0658]: This attribute was renamed to `panic_handler` (see issue #44489)
1+
error[E0658]: this attribute was renamed to `panic_handler` (see issue #44489)
22
--> $DIR/feature-gate-panic-implementation.rs:18:1
33
|
4-
LL | #[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
4+
LL | #[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489)
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(panic_implementation)] to the crate attributes to enable

src/test/ui/panic-implementation/panic-implementation-deprecated.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: use of deprecated attribute `panic_implementation`: This attribute was renamed to `panic_handler`. See https://github.com/rust-lang/rust/issues/44489#issuecomment-415140224
1+
error: use of deprecated attribute `panic_implementation`: this attribute was renamed to `panic_handler`. See https://github.com/rust-lang/rust/issues/44489#issuecomment-415140224
22
--> $DIR/panic-implementation-deprecated.rs:19:1
33
|
44
LL | #[panic_implementation]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[panic_handler]`
66
|
77
note: lint level defined here
88
--> $DIR/panic-implementation-deprecated.rs:13:9

0 commit comments

Comments
 (0)