Skip to content

profusion of redundant "overruled by outer forbid" messages #42873

Closed
@zackmdavis

Description

@zackmdavis

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

No one assigned

    Labels

    A-lintsArea: 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions