Skip to content

Commit

Permalink
Expand test coverage for deny-inside-forbid interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu authored and Noratrieb committed Oct 18, 2024
1 parent e78d788 commit 1af9d11
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 12 deletions.
7 changes: 7 additions & 0 deletions tests/ui/lint/auxiliary/allow-macro.rs
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;
};
}
7 changes: 7 additions & 0 deletions tests/ui/lint/auxiliary/forbid-macro.rs
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;
};
}
7 changes: 7 additions & 0 deletions tests/ui/lint/auxiliary/warn-macro.rs
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;
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0453]: allow(unsafe_code) incompatible with previous forbid
--> $DIR/deny-inside-forbid-ignored.rs:8:17
--> $DIR/deny-inside-forbid-ignored.rs:12:17
|
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
| ----------- `forbid` level set here
Expand All @@ -8,7 +8,7 @@ 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
--> $DIR/deny-inside-forbid-ignored.rs:12:17
|
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
| ----------- `forbid` level set here
Expand All @@ -19,13 +19,13 @@ LL | #[allow(unsafe_code)] // let's have some unsafe code in here
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: usage of an `unsafe` block
--> $DIR/deny-inside-forbid-ignored.rs:12:13
--> $DIR/deny-inside-forbid-ignored.rs:16:13
|
LL | unsafe { /* ≽^•⩊•^≼ */ }
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/deny-inside-forbid-ignored.rs:4:10
--> $DIR/deny-inside-forbid-ignored.rs:8:10
|
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
| ^^^^^^^^^^^
Expand Down
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`.
8 changes: 6 additions & 2 deletions tests/ui/lint/deny-inside-forbid-ignored.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/// Ensure that using deny inside forbid is treated as a no-op,
/// and does not override the level to deny.
//! 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() {
Expand Down
35 changes: 35 additions & 0 deletions tests/ui/lint/deny-inside-forbid-ignored.source_only.stderr
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`.
26 changes: 26 additions & 0 deletions tests/ui/lint/forbid-macro-with-deny.allow.stderr
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`.
41 changes: 35 additions & 6 deletions tests/ui/lint/forbid-macro-with-deny.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
//@ 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.
//!
//! However, still emit an error if the macro does `#[allow]` or `#[warn]`.
// 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.
//@ 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() {
deny_macro::emit_deny! {}
#[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)]
#[deny(unsafe_code)] // OK
let _ = 0;
}
26 changes: 26 additions & 0 deletions tests/ui/lint/forbid-macro-with-deny.warn.stderr
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`.

0 comments on commit 1af9d11

Please sign in to comment.