rust-lang / rust-lang/rust

Duplicate error for using allow inside forbid

Open
#131,842 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/ui/lint/deny-inside-forbid-ignored.rs and reproduce the output using -Zdeduplicate-diagnostics=false; then read tests/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs for related behavior. Done means the allow-inside-forbid case emits one E0453 diagnostic and reports one previous error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.