-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow #[deny]
inside #[forbid]
as a no-op
#121560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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_allow { | ||
() => { | ||
#[allow(unsafe_code)] | ||
let _so_safe = 0; | ||
}; | ||
} |
This file contains hidden or 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 hidden or 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_forbid { | ||
() => { | ||
#[forbid(unsafe_code)] | ||
let _so_safe = 0; | ||
}; | ||
} |
This file contains hidden or 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_warn { | ||
() => { | ||
#[warn(unsafe_code)] | ||
let _so_safe = 0; | ||
}; | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/ui/lint/deny-inside-forbid-ignored.cli_forbid.stderr
This file contains hidden or 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:12: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:12: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:16:13 | ||
| | ||
LL | unsafe { /* ≽^•⩊•^≼ */ } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/deny-inside-forbid-ignored.rs:8: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`. |
35 changes: 35 additions & 0 deletions
35
tests/ui/lint/deny-inside-forbid-ignored.cli_forbid_warnings.stderr
This file contains hidden or 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:12: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:12: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:16:13 | ||
| | ||
LL | unsafe { /* ≽^•⩊•^≼ */ } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/deny-inside-forbid-ignored.rs:8: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 hidden or 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,20 @@ | ||
//! Ensure that using deny inside forbid is treated as a no-op, and does not override the level to | ||
//! deny. | ||
|
||
//@ revisions: source_only cli_forbid cli_forbid_warnings | ||
//@[cli_forbid] compile-flags: -F unsafe_code | ||
//@[cli_forbid_warnings] compile-flags: -F warnings | ||
|
||
#[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 | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/ui/lint/deny-inside-forbid-ignored.source_only.stderr
This file contains hidden or 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:12: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:12: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:16:13 | ||
| | ||
LL | unsafe { /* ≽^•⩊•^≼ */ } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/deny-inside-forbid-ignored.rs:8: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 hidden or 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,26 @@ | ||
error[E0453]: allow(unsafe_code) incompatible with previous forbid | ||
--> $DIR/forbid-macro-with-deny.rs:39:5 | ||
| | ||
LL | #![forbid(unsafe_code)] | ||
| ----------- `forbid` level set here | ||
... | ||
LL | allow_macro::emit_allow! {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid | ||
| | ||
= note: this error originates in the macro `allow_macro::emit_allow` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0453]: allow(unsafe_code) incompatible with previous forbid | ||
--> $DIR/forbid-macro-with-deny.rs:39:5 | ||
| | ||
LL | #![forbid(unsafe_code)] | ||
| ----------- `forbid` level set here | ||
... | ||
LL | allow_macro::emit_allow! {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
= note: this error originates in the macro `allow_macro::emit_allow` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0453`. |
This file contains hidden or 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,45 @@ | ||
//! 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. | ||
//! | ||
//! However, still emit an error if the macro does `#[allow]` or `#[warn]`. | ||
|
||
//@ revisions: forbid deny warn allow | ||
//@[forbid] aux-build:forbid-macro.rs | ||
//@[deny] aux-build:deny-macro.rs | ||
//@[warn] aux-build:warn-macro.rs | ||
//@[allow] aux-build:allow-macro.rs | ||
|
||
//@[forbid] check-pass | ||
//@[deny] check-pass | ||
|
||
#![forbid(unsafe_code)] | ||
|
||
#[cfg(allow)] | ||
extern crate allow_macro; | ||
#[cfg(deny)] | ||
extern crate deny_macro; | ||
#[cfg(forbid)] | ||
extern crate forbid_macro; | ||
#[cfg(warn)] | ||
extern crate warn_macro; | ||
|
||
fn main() { | ||
#[cfg(forbid)] | ||
forbid_macro::emit_forbid! {} // OK | ||
|
||
#[cfg(deny)] | ||
deny_macro::emit_deny! {} // OK | ||
|
||
#[cfg(warn)] | ||
warn_macro::emit_warn! {} | ||
//[warn]~^ ERROR warn(unsafe_code) incompatible with previous forbid | ||
//[warn]~| ERROR warn(unsafe_code) incompatible with previous forbid | ||
|
||
#[cfg(allow)] | ||
allow_macro::emit_allow! {} | ||
//[allow]~^ ERROR allow(unsafe_code) incompatible with previous forbid | ||
//[allow]~| ERROR allow(unsafe_code) incompatible with previous forbid | ||
|
||
#[deny(unsafe_code)] // OK | ||
let _ = 0; | ||
} |
This file contains hidden or 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,26 @@ | ||
error[E0453]: warn(unsafe_code) incompatible with previous forbid | ||
--> $DIR/forbid-macro-with-deny.rs:34:5 | ||
| | ||
LL | #![forbid(unsafe_code)] | ||
| ----------- `forbid` level set here | ||
... | ||
LL | warn_macro::emit_warn! {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid | ||
| | ||
= note: this error originates in the macro `warn_macro::emit_warn` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0453]: warn(unsafe_code) incompatible with previous forbid | ||
--> $DIR/forbid-macro-with-deny.rs:34:5 | ||
| | ||
LL | #![forbid(unsafe_code)] | ||
| ----------- `forbid` level set here | ||
... | ||
LL | warn_macro::emit_warn! {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
= note: this error originates in the macro `warn_macro::emit_warn` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0453`. |
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.