Skip to content

Commit 05d4881

Browse files
committed
tests for duplicate label detection.
1 parent c657cf4 commit 05d4881

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
// Issue #21633: reject duplicate loop labels in function bodies.
12+
//
13+
// This is testing the generalization (to the whole function body)
14+
// discussed here:
15+
// http://internals.rust-lang.org/t/psa-rejecting-duplicate-loop-labels/1833
16+
17+
fn main() {
18+
{ 'fl: for _ in 0..10 { break; } } //~ NOTE first label occurrence here
19+
{ 'fl: loop { break; } } //~ ERROR duplicate loop label 'fl in function
20+
21+
{ 'lf: loop { break; } } //~ NOTE first label occurrence here
22+
{ 'lf: for _ in 0..10 { break; } } //~ ERROR duplicate loop label 'lf in function
23+
24+
{ 'wl: while 2 > 1 { break; } } //~ NOTE first label occurrence here
25+
{ 'wl: loop { break; } } //~ ERROR duplicate loop label 'wl in function
26+
27+
{ 'lw: loop { break; } } //~ NOTE first label occurrence here
28+
{ 'lw: while 2 > 1 { break; } } //~ ERROR duplicate loop label 'lw in function
29+
30+
{ 'fw: for _ in 0..10 { break; } } //~ NOTE first label occurrence here
31+
{ 'fw: while 2 > 1 { break; } } //~ ERROR duplicate loop label 'fw in function
32+
33+
{ 'wf: while 2 > 1 { break; } } //~ NOTE first label occurrence here
34+
{ 'wf: for _ in 0..10 { break; } } //~ ERROR duplicate loop label 'wf in function
35+
36+
{ 'tl: while let Some(_) = None::<i32> { break; } } //~ NOTE first label occurrence here
37+
{ 'tl: loop { break; } } //~ ERROR duplicate loop label 'tl in function
38+
39+
{ 'lt: loop { break; } } //~ NOTE first label occurrence here
40+
{ 'lt: while let Some(_) = None::<i32> { break; } }
41+
//~^ ERROR duplicate loop label 'lt in function
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
// Issue #21633: reject duplicate loop labels in function bodies.
12+
// This is testing the exact cases that are in the issue description.
13+
14+
fn main() {
15+
'fl: for _ in 0..10 { break; } //~ NOTE first label occurrence here
16+
'fl: loop { break; } //~ ERROR duplicate loop label 'fl in function
17+
18+
'lf: loop { break; } //~ NOTE first label occurrence here
19+
'lf: for _ in 0..10 { break; } //~ ERROR duplicate loop label 'lf in function
20+
21+
'wl: while 2 > 1 { break; } //~ NOTE first label occurrence here
22+
'wl: loop { break; } //~ ERROR duplicate loop label 'wl in function
23+
24+
'lw: loop { break; } //~ NOTE first label occurrence here
25+
'lw: while 2 > 1 { break; } //~ ERROR duplicate loop label 'lw in function
26+
27+
'fw: for _ in 0..10 { break; } //~ NOTE first label occurrence here
28+
'fw: while 2 > 1 { break; } //~ ERROR duplicate loop label 'fw in function
29+
30+
'wf: while 2 > 1 { break; } //~ NOTE first label occurrence here
31+
'wf: for _ in 0..10 { break; } //~ ERROR duplicate loop label 'wf in function
32+
33+
'tl: while let Some(_) = None::<i32> { break; } //~ NOTE first label occurrence here
34+
'tl: loop { break; } //~ ERROR duplicate loop label 'tl in function
35+
36+
'lt: loop { break; } //~ NOTE first label occurrence here
37+
'lt: while let Some(_) = None::<i32> { break; }
38+
//~^ ERROR duplicate loop label 'lt in function
39+
}

0 commit comments

Comments
 (0)