Skip to content

Commit ef03a5d

Browse files
committed
Regression test.
1 parent 01e8e9f commit ef03a5d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This test is checking that you cannot override a `forbid` by adding in other
2+
// attributes later in the same scope. (We already ensure that you cannot
3+
// override it in nested scopes).
4+
5+
// If you turn off deduplicate diagnostics (which rustc turns on by default but
6+
// compiletest turns off when it runs ui tests), then the errors are
7+
// (unfortunately) repeated here because the checking is done as we read in the
8+
// errors, and curretly that happens two or three different times, depending on
9+
// compiler flags.
10+
//
11+
// I decided avoiding the redundant output was not worth the time in engineering
12+
// effort for bug like this, which 1. end users are unlikely to run into in the
13+
// first place, and 2. they won't see the redundant output anyway.
14+
15+
// compile-flags: -Z deduplicate-diagnostics=yes
16+
17+
fn forbid_first(num: i32) -> i32 {
18+
#![forbid(unused)]
19+
#![deny(unused)]
20+
//~^ ERROR: deny(unused) incompatible with previous forbid in same scope [E0453]
21+
#![warn(unused)]
22+
//~^ ERROR: warn(unused) incompatible with previous forbid in same scope [E0453]
23+
#![allow(unused)]
24+
//~^ ERROR: allow(unused) incompatible with previous forbid in same scope [E0453]
25+
26+
num * num
27+
}
28+
29+
fn forbid_last(num: i32) -> i32 {
30+
#![deny(unused)]
31+
#![warn(unused)]
32+
#![allow(unused)]
33+
#![forbid(unused)]
34+
35+
num * num
36+
}
37+
38+
fn forbid_multiple(num: i32) -> i32 {
39+
#![forbid(unused)]
40+
#![forbid(unused)]
41+
42+
num * num
43+
}
44+
45+
fn main() {
46+
forbid_first(10);
47+
forbid_last(10);
48+
forbid_multiple(10);
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0453]: deny(unused) incompatible with previous forbid in same scope
2+
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:19:13
3+
|
4+
LL | #![forbid(unused)]
5+
| ------ `forbid` level set here
6+
LL | #![deny(unused)]
7+
| ^^^^^^
8+
9+
error[E0453]: warn(unused) incompatible with previous forbid in same scope
10+
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:21:13
11+
|
12+
LL | #![forbid(unused)]
13+
| ------ `forbid` level set here
14+
...
15+
LL | #![warn(unused)]
16+
| ^^^^^^
17+
18+
error[E0453]: allow(unused) incompatible with previous forbid in same scope
19+
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:23:14
20+
|
21+
LL | #![forbid(unused)]
22+
| ------ `forbid` level set here
23+
...
24+
LL | #![allow(unused)]
25+
| ^^^^^^
26+
27+
error: aborting due to 3 previous errors
28+
29+
For more information about this error, try `rustc --explain E0453`.

0 commit comments

Comments
 (0)