|
| 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 | +} |
0 commit comments