2019-07-02 23:30:28 +02:00
|
|
|
// build-pass (FIXME(62277): could be check-pass?)
|
2015-04-08 18:37:47 +02:00
|
|
|
|
|
|
|
// ignore-tidy-linelength
|
|
|
|
|
|
|
|
// Issue #21633: reject duplicate loop labels in function bodies.
|
|
|
|
// This is testing the exact cases that are in the issue description.
|
|
|
|
|
2018-05-18 02:20:30 +02:00
|
|
|
#[allow(unused_labels)]
|
2015-04-08 18:37:47 +02:00
|
|
|
fn foo() {
|
2017-12-10 21:29:24 +01:00
|
|
|
'fl: for _ in 0..10 { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'fl: loop { break; } //~ WARN label name `'fl` shadows a label name that is already in scope
|
|
|
|
|
2017-12-10 21:29:24 +01:00
|
|
|
'lf: loop { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'lf: for _ in 0..10 { break; } //~ WARN label name `'lf` shadows a label name that is already in scope
|
2017-12-10 21:29:24 +01:00
|
|
|
'wl: while 2 > 1 { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'wl: loop { break; } //~ WARN label name `'wl` shadows a label name that is already in scope
|
2017-12-10 21:29:24 +01:00
|
|
|
'lw: loop { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'lw: while 2 > 1 { break; } //~ WARN label name `'lw` shadows a label name that is already in scope
|
2017-12-10 21:29:24 +01:00
|
|
|
'fw: for _ in 0..10 { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'fw: while 2 > 1 { break; } //~ WARN label name `'fw` shadows a label name that is already in scope
|
2017-12-10 21:29:24 +01:00
|
|
|
'wf: while 2 > 1 { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'wf: for _ in 0..10 { break; } //~ WARN label name `'wf` shadows a label name that is already in scope
|
2017-12-10 21:29:24 +01:00
|
|
|
'tl: while let Some(_) = None::<i32> { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'tl: loop { break; } //~ WARN label name `'tl` shadows a label name that is already in scope
|
2017-12-10 21:29:24 +01:00
|
|
|
'lt: loop { break; }
|
2015-04-08 18:37:47 +02:00
|
|
|
'lt: while let Some(_) = None::<i32> { break; }
|
2016-08-28 12:57:38 +02:00
|
|
|
//~^ WARN label name `'lt` shadows a label name that is already in scope
|
2015-04-08 18:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note however that it is okay for the same label to be reused in
|
|
|
|
// different methods of one impl, as illustrated here.
|
|
|
|
|
|
|
|
struct S;
|
|
|
|
impl S {
|
|
|
|
fn m1(&self) { 'okay: loop { break 'okay; } }
|
|
|
|
fn m2(&self) { 'okay: loop { break 'okay; } }
|
|
|
|
}
|
|
|
|
|
2018-10-31 13:08:01 +01:00
|
|
|
|
|
|
|
pub fn main() {
|
2015-04-08 18:37:47 +02:00
|
|
|
let s = S;
|
|
|
|
s.m1();
|
|
|
|
s.m2();
|
|
|
|
foo();
|
|
|
|
}
|