]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs
Rollup merge of #87180 - notriddle:notriddle/sidebar-keyboard-mobile, r=GuillaumeGomez
[rust.git] / src / test / ui / lint / issue-70819-dont-override-forbid-in-same-scope.rs
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 #![forbid(forbidden_lint_groups)]
18
19 fn forbid_first(num: i32) -> i32 {
20     #![forbid(unused)]
21     #![deny(unused)]
22     //~^ ERROR: deny(unused) incompatible with previous forbid
23     //~| WARNING being phased out
24     //~| ERROR: deny(unused) incompatible with previous forbid
25     //~| WARNING being phased out
26     #![warn(unused)]
27     #![allow(unused)]
28
29     num * num
30 }
31
32 fn forbid_last(num: i32) -> i32 {
33     #![deny(unused)]
34     #![warn(unused)]
35     #![allow(unused)]
36     #![forbid(unused)]
37
38     num * num
39 }
40
41 fn forbid_multiple(num: i32) -> i32 {
42     #![forbid(unused)]
43     #![forbid(unused)]
44
45     num * num
46 }
47
48 fn main() {
49     forbid_first(10);
50     forbid_last(10);
51     forbid_multiple(10);
52 }