-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Consider this (erroneous) program:
#![forbid(unused)]
#[allow(unused)]
fn main() {
println!("hello forbidden world");
}
As we expect, this fails to compile, because the outer "forbid" attribute contradicts the "allow" attribute. ("Forbid" is like "deny" except that it prevents itself from being subsequently overridden.) However, the error messages leave something to be desired:
$ rustc --version
rustc 1.18.0 (03fc9d622 2017-06-06)
$ rustc scratch.rs
error[E0453]: allow(unused_imports) overruled by outer forbid(unused_imports)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unused_variables) overruled by outer forbid(unused_variables)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unused_assignments) overruled by outer forbid(unused_assignments)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(dead_code) overruled by outer forbid(dead_code)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unused_mut) overruled by outer forbid(unused_mut)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unreachable_code) overruled by outer forbid(unreachable_code)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unreachable_patterns) overruled by outer forbid(unreachable_patterns)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unused_must_use) overruled by outer forbid(unused_must_use)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unused_unsafe) overruled by outer forbid(unused_unsafe)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(path_statements) overruled by outer forbid(path_statements)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error[E0453]: allow(unused_attributes) overruled by outer forbid(unused_attributes)
--> /home/ubuntu/rust/scratch.rs:3:9
|
1 | #![forbid(unused)]
| ------ `forbid` level set here
2 |
3 | #[allow(unused)]
| ^^^^^^ overruled by previous forbid
error: aborting due to 11 previous errors
We get a separate error for each lint in the "unused" lint group! This is kind of terrible! We would prefer to get a single error for the contradicting attributes, whose message names the offending attributes (it's weird to say "overruled by outer forbid(path_statements)", when the outer forbid is for unused, not path_statements).
A fix by the present author is forthcoming.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.