diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 74328709620..b644cafe4ec 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -338,7 +338,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { }, FutureIncompatibleInfo { id: LintId::of(ILL_FORMED_ATTRIBUTE_INPUT), - reference: "issue #57321 ", + reference: "issue #57571 ", edition: None, }, ]); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index a483e35a5b5..09fdf2d6618 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -717,6 +717,8 @@ pub enum AttributeGate { Ungated, } +/// A template that the attribute input must match. +/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now. #[derive(Clone, Copy)] pub struct AttributeTemplate { word: bool, @@ -725,6 +727,7 @@ pub struct AttributeTemplate { } impl AttributeTemplate { + /// Check that the given meta-item is compatible with this template. fn compatible(&self, meta_item_kind: &ast::MetaItemKind) -> bool { match meta_item_kind { ast::MetaItemKind::Word => self.word, @@ -735,10 +738,10 @@ impl AttributeTemplate { } } +/// A convenience macro for constructing attribute templates. +/// E.g. `template!(Word, List: "description")` means that the attribute +/// supports forms `#[attr]` and `#[attr(description)]`. macro_rules! template { - (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate { - word: $word, list: $list, name_value_str: $name_value_str - } }; (Word) => { template!(@ true, None, None) }; (List: $descr: expr) => { template!(@ false, Some($descr), None) }; (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) }; @@ -750,6 +753,9 @@ macro_rules! template { (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => { template!(@ true, Some($descr1), Some($descr2)) }; + (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate { + word: $word, list: $list, name_value_str: $name_value_str + } }; } impl AttributeGate { @@ -1084,7 +1090,8 @@ pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeTemplate, Attribu is an experimental feature", cfg_fn!(fundamental))), - ("proc_macro_derive", Normal, template!(List: "TraitName, attributes(name1, name2, ...)"), + ("proc_macro_derive", Normal, template!(List: "TraitName, \ + /*opt*/ attributes(name1, name2, ...)"), Ungated), ("rustc_copy_clone_marker", Whitelisted, template!(Word), Gated(Stability::Unstable, diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr index 485ff11eea7..71e8f11ff07 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr @@ -6,7 +6,7 @@ LL | #[inline = "2100"] fn f() { } | = note: #[warn(ill_formed_attribute_input)] on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57321 + = note: for more information, see issue #57571 error[E0518]: attribute should be applied to function or closure --> $DIR/issue-43106-gating-of-inline.rs:11:1 diff --git a/src/test/ui/malformed/malformed-regressions.stderr b/src/test/ui/malformed/malformed-regressions.stderr index f8dbfc04f10..a3b2bda07f6 100644 --- a/src/test/ui/malformed/malformed-regressions.stderr +++ b/src/test/ui/malformed/malformed-regressions.stderr @@ -6,7 +6,7 @@ LL | #[doc] //~ WARN attribute must be of the form | = note: #[warn(ill_formed_attribute_input)] on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57321 + = note: for more information, see issue #57571 warning: attribute must be of the form `#[ignore]` or `#[ignore = "reason"]` --> $DIR/malformed-regressions.rs:4:1 @@ -15,7 +15,7 @@ LL | #[ignore()] //~ WARN attribute must be of the form | ^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57321 + = note: for more information, see issue #57571 warning: attribute must be of the form `#[inline]` or `#[inline(always|never)]` --> $DIR/malformed-regressions.rs:5:1 @@ -24,7 +24,7 @@ LL | #[inline = ""] //~ WARN attribute must be of the form | ^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57321 + = note: for more information, see issue #57571 warning: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` @@ -34,7 +34,7 @@ LL | #[link] //~ WARN attribute must be of the form | ^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57321 + = note: for more information, see issue #57571 warning: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` @@ -44,5 +44,5 @@ LL | #[link = ""] //~ WARN attribute must be of the form | ^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #57321 + = note: for more information, see issue #57571 diff --git a/src/test/ui/proc-macro/attribute.stderr b/src/test/ui/proc-macro/attribute.stderr index c5dc3b8284b..231eb1f1068 100644 --- a/src/test/ui/proc-macro/attribute.stderr +++ b/src/test/ui/proc-macro/attribute.stderr @@ -34,13 +34,13 @@ error: attribute must have either one or two arguments LL | #[proc_macro_derive(l, attributes(m), n)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: attribute must be of the form `#[proc_macro_derive(TraitName, attributes(name1, name2, ...))]` +error: attribute must be of the form `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` --> $DIR/attribute.rs:8:1 | LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ -error: attribute must be of the form `#[proc_macro_derive(TraitName, attributes(name1, name2, ...))]` +error: attribute must be of the form `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` --> $DIR/attribute.rs:14:1 | LL | #[proc_macro_derive = "foo"]