rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.16k stars 12.8k forks source link

Duplicate error for using allow inside forbid #131842

Open Noratrieb opened 1 month ago

Noratrieb commented 1 month ago

Code

// USE `-Zdeduplicate-diagnostics=false`
#[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
fn main() {
    {
        #[allow(unsafe_code)] // let's have some unsafe code in here
        {
        }
    }
}

Current output

error[E0453]: allow(unsafe_code) incompatible with previous forbid
 --> tests/ui/lint/deny-inside-forbid-ignored.rs:4:17
  |
1 | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
  |          ----------- `forbid` level set here
...
4 |         #[allow(unsafe_code)] // let's have some unsafe code in here
  |                 ^^^^^^^^^^^ overruled by previous forbid

error[E0453]: allow(unsafe_code) incompatible with previous forbid
 --> tests/ui/lint/deny-inside-forbid-ignored.rs:4:17
  |
1 | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
  |          ----------- `forbid` level set here
...
4 |         #[allow(unsafe_code)] // let's have some unsafe code in here
  |                 ^^^^^^^^^^^ overruled by previous forbid
  |
  = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0453`.

Desired output

error[E0453]: allow(unsafe_code) incompatible with previous forbid
 --> tests/ui/lint/deny-inside-forbid-ignored.rs:4:17
  |
1 | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
  |          ----------- `forbid` level set here
...
4 |         #[allow(unsafe_code)] // let's have some unsafe code in here
  |                 ^^^^^^^^^^^ overruled by previous forbid

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0453`.

Rationale and extra context

Use -Zdeduplicate-diagnostics=false

more context can be found in tests/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs

Other cases

No response

Rust Version

rustc 1.83.0-nightly (14f303bc1 2024-10-04) binary: rustc commit-hash: 14f303bc1430a78ddaa91b3e104bbe4c0413184e commit-date: 2024-10-04 host: x86_64-unknown-linux-gnu release: 1.83.0-nightly LLVM version: 19.1.0

Anything else?

No response

ismailarilik commented 1 month ago

Shouldn't desired output contain error: aborting due to 1 previous error instead of error: aborting due to 2 previous errors since there is just one error in that case?

Noratrieb commented 1 month ago

I assume that part deduplicates the diagnostics or something like that

ismailarilik commented 1 month ago

Sorry if I misunderstood but I mean the desired output you put above:

error[E0453]: allow(unsafe_code) incompatible with previous forbid
 --> tests/ui/lint/deny-inside-forbid-ignored.rs:4:17
  |
1 | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
  |          ----------- `forbid` level set here
...
4 |         #[allow(unsafe_code)] // let's have some unsafe code in here
  |                 ^^^^^^^^^^^ overruled by previous forbid

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0453`.

I think it should state:

error: aborting due to 1 previous error

instead of the current statement:

error: aborting due to 2 previous errors

since there is just one error in that case.

Do you agree?

Noratrieb commented 1 month ago

oh right

ismailarilik commented 1 month ago

I didn't try the code yet but I also didn't get why the first output states that there were 2 errors; the second one is just a duplicate so shouldn't there just be 1 error in that case as well?

ismailarilik commented 1 month ago

It is better now but I think 1 previous error is the right usage instead of 1 previous errors.

Noratrieb commented 1 month ago

the code just counts the errors, and there are 2 errors, so it says there are 2 errors. that's fine, nothing wrong with that