]> git.proxmox.com Git - rustc.git/blame - src/test/ui/loops/loops-reject-duplicate-labels.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / test / ui / loops / loops-reject-duplicate-labels.rs
CommitLineData
f9f354fc 1// check-pass
c295e0f8 2#![feature(label_break_value)]
9346a6ac 3
c295e0f8 4// Issue #21633: reject duplicate loop labels and block labels in function bodies.
9346a6ac 5
94b46f34 6#[allow(unused_labels)]
9346a6ac 7fn foo() {
ff7c6d11 8 'fl: for _ in 0..10 { break; }
9346a6ac
AL
9 'fl: loop { break; } //~ WARN label name `'fl` shadows a label name that is already in scope
10
ff7c6d11 11 'lf: loop { break; }
9346a6ac 12 'lf: for _ in 0..10 { break; } //~ WARN label name `'lf` shadows a label name that is already in scope
ff7c6d11 13 'wl: while 2 > 1 { break; }
9346a6ac 14 'wl: loop { break; } //~ WARN label name `'wl` shadows a label name that is already in scope
ff7c6d11 15 'lw: loop { break; }
9346a6ac 16 'lw: while 2 > 1 { break; } //~ WARN label name `'lw` shadows a label name that is already in scope
ff7c6d11 17 'fw: for _ in 0..10 { break; }
9346a6ac 18 'fw: while 2 > 1 { break; } //~ WARN label name `'fw` shadows a label name that is already in scope
ff7c6d11 19 'wf: while 2 > 1 { break; }
9346a6ac 20 'wf: for _ in 0..10 { break; } //~ WARN label name `'wf` shadows a label name that is already in scope
ff7c6d11 21 'tl: while let Some(_) = None::<i32> { break; }
9346a6ac 22 'tl: loop { break; } //~ WARN label name `'tl` shadows a label name that is already in scope
ff7c6d11 23 'lt: loop { break; }
9346a6ac 24 'lt: while let Some(_) = None::<i32> { break; }
9e0c209e 25 //~^ WARN label name `'lt` shadows a label name that is already in scope
c295e0f8
XL
26 'bl: {}
27 'bl: {} //~ WARN label name `'bl` shadows a label name that is already in scope
9346a6ac
AL
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
33struct S;
34impl S {
35 fn m1(&self) { 'okay: loop { break 'okay; } }
36 fn m2(&self) { 'okay: loop { break 'okay; } }
c295e0f8
XL
37 fn m3(&self) { 'okay: { break 'okay; } }
38 fn m4(&self) { 'okay: { break 'okay; } }
9346a6ac
AL
39}
40
a1dfa0c6
XL
41
42pub fn main() {
9346a6ac
AL
43 let s = S;
44 s.m1();
45 s.m2();
c295e0f8
XL
46 s.m3();
47 s.m4();
9346a6ac
AL
48 foo();
49}