]> git.lizzy.rs Git - rust.git/blob - src/test/ui/loops-reject-duplicate-labels-2.rs
Auto merge of #50665 - alexcrichton:fix-single-item-path-warnings, r=oli-obk
[rust.git] / src / test / ui / loops-reject-duplicate-labels-2.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(rustc_attrs)]
12
13 // ignore-tidy-linelength
14
15 // Issue #21633: reject duplicate loop labels in function bodies.
16 //
17 // This is testing the generalization (to the whole function body)
18 // discussed here:
19 // https://internals.rust-lang.org/t/psa-rejecting-duplicate-loop-labels/1833
20
21 pub fn foo() {
22     { 'fl: for _ in 0..10 { break; } }
23     { 'fl: loop { break; } }             //~ WARN label name `'fl` shadows a label name that is already in scope
24     { 'lf: loop { break; } }
25     { 'lf: for _ in 0..10 { break; } }   //~ WARN label name `'lf` shadows a label name that is already in scope
26     { 'wl: while 2 > 1 { break; } }
27     { 'wl: loop { break; } }             //~ WARN label name `'wl` shadows a label name that is already in scope
28     { 'lw: loop { break; } }
29     { 'lw: while 2 > 1 { break; } }      //~ WARN label name `'lw` shadows a label name that is already in scope
30     { 'fw: for _ in 0..10 { break; } }
31     { 'fw: while 2 > 1 { break; } }      //~ WARN label name `'fw` shadows a label name that is already in scope
32     { 'wf: while 2 > 1 { break; } }
33     { 'wf: for _ in 0..10 { break; } }   //~ WARN label name `'wf` shadows a label name that is already in scope
34     { 'tl: while let Some(_) = None::<i32> { break; } }
35     { 'tl: loop { break; } }             //~ WARN label name `'tl` shadows a label name that is already in scope
36     { 'lt: loop { break; } }
37     { 'lt: while let Some(_) = None::<i32> { break; } }
38                                          //~^ WARN label name `'lt` shadows a label name that is already in scope
39 }
40
41 #[rustc_error]
42 pub fn main() { //~ ERROR compilation successful
43     foo();
44 }