Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 13, 2019
1 parent 41c6599 commit d3411d3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/57321>",
reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
edition: None,
},
]);
Expand Down
15 changes: 11 additions & 4 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)) };
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/57321>
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>

error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-inline.rs:11:1
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/malformed/malformed-regressions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/57321>
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>

warning: attribute must be of the form `#[ignore]` or `#[ignore = "reason"]`
--> $DIR/malformed-regressions.rs:4:1
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/57321>
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>

warning: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
--> $DIR/malformed-regressions.rs:5:1
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/57321>
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>

warning: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...",
/*opt*/ cfg = "...")]`
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/57321>
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>

warning: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...",
/*opt*/ cfg = "...")]`
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/57321>
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>

4 changes: 2 additions & 2 deletions src/test/ui/proc-macro/attribute.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit d3411d3

Please sign in to comment.