Skip to content

Commit 79da7a0

Browse files
author
Alva Snædís
committed
libsyntax: add optional help message for deprecated features
1 parent e4e4039 commit 79da7a0

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
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

+9-6
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
@@ -1044,7 +1045,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
10441045
("no_builtins", Whitelisted, Ungated),
10451046
("no_mangle", Whitelisted, Ungated),
10461047
("no_debug", Whitelisted, Gated(
1047-
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721"),
1048+
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721", None),
10481049
"no_debug",
10491050
"the `#[no_debug]` attribute was an experimental feature that has been \
10501051
deprecated due to lack of demand",
@@ -1057,7 +1058,8 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
10571058
cfg_fn!(omit_gdb_pretty_printer_section))),
10581059
("unsafe_destructor_blind_to_params",
10591060
Normal,
1060-
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761"),
1061+
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761",
1062+
Some("replace this attribute with `#[may_dangle]`")),
10611063
"dropck_parametricity",
10621064
"unsafe_destructor_blind_to_params has been replaced by \
10631065
may_dangle and will be removed in the future",
@@ -1136,7 +1138,8 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
11361138
("panic_implementation",
11371139
Normal,
11381140
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\
1139-
#issuecomment-415140224"),
1141+
#issuecomment-415140224",
1142+
Some("replace this attribute with `#[panic_handler]`")),
11401143
"panic_implementation",
11411144
"this attribute was renamed to `panic_handler`",
11421145
cfg_fn!(panic_implementation))),

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/panic-implementation/panic-implementation-deprecated.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: use of deprecated attribute `panic_implementation`: this attribute was re
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)