]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hygiene/hygienic-labels.rs
Require Drop impls to have the same constness on its bounds as the bounds on the...
[rust.git] / src / test / ui / hygiene / hygienic-labels.rs
1 // run-pass
2 #![allow(unreachable_code)]
3 #![allow(unused_labels)]
4 // Test that labels injected by macros do not break hygiene.
5
6 // Issue #24278: The label/lifetime shadowing checker from #24162
7 // conservatively ignores hygiene, and thus issues warnings that are
8 // both true- and false-positives for this test.
9
10 macro_rules! loop_x {
11     ($e: expr) => {
12         // $e shouldn't be able to interact with this 'x
13         'x: loop {
14             $e
15         }
16     };
17 }
18
19 macro_rules! run_once {
20     ($e: expr) => {
21         // ditto
22         'x: for _ in 0..1 {
23             $e
24         }
25     };
26 }
27
28 macro_rules! while_x {
29     ($e: expr) => {
30         // ditto
31         'x: while 1 + 1 == 2 {
32             $e
33         }
34     };
35 }
36
37 pub fn main() {
38     'x: for _ in 0..1 {
39         // this 'x should refer to the outer loop, lexically
40         loop_x!(break 'x);
41         panic!("break doesn't act hygienically inside for loop");
42     }
43
44     'x: loop {
45         // ditto
46         loop_x!(break 'x);
47         panic!("break doesn't act hygienically inside infinite loop");
48     }
49
50     'x: while 1 + 1 == 2 {
51         while_x!(break 'x);
52         panic!("break doesn't act hygienically inside infinite while loop");
53     }
54
55     'x: for _ in 0..1 {
56         // ditto
57         run_once!(continue 'x);
58         panic!("continue doesn't act hygienically inside for loop");
59     }
60 }