-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
11 changed files
with
84 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#[macro_export] | ||
macro_rules! emit_deny { | ||
() => { | ||
#[deny(unsafe_code)] | ||
let _so_safe = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// Ensure that using deny inside forbid is treated as a no-op, | ||
/// and does not override the level to deny. | ||
#[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! | ||
fn main() { | ||
#[deny(unsafe_code)] // m-m-maybe we can have unsafe code in here? | ||
{ | ||
#[allow(unsafe_code)] // let's have some unsafe code in here | ||
//~^ ERROR allow(unsafe_code) incompatible with previous forbid | ||
//~| ERROR allow(unsafe_code) incompatible with previous forbid | ||
{ | ||
unsafe { /* ≽^•⩊•^≼ */ } | ||
//~^ ERROR usage of an `unsafe` block | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error[E0453]: allow(unsafe_code) incompatible with previous forbid | ||
--> $DIR/deny-inside-forbid-ignored.rs:8:17 | ||
| | ||
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! | ||
| ----------- `forbid` level set here | ||
... | ||
LL | #[allow(unsafe_code)] // let's have some unsafe code in here | ||
| ^^^^^^^^^^^ overruled by previous forbid | ||
|
||
error[E0453]: allow(unsafe_code) incompatible with previous forbid | ||
--> $DIR/deny-inside-forbid-ignored.rs:8:17 | ||
| | ||
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! | ||
| ----------- `forbid` level set here | ||
... | ||
LL | #[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: usage of an `unsafe` block | ||
--> $DIR/deny-inside-forbid-ignored.rs:12:13 | ||
| | ||
LL | unsafe { /* ≽^•⩊•^≼ */ } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/deny-inside-forbid-ignored.rs:4:10 | ||
| | ||
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0453`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ aux-build:deny-macro.rs | ||
//@ check-pass | ||
|
||
// Ensure that when a macro (or normal code) does #[deny] inside a #[forbid] | ||
// context, no error is emitted, as both parties agree on the treatment of the lint. | ||
|
||
#![forbid(unsafe_code)] | ||
|
||
extern crate deny_macro; | ||
|
||
fn main() { | ||
deny_macro::emit_deny! {} | ||
|
||
#[deny(unsafe_code)] | ||
let _ = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
tests/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.