diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 1bbc1accc07d6..b4a6578e6ae07 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -10,7 +10,7 @@ //! Parsing and validation of builtin attributes -use ast::{self, Attribute, MetaItem, Name, NestedMetaItemKind}; +use ast::{self, Attribute, LitKind, MetaItem, Name, NestedMetaItemKind}; use errors::{Applicability, Handler}; use feature_gate::{Features, GatedCfg}; use parse::ParseSess; @@ -598,12 +598,10 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, let diagnostic = &sess.span_diagnostic; 'outer: for attr in attrs_iter { - if attr.path != "deprecated" { + if !attr.check_name("deprecated") { continue } - mark_used(attr); - if depr.is_some() { span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes"); break @@ -670,6 +668,28 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, } Some(Deprecation {since: since, note: note}) + } else if let Some(lit) = attr + .meta() + .as_ref() + .and_then(|meta| meta.name_value_literal()) + { + let mut err = sess + .span_diagnostic + .struct_span_err(attr.span, "expected meta item sequence"); + + if let LitKind::Str(s, _) = lit.node { + let sp = attr.path.span.to(lit.span); + err.span_suggestion_with_applicability( + sp, + "use the `note` key", + format!("deprecated(note = \"{}\")", s), + Applicability::MachineApplicable, + ); + } + + err.emit(); + + continue 'outer; } else { Some(Deprecation{since: None, note: None}) } diff --git a/src/test/ui/deprecation/deprecation-sanity.rs b/src/test/ui/deprecation/deprecation-sanity.rs index af2ac79ea8072..e32e53c1b6268 100644 --- a/src/test/ui/deprecation/deprecation-sanity.rs +++ b/src/test/ui/deprecation/deprecation-sanity.rs @@ -34,4 +34,9 @@ fn multiple1() { } //~ ERROR multiple deprecated attributes #[deprecated(since = "a", since = "b", note = "c")] //~ ERROR multiple 'since' items fn f1() { } +#[deprecated = "reason"] +fn foo() { } //~^ ERROR expected meta item sequence + //~| HELP use the `note` key + //~| SUGGESTION deprecated(note = "reason") + fn main() { } diff --git a/src/test/ui/deprecation/deprecation-sanity.stderr b/src/test/ui/deprecation/deprecation-sanity.stderr index 967eb6e23a379..b84e6a23ca81b 100644 --- a/src/test/ui/deprecation/deprecation-sanity.stderr +++ b/src/test/ui/deprecation/deprecation-sanity.stderr @@ -40,7 +40,15 @@ error[E0538]: multiple 'since' items LL | #[deprecated(since = "a", since = "b", note = "c")] //~ ERROR multiple 'since' items | ^^^^^^^^^^^ -error: aborting due to 7 previous errors +error: expected meta item sequence + --> $DIR/deprecation-sanity.rs:37:1 + | +LL | #[deprecated = "reason"] + | ^^---------------------^ + | | + | help: use the `note` key: `deprecated(note = "reason")` + +error: aborting due to 8 previous errors Some errors occurred: E0538, E0541, E0550, E0551. For more information about an error, try `rustc --explain E0538`. diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.rs b/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.rs index 3f340145acffe..34feece35bfa6 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.rs +++ b/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.rs @@ -630,17 +630,17 @@ mod link_section { struct StructForDeprecated; -#[deprecated = "1500"] +#[deprecated] mod deprecated { - mod inner { #![deprecated="1500"] } + mod inner { #![deprecated] } - #[deprecated = "1500"] fn f() { } + #[deprecated] fn f() { } - #[deprecated = "1500"] struct S1; + #[deprecated] struct S1; - #[deprecated = "1500"] type T = super::StructForDeprecated; + #[deprecated] type T = super::StructForDeprecated; - #[deprecated = "1500"] impl super::StructForDeprecated { } + #[deprecated] impl super::StructForDeprecated { } } #[must_use = "1400"] diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-deprecated.rs b/src/test/ui/feature-gate/issue-43106-gating-of-deprecated.rs index 3f423a415cfb8..e221d34251f61 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-deprecated.rs +++ b/src/test/ui/feature-gate/issue-43106-gating-of-deprecated.rs @@ -18,13 +18,7 @@ // compile-pass // skip-codegen #![allow(dead_code)] -#![deprecated = "1100"] - -// Since we expect for the mix of attributes used here to compile -// successfully, and we are just testing for the expected warnings of -// various (mis)uses of attributes, we use the `rustc_error` attribute -// on the `fn main()`. - +#![deprecated] fn main() { println!("Hello World");