Skip to content

Commit 217e43d

Browse files
committed
Expand test coverage for deny-inside-forbid interactions
1 parent e3c12d2 commit 217e43d

10 files changed

+207
-12
lines changed
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[macro_export]
2+
macro_rules! emit_allow {
3+
() => {
4+
#[allow(unsafe_code)]
5+
let _so_safe = 0;
6+
};
7+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[macro_export]
2+
macro_rules! emit_forbid {
3+
() => {
4+
#[forbid(unsafe_code)]
5+
let _so_safe = 0;
6+
};
7+
}

tests/ui/lint/auxiliary/warn-macro.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[macro_export]
2+
macro_rules! emit_warn {
3+
() => {
4+
#[warn(unsafe_code)]
5+
let _so_safe = 0;
6+
};
7+
}

tests/ui/lint/deny-inside-forbid-ignored.stderr tests/ui/lint/deny-inside-forbid-ignored.cli_forbid.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0453]: allow(unsafe_code) incompatible with previous forbid
2-
--> $DIR/deny-inside-forbid-ignored.rs:8:17
2+
--> $DIR/deny-inside-forbid-ignored.rs:12:17
33
|
44
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
55
| ----------- `forbid` level set here
@@ -8,7 +8,7 @@ LL | #[allow(unsafe_code)] // let's have some unsafe code in here
88
| ^^^^^^^^^^^ overruled by previous forbid
99

1010
error[E0453]: allow(unsafe_code) incompatible with previous forbid
11-
--> $DIR/deny-inside-forbid-ignored.rs:8:17
11+
--> $DIR/deny-inside-forbid-ignored.rs:12:17
1212
|
1313
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
1414
| ----------- `forbid` level set here
@@ -19,13 +19,13 @@ LL | #[allow(unsafe_code)] // let's have some unsafe code in here
1919
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2020

2121
error: usage of an `unsafe` block
22-
--> $DIR/deny-inside-forbid-ignored.rs:12:13
22+
--> $DIR/deny-inside-forbid-ignored.rs:16:13
2323
|
2424
LL | unsafe { /* ≽^•⩊•^≼ */ }
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^
2626
|
2727
note: the lint level is defined here
28-
--> $DIR/deny-inside-forbid-ignored.rs:4:10
28+
--> $DIR/deny-inside-forbid-ignored.rs:8:10
2929
|
3030
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
3131
| ^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
warning[E0602]: unknown lint: `warning`
2+
|
3+
= help: did you mean: `warnings`
4+
= note: requested on the command line with `-F warning`
5+
= note: `#[warn(unknown_lints)]` on by default
6+
7+
warning[E0602]: unknown lint: `warning`
8+
|
9+
= help: did you mean: `warnings`
10+
= note: requested on the command line with `-F warning`
11+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
12+
13+
error[E0453]: allow(unsafe_code) incompatible with previous forbid
14+
--> $DIR/deny-inside-forbid-ignored.rs:12:17
15+
|
16+
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
17+
| ----------- `forbid` level set here
18+
...
19+
LL | #[allow(unsafe_code)] // let's have some unsafe code in here
20+
| ^^^^^^^^^^^ overruled by previous forbid
21+
22+
error[E0453]: allow(unsafe_code) incompatible with previous forbid
23+
--> $DIR/deny-inside-forbid-ignored.rs:12:17
24+
|
25+
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
26+
| ----------- `forbid` level set here
27+
...
28+
LL | #[allow(unsafe_code)] // let's have some unsafe code in here
29+
| ^^^^^^^^^^^ overruled by previous forbid
30+
|
31+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
32+
33+
error: usage of an `unsafe` block
34+
--> $DIR/deny-inside-forbid-ignored.rs:16:13
35+
|
36+
LL | unsafe { /* ≽^•⩊•^≼ */ }
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^
38+
|
39+
note: the lint level is defined here
40+
--> $DIR/deny-inside-forbid-ignored.rs:8:10
41+
|
42+
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
43+
| ^^^^^^^^^^^
44+
45+
warning[E0602]: unknown lint: `warning`
46+
|
47+
= help: did you mean: `warnings`
48+
= note: requested on the command line with `-F warning`
49+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
50+
51+
error: aborting due to 3 previous errors; 3 warnings emitted
52+
53+
Some errors have detailed explanations: E0453, E0602.
54+
For more information about an error, try `rustc --explain E0453`.

tests/ui/lint/deny-inside-forbid-ignored.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
/// Ensure that using deny inside forbid is treated as a no-op,
2-
/// and does not override the level to deny.
1+
//! Ensure that using deny inside forbid is treated as a no-op, and does not override the level to
2+
//! deny.
3+
4+
//@ revisions: source_only cli_forbid cli_forbid_warnings
5+
//@[cli_forbid] compile-flags: -F unsafe_code
6+
//@[cli_forbid_warnings] compile-flags: -F warning
37

48
#[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
59
fn main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0453]: allow(unsafe_code) incompatible with previous forbid
2+
--> $DIR/deny-inside-forbid-ignored.rs:12:17
3+
|
4+
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
5+
| ----------- `forbid` level set here
6+
...
7+
LL | #[allow(unsafe_code)] // let's have some unsafe code in here
8+
| ^^^^^^^^^^^ overruled by previous forbid
9+
10+
error[E0453]: allow(unsafe_code) incompatible with previous forbid
11+
--> $DIR/deny-inside-forbid-ignored.rs:12:17
12+
|
13+
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
14+
| ----------- `forbid` level set here
15+
...
16+
LL | #[allow(unsafe_code)] // let's have some unsafe code in here
17+
| ^^^^^^^^^^^ overruled by previous forbid
18+
|
19+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20+
21+
error: usage of an `unsafe` block
22+
--> $DIR/deny-inside-forbid-ignored.rs:16:13
23+
|
24+
LL | unsafe { /* ≽^•⩊•^≼ */ }
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^
26+
|
27+
note: the lint level is defined here
28+
--> $DIR/deny-inside-forbid-ignored.rs:8:10
29+
|
30+
LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!!
31+
| ^^^^^^^^^^^
32+
33+
error: aborting due to 3 previous errors
34+
35+
For more information about this error, try `rustc --explain E0453`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0453]: allow(unsafe_code) incompatible with previous forbid
2+
--> $DIR/forbid-macro-with-deny.rs:39:5
3+
|
4+
LL | #![forbid(unsafe_code)]
5+
| ----------- `forbid` level set here
6+
...
7+
LL | allow_macro::emit_allow! {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid
9+
|
10+
= note: this error originates in the macro `allow_macro::emit_allow` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error[E0453]: allow(unsafe_code) incompatible with previous forbid
13+
--> $DIR/forbid-macro-with-deny.rs:39:5
14+
|
15+
LL | #![forbid(unsafe_code)]
16+
| ----------- `forbid` level set here
17+
...
18+
LL | allow_macro::emit_allow! {}
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid
20+
|
21+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
22+
= note: this error originates in the macro `allow_macro::emit_allow` (in Nightly builds, run with -Z macro-backtrace for more info)
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0453`.
+35-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
1-
//@ aux-build:deny-macro.rs
2-
//@ check-pass
1+
//! Ensure that when a macro (or normal code) does `#[deny]` inside a `#[forbid]` context, no error
2+
//! is emitted, as both parties agree on the treatment of the lint.
3+
//!
4+
//! However, still emit an error if the macro does `#[allow]` or `#[warn]`.
35
4-
// Ensure that when a macro (or normal code) does #[deny] inside a #[forbid]
5-
// context, no error is emitted, as both parties agree on the treatment of the lint.
6+
//@ revisions: forbid deny warn allow
7+
//@[forbid] aux-build:forbid-macro.rs
8+
//@[deny] aux-build:deny-macro.rs
9+
//@[warn] aux-build:warn-macro.rs
10+
//@[allow] aux-build:allow-macro.rs
11+
12+
//@[forbid] check-pass
13+
//@[deny] check-pass
614

715
#![forbid(unsafe_code)]
816

17+
#[cfg(allow)]
18+
extern crate allow_macro;
19+
#[cfg(deny)]
920
extern crate deny_macro;
21+
#[cfg(forbid)]
22+
extern crate forbid_macro;
23+
#[cfg(warn)]
24+
extern crate warn_macro;
1025

1126
fn main() {
12-
deny_macro::emit_deny! {}
27+
#[cfg(forbid)]
28+
forbid_macro::emit_forbid! {} // OK
29+
30+
#[cfg(deny)]
31+
deny_macro::emit_deny! {} // OK
32+
33+
#[cfg(warn)]
34+
warn_macro::emit_warn! {}
35+
//[warn]~^ ERROR warn(unsafe_code) incompatible with previous forbid
36+
//[warn]~| ERROR warn(unsafe_code) incompatible with previous forbid
37+
38+
#[cfg(allow)]
39+
allow_macro::emit_allow! {}
40+
//[allow]~^ ERROR allow(unsafe_code) incompatible with previous forbid
41+
//[allow]~| ERROR allow(unsafe_code) incompatible with previous forbid
1342

14-
#[deny(unsafe_code)]
43+
#[deny(unsafe_code)] // OK
1544
let _ = 0;
1645
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0453]: warn(unsafe_code) incompatible with previous forbid
2+
--> $DIR/forbid-macro-with-deny.rs:34:5
3+
|
4+
LL | #![forbid(unsafe_code)]
5+
| ----------- `forbid` level set here
6+
...
7+
LL | warn_macro::emit_warn! {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid
9+
|
10+
= note: this error originates in the macro `warn_macro::emit_warn` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error[E0453]: warn(unsafe_code) incompatible with previous forbid
13+
--> $DIR/forbid-macro-with-deny.rs:34:5
14+
|
15+
LL | #![forbid(unsafe_code)]
16+
| ----------- `forbid` level set here
17+
...
18+
LL | warn_macro::emit_warn! {}
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid
20+
|
21+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
22+
= note: this error originates in the macro `warn_macro::emit_warn` (in Nightly builds, run with -Z macro-backtrace for more info)
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0453`.

0 commit comments

Comments
 (0)