Expand test coverage for deny-inside-forbid interactions · rust-lang/rust@1af9d11 (original) (raw)
10 files changed
lines changed
| Original file line number | Diff line number | Diff 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 | +} |
| Original file line number | Diff line number | Diff 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 | +} |
| Original file line number | Diff line number | Diff 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 | +} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | 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 | |
| 3 | 3 | | |
| 4 | 4 | LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! |
| 5 | 5 | | ----------- `forbid` level set here |
| @@ -8,7 +8,7 @@ LL | #[allow(unsafe_code)] // let's have some unsafe code in here | ||
| 8 | 8 | | ^^^^^^^^^^^ overruled by previous forbid |
| 9 | 9 | |
| 10 | 10 | 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 | |
| 12 | 12 | | |
| 13 | 13 | LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! |
| 14 | 14 | | ----------- `forbid` level set here |
| @@ -19,13 +19,13 @@ LL | #[allow(unsafe_code)] // let's have some unsafe code in here | ||
| 19 | 19 | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` |
| 20 | 20 | |
| 21 | 21 | error: usage of an `unsafe` block |
| 22 | - --> $DIR/deny-inside-forbid-ignored.rs:12:13 | |
| 22 | + --> $DIR/deny-inside-forbid-ignored.rs:16:13 | |
| 23 | 23 | | |
| 24 | 24 | LL | unsafe { /* ≽^•⩊•^≼ */ } |
| 25 | 25 | | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 26 | 26 | | |
| 27 | 27 | 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 | |
| 29 | 29 | | |
| 30 | 30 | LL | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! |
| 31 | 31 | | ^^^^^^^^^^^ |
| Original file line number | Diff line number | Diff 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 number | Diff line number | Diff 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 warnings | |
| 3 | 7 | |
| 4 | 8 | #[forbid(unsafe_code)] // NO UNSAFE CODE IN HERE!! |
| 5 | 9 | fn main() { |
| Original file line number | Diff line number | Diff 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 number | Diff line number | Diff 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`. |
| Original file line number | Diff line number | Diff 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]`. | |
| 3 | 5 | |
| 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 | |
| 6 | 14 | |
| 7 | 15 | #![forbid(unsafe_code)] |
| 8 | 16 | |
| 17 | +#[cfg(allow)] | |
| 18 | +extern crate allow_macro; | |
| 19 | +#[cfg(deny)] | |
| 9 | 20 | extern crate deny_macro; |
| 21 | +#[cfg(forbid)] | |
| 22 | +extern crate forbid_macro; | |
| 23 | +#[cfg(warn)] | |
| 24 | +extern crate warn_macro; | |
| 10 | 25 | |
| 11 | 26 | 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 | |
| 13 | 42 | |
| 14 | -#[deny(unsafe_code)] | |
| 43 | +#[deny(unsafe_code)] // OK | |
| 15 | 44 | let _ = 0; |
| 16 | 45 | } |
| Original file line number | Diff line number | Diff 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`. |