Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint empty #[derive()] as unused attribute. #62051

Merged
merged 1 commit into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/libsyntax/ext/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ pub fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>) ->

match attr.parse_list(cx.parse_sess,
|parser| parser.parse_path_allowing_meta(PathStyle::Mod)) {
Ok(ref traits) if traits.is_empty() => {
cx.span_warn(attr.span, "empty trait list in `derive`");
false
}
Ok(traits) => {
result.extend(traits);
true
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/derives/deriving-meta-empty-trait-list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// compile-pass
#![deny(unused)]

#[derive()] //~ WARNING empty trait list in `derive`
struct Bar;
#[derive()] //~ ERROR unused attribute
struct _Bar;

pub fn main() {}
11 changes: 10 additions & 1 deletion src/test/ui/derives/deriving-meta-empty-trait-list.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
warning: empty trait list in `derive`
error: unused attribute
--> $DIR/deriving-meta-empty-trait-list.rs:3:1
|
LL | #[derive()]
| ^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/deriving-meta-empty-trait-list.rs:1:9
|
LL | #![deny(unused)]
| ^^^^^^
= note: #[deny(unused_attributes)] implied by #[deny(unused)]

error: aborting due to previous error

3 changes: 0 additions & 3 deletions src/test/ui/malformed/malformed-derive-entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ struct Test1;
#[derive(Copy="bad")] //~ ERROR expected one of `)`, `,`, or `::`, found `=`
struct Test2;

#[derive()] //~ WARNING empty trait list
struct Test3;

#[derive] //~ ERROR malformed `derive` attribute input
struct Test4;

Expand Down
8 changes: 1 addition & 7 deletions src/test/ui/malformed/malformed-derive-entry.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ error: expected one of `)`, `,`, or `::`, found `=`
LL | #[derive(Copy="bad")]
| ^ expected one of `)`, `,`, or `::` here

warning: empty trait list in `derive`
--> $DIR/malformed-derive-entry.rs:7:1
|
LL | #[derive()]
| ^^^^^^^^^^^

error: malformed `derive` attribute input
--> $DIR/malformed-derive-entry.rs:10:1
--> $DIR/malformed-derive-entry.rs:7:1
|
LL | #[derive]
| ^^^^^^^^^ help: missing traits to be derived: `#[derive(Trait1, Trait2, ...)]`
Expand Down