]> git.proxmox.com Git - rustc.git/blob - src/test/ui/loops/loops-reject-duplicate-labels.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / ui / loops / loops-reject-duplicate-labels.rs
1 // build-pass (FIXME(62277): could be check-pass?)
2
3 // ignore-tidy-linelength
4
5 // Issue #21633: reject duplicate loop labels in function bodies.
6 // This is testing the exact cases that are in the issue description.
7
8 #[allow(unused_labels)]
9 fn foo() {
10 'fl: for _ in 0..10 { break; }
11 'fl: loop { break; } //~ WARN label name `'fl` shadows a label name that is already in scope
12
13 'lf: loop { break; }
14 'lf: for _ in 0..10 { break; } //~ WARN label name `'lf` shadows a label name that is already in scope
15 'wl: while 2 > 1 { break; }
16 'wl: loop { break; } //~ WARN label name `'wl` shadows a label name that is already in scope
17 'lw: loop { break; }
18 'lw: while 2 > 1 { break; } //~ WARN label name `'lw` shadows a label name that is already in scope
19 'fw: for _ in 0..10 { break; }
20 'fw: while 2 > 1 { break; } //~ WARN label name `'fw` shadows a label name that is already in scope
21 'wf: while 2 > 1 { break; }
22 'wf: for _ in 0..10 { break; } //~ WARN label name `'wf` shadows a label name that is already in scope
23 'tl: while let Some(_) = None::<i32> { break; }
24 'tl: loop { break; } //~ WARN label name `'tl` shadows a label name that is already in scope
25 'lt: loop { break; }
26 'lt: while let Some(_) = None::<i32> { break; }
27 //~^ WARN label name `'lt` shadows a label name that is already in scope
28 }
29
30 // Note however that it is okay for the same label to be reused in
31 // different methods of one impl, as illustrated here.
32
33 struct S;
34 impl S {
35 fn m1(&self) { 'okay: loop { break 'okay; } }
36 fn m2(&self) { 'okay: loop { break 'okay; } }
37 }
38
39
40 pub fn main() {
41 let s = S;
42 s.m1();
43 s.m2();
44 foo();
45 }