]> git.proxmox.com Git - rustc.git/blob - src/test/ui/hygiene/hygienic-labels-in-let.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / hygiene / hygienic-labels-in-let.rs
1 // run-pass
2 #![allow(unreachable_code)]
3 #![allow(unused_labels)]
4
5 // Test that labels injected by macros do not break hygiene. This
6 // checks cases where the macros invocations are under the rhs of a
7 // let statement.
8
9 // Issue #24278: The label/lifetime shadowing checker from #24162
10 // conservatively ignores hygiene, and thus issues warnings that are
11 // both true- and false-positives for this test.
12
13 macro_rules! loop_x {
14 ($e: expr) => {
15 // $e shouldn't be able to interact with this 'x
16 'x: loop {
17 $e
18 }
19 };
20 }
21
22 macro_rules! while_true {
23 ($e: expr) => {
24 // $e shouldn't be able to interact with this 'x
25 'x: while 1 + 1 == 2 {
26 $e
27 }
28 };
29 }
30
31 macro_rules! run_once {
32 ($e: expr) => {
33 // ditto
34 'x: for _ in 0..1 {
35 $e
36 }
37 };
38 }
39
40 pub fn main() {
41 let mut i = 0;
42
43 let j: isize = {
44 'x: loop {
45 // this 'x should refer to the outer loop, lexically
46 loop_x!(break 'x);
47 i += 1;
48 }
49 i + 1
50 };
51 assert_eq!(j, 1);
52
53 let k: isize = {
54 'x: for _ in 0..1 {
55 // ditto
56 loop_x!(break 'x);
57 i += 1;
58 }
59 i + 1
60 };
61 assert_eq!(k, 1);
62
63 let l: isize = {
64 'x: for _ in 0..1 {
65 // ditto
66 while_true!(break 'x);
67 i += 1;
68 }
69 i + 1
70 };
71 assert_eq!(l, 1);
72
73 let n: isize = {
74 'x: for _ in 0..1 {
75 // ditto
76 run_once!(continue 'x);
77 i += 1;
78 }
79 i + 1
80 };
81 assert_eq!(n, 1);
82 }