]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hygiene/hygienic-labels.rs
Rollup merge of #90202 - matthewjasper:xcrate-hygiene, r=petrochenkov
[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 { $e }
14         //~^ WARNING shadows a label name that is already in scope
15         //~| WARNING shadows a label name that is already in scope
16         //~| WARNING shadows a label name that is already in scope
17         //~| WARNING shadows a label name that is already in scope
18     }
19 }
20
21 macro_rules! run_once {
22     ($e: expr) => {
23         // ditto
24         'x: for _ in 0..1 { $e }
25         //~^ WARNING shadows a label name that is already in scope
26         //~| WARNING shadows a label name that is already in scope
27         //~| WARNING shadows a label name that is already in scope
28         //~| WARNING shadows a label name that is already in scope
29         //~| WARNING shadows a label name that is already in scope
30         //~| WARNING shadows a label name that is already in scope
31         //~| WARNING shadows a label name that is already in scope
32     }
33 }
34
35 macro_rules! while_x {
36     ($e: expr) => {
37         // ditto
38         'x: while 1 + 1 == 2 { $e }
39         //~^ WARNING shadows a label name that is already in scope
40         //~| WARNING shadows a label name that is already in scope
41         //~| WARNING shadows a label name that is already in scope
42         //~| WARNING shadows a label name that is already in scope
43         //~| WARNING shadows a label name that is already in scope
44     }
45 }
46
47 pub fn main() {
48     'x: for _ in 0..1 {
49         // this 'x should refer to the outer loop, lexically
50         loop_x!(break 'x);
51         panic!("break doesn't act hygienically inside for loop");
52     }
53
54     'x: loop {
55         //~^ WARNING shadows a label name that is already in scope
56         //~| WARNING shadows a label name that is already in scope
57
58         // ditto
59         loop_x!(break 'x);
60         panic!("break doesn't act hygienically inside infinite loop");
61     }
62
63     'x: while 1 + 1 == 2 {
64         //~^ WARNING shadows a label name that is already in scope
65         //~| WARNING shadows a label name that is already in scope
66         //~| WARNING shadows a label name that is already in scope
67         //~| WARNING shadows a label name that is already in scope
68
69         while_x!(break 'x);
70         panic!("break doesn't act hygienically inside infinite while loop");
71     }
72
73     'x: for _ in 0..1 {
74         //~^ WARNING shadows a label name that is already in scope
75         //~| WARNING shadows a label name that is already in scope
76         //~| WARNING shadows a label name that is already in scope
77         //~| WARNING shadows a label name that is already in scope
78         //~| WARNING shadows a label name that is already in scope
79         //~| WARNING shadows a label name that is already in scope
80
81         // ditto
82         run_once!(continue 'x);
83         panic!("continue doesn't act hygienically inside for loop");
84     }
85 }