rust/tests/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs
Noratrieb e78d78868a Allow #[deny(..)] inside #[forbid(..)] as a no-op with a warning
Forbid cannot be overriden. When someome tries to do this anyways,
it results in a hard error. That makes sense.

Except it doesn't, because macros. Macros may reasonably use `#[deny]`
in their expansion to assert
that their expanded code follows the lint. This is doesn't work when the
output gets expanded into a `forbid()` context. This is pretty silly,
since both the macros and the code agree on the lint!

Therefore, we allow `#[deny(..)]`ing a lint that's already forbidden,
keeping the level at forbid.
2024-10-18 18:18:41 +02:00

51 lines
1.4 KiB
Rust

// This test is checking that you cannot override a `forbid` by adding in other
// attributes later in the same scope. (We already ensure that you cannot
// override it in nested scopes).
// If you turn off deduplicate diagnostics (which rustc turns on by default but
// compiletest turns off when it runs ui tests), then the errors are
// (unfortunately) repeated here because the checking is done as we read in the
// errors, and currently that happens two or three different times, depending on
// compiler flags.
//
// I decided avoiding the redundant output was not worth the time in engineering
// effort for bug like this, which 1. end users are unlikely to run into in the
// first place, and 2. they won't see the redundant output anyway.
//@ compile-flags: -Z deduplicate-diagnostics=yes
#![forbid(forbidden_lint_groups)]
fn forbid_first(num: i32) -> i32 {
#![forbid(unused)]
#![deny(unused)]
#![warn(unused)]
//~^ ERROR: warn(unused) incompatible with previous forbid
//~| WARNING being phased out
#![allow(unused)]
num * num
}
fn forbid_last(num: i32) -> i32 {
#![deny(unused)]
#![warn(unused)]
#![allow(unused)]
#![forbid(unused)]
num * num
}
fn forbid_multiple(num: i32) -> i32 {
#![forbid(unused)]
#![forbid(unused)]
num * num
}
fn main() {
forbid_first(10);
forbid_last(10);
forbid_multiple(10);
}