From e4e4039c5b70807edfe41f6511b56520b3786ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alva=20Sn=C3=A6d=C3=ADs?= Date: Mon, 17 Sep 2018 03:38:15 +0000 Subject: [PATCH 1/2] libsyntax: fix casing in error message --- src/libsyntax/feature_gate.rs | 2 +- .../ui/feature-gates/feature-gate-panic-implementation.rs | 2 +- .../ui/feature-gates/feature-gate-panic-implementation.stderr | 4 ++-- .../panic-implementation-deprecated.stderr | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 7266d807d3ba8..603dfad38eb19 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1138,7 +1138,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\ #issuecomment-415140224"), "panic_implementation", - "This attribute was renamed to `panic_handler`", + "this attribute was renamed to `panic_handler`", cfg_fn!(panic_implementation))), // RFC 2070 diff --git a/src/test/ui/feature-gates/feature-gate-panic-implementation.rs b/src/test/ui/feature-gates/feature-gate-panic-implementation.rs index 84e5f302c1676..ca51154884f12 100644 --- a/src/test/ui/feature-gates/feature-gate-panic-implementation.rs +++ b/src/test/ui/feature-gates/feature-gate-panic-implementation.rs @@ -15,7 +15,7 @@ use core::panic::PanicInfo; -#[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489) +#[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489) fn panic(info: &PanicInfo) -> ! { loop {} } diff --git a/src/test/ui/feature-gates/feature-gate-panic-implementation.stderr b/src/test/ui/feature-gates/feature-gate-panic-implementation.stderr index 926a49ae83199..a54780468c42d 100644 --- a/src/test/ui/feature-gates/feature-gate-panic-implementation.stderr +++ b/src/test/ui/feature-gates/feature-gate-panic-implementation.stderr @@ -1,7 +1,7 @@ -error[E0658]: This attribute was renamed to `panic_handler` (see issue #44489) +error[E0658]: this attribute was renamed to `panic_handler` (see issue #44489) --> $DIR/feature-gate-panic-implementation.rs:18:1 | -LL | #[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489) +LL | #[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489) | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(panic_implementation)] to the crate attributes to enable diff --git a/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr b/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr index 43f51447ac46e..c869dddb715c6 100644 --- a/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr +++ b/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr @@ -1,4 +1,4 @@ -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 +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 --> $DIR/panic-implementation-deprecated.rs:19:1 | LL | #[panic_implementation] From 79da7a0a2f3c5490e1b8a4233795424bcf05520a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alva=20Sn=C3=A6d=C3=ADs?= Date: Mon, 17 Sep 2018 03:40:31 +0000 Subject: [PATCH 2/2] libsyntax: add optional help message for deprecated features --- src/librustc_lint/builtin.rs | 4 ++-- src/libsyntax/feature_gate.rs | 15 +++++++++------ .../feature-gate-dropck-ugeh-2.stderr | 2 +- .../panic-implementation-deprecated.stderr | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index b662b82501393..f9e717f8d456e 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -783,7 +783,7 @@ impl EarlyLintPass for DeprecatedAttr { fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) { for &&(n, _, ref g) in &self.depr_attrs { if attr.name() == n { - if let &AttributeGate::Gated(Stability::Deprecated(link), + if let &AttributeGate::Gated(Stability::Deprecated(link, suggestion), ref name, ref reason, _) = g { @@ -792,7 +792,7 @@ impl EarlyLintPass for DeprecatedAttr { let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg); err.span_suggestion_short_with_applicability( attr.span, - "remove this attribute", + suggestion.unwrap_or("remove this attribute"), String::new(), Applicability::MachineApplicable ); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 603dfad38eb19..96328be2dadf2 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -711,7 +711,7 @@ pub enum AttributeGate { impl AttributeGate { fn is_deprecated(&self) -> bool { match *self { - Gated(Stability::Deprecated(_), ..) => true, + Gated(Stability::Deprecated(_, _), ..) => true, _ => false, } } @@ -720,8 +720,9 @@ impl AttributeGate { #[derive(Copy, Clone, Debug)] pub enum Stability { Unstable, - // Argument is tracking issue link. - Deprecated(&'static str), + // First argument is tracking issue link; second argument is an optional + // help message, which defaults to "remove this attribute" + Deprecated(&'static str, Option<&'static str>), } // fn() is not Debug @@ -1044,7 +1045,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG ("no_builtins", Whitelisted, Ungated), ("no_mangle", Whitelisted, Ungated), ("no_debug", Whitelisted, Gated( - Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721"), + Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721", None), "no_debug", "the `#[no_debug]` attribute was an experimental feature that has been \ deprecated due to lack of demand", @@ -1057,7 +1058,8 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG cfg_fn!(omit_gdb_pretty_printer_section))), ("unsafe_destructor_blind_to_params", Normal, - Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761"), + Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761", + Some("replace this attribute with `#[may_dangle]`")), "dropck_parametricity", "unsafe_destructor_blind_to_params has been replaced by \ may_dangle and will be removed in the future", @@ -1136,7 +1138,8 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG ("panic_implementation", Normal, Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\ - #issuecomment-415140224"), + #issuecomment-415140224", + Some("replace this attribute with `#[panic_handler]`")), "panic_implementation", "this attribute was renamed to `panic_handler`", cfg_fn!(panic_implementation))), diff --git a/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr b/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr index 80d81ea03cb6d..d3d5bd498cfe8 100644 --- a/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr +++ b/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr @@ -2,7 +2,7 @@ error: use of deprecated attribute `dropck_parametricity`: unsafe_destructor_bli --> $DIR/feature-gate-dropck-ugeh-2.rs:17:5 | LL | #[unsafe_destructor_blind_to_params] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[may_dangle]` | note: lint level defined here --> $DIR/feature-gate-dropck-ugeh-2.rs:11:9 diff --git a/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr b/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr index c869dddb715c6..fabfba94878f5 100644 --- a/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr +++ b/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr @@ -2,7 +2,7 @@ error: use of deprecated attribute `panic_implementation`: this attribute was re --> $DIR/panic-implementation-deprecated.rs:19:1 | LL | #[panic_implementation] - | ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute + | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[panic_handler]` | note: lint level defined here --> $DIR/panic-implementation-deprecated.rs:13:9