Skip to content

Commit dfa9831

Browse files
committed
Add feature gate label_break_value
1 parent 128f2b5 commit dfa9831

11 files changed

+54
-10
lines changed

src/librustc_passes/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ loop {
278278
Make sure to always label the `break`:
279279
280280
```
281+
# #![feature(label_break_value)]
281282
'l: loop {
282283
'a: {
283284
break 'l;

src/libsyntax/feature_gate.rs

+9
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ declare_features! (
466466

467467
// inconsistent bounds in where clauses
468468
(active, trivial_bounds, "1.28.0", Some(48214), None),
469+
470+
// 'a: { break 'a; }
471+
(active, label_break_value, "1.28.0", Some(48594), None),
469472
);
470473

471474
declare_features! (
@@ -1696,6 +1699,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
16961699
"multiple patterns in `if let` and `while let` are unstable");
16971700
}
16981701
}
1702+
ast::ExprKind::Block(_, opt_label) => {
1703+
if let Some(label) = opt_label {
1704+
gate_feature_post!(&self, label_break_value, label.ident.span,
1705+
"labels on blocks are unstable");
1706+
}
1707+
}
16991708
_ => {}
17001709
}
17011710
visit::walk_expr(self, e);

src/test/run-pass/label_break_value.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(label_break_value)]
12+
1113
// Test control flow to follow label_break_value semantics
1214
fn label_break(a: bool, b: bool) -> u32 {
1315
let mut v = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018 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+
pub fn main() {
12+
'a: { //~ ERROR labels on blocks are unstable
13+
break 'a;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: labels on blocks are unstable (see issue #48594)
2+
--> $DIR/feature-gate-label_break_value.rs:12:5
3+
|
4+
LL | 'a: { //~ ERROR labels on blocks are unstable
5+
| ^^
6+
|
7+
= help: add #![feature(label_break_value)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/label_break_value_continue.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(label_break_value)]
12+
1113
// Simple continue pointing to an unlabeled break should yield in an error
1214
fn continue_simple() {
1315
'b: {

src/test/ui/label_break_value_continue.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error[E0695]: unlabeled `continue` inside of a labeled block
2-
--> $DIR/label_break_value_continue.rs:14:9
2+
--> $DIR/label_break_value_continue.rs:16:9
33
|
44
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
55
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label
66

77
error[E0696]: `continue` pointing to a labeled block
8-
--> $DIR/label_break_value_continue.rs:21:9
8+
--> $DIR/label_break_value_continue.rs:23:9
99
|
1010
LL | continue 'b; //~ ERROR `continue` pointing to a labeled block
1111
| ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
1212
|
1313
note: labeled block the continue points to
14-
--> $DIR/label_break_value_continue.rs:20:5
14+
--> $DIR/label_break_value_continue.rs:22:5
1515
|
1616
LL | / 'b: {
1717
LL | | continue 'b; //~ ERROR `continue` pointing to a labeled block
1818
LL | | }
1919
| |_____^
2020

2121
error[E0695]: unlabeled `continue` inside of a labeled block
22-
--> $DIR/label_break_value_continue.rs:29:13
22+
--> $DIR/label_break_value_continue.rs:31:13
2323
|
2424
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
2525
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label

src/test/ui/label_break_value_illegal_uses.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(label_break_value)]
12+
1113
// These are forbidden occurences of label-break-value
1214

1315
fn labeled_unsafe() {

src/test/ui/label_break_value_illegal_uses.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: expected one of `extern`, `fn`, or `{`, found `'b`
2-
--> $DIR/label_break_value_illegal_uses.rs:14:12
2+
--> $DIR/label_break_value_illegal_uses.rs:16:12
33
|
44
LL | unsafe 'b: {} //~ ERROR expected one of `extern`, `fn`, or `{`
55
| ^^ expected one of `extern`, `fn`, or `{` here
66

77
error: expected `{`, found `'b`
8-
--> $DIR/label_break_value_illegal_uses.rs:18:13
8+
--> $DIR/label_break_value_illegal_uses.rs:20:13
99
|
1010
LL | if true 'b: {} //~ ERROR expected `{`, found `'b`
1111
| -- ^^----
@@ -14,15 +14,15 @@ LL | if true 'b: {} //~ ERROR expected `{`, found `'b`
1414
| this `if` statement has a condition, but no block
1515

1616
error: expected `{`, found `'b`
17-
--> $DIR/label_break_value_illegal_uses.rs:22:21
17+
--> $DIR/label_break_value_illegal_uses.rs:24:21
1818
|
1919
LL | if true {} else 'b: {} //~ ERROR expected `{`, found `'b`
2020
| ^^----
2121
| |
2222
| help: try placing this code inside a block: `{ 'b: { } }`
2323

2424
error: expected one of `.`, `?`, `{`, or an operator, found `'b`
25-
--> $DIR/label_break_value_illegal_uses.rs:26:17
25+
--> $DIR/label_break_value_illegal_uses.rs:28:17
2626
|
2727
LL | match false 'b: {} //~ ERROR expected one of `.`, `?`, `{`, or an operator
2828
| ^^ expected one of `.`, `?`, `{`, or an operator here

src/test/ui/label_break_value_unlabeled_break.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(label_break_value)]
12+
1113
// Simple unlabeled break should yield in an error
1214
fn unlabeled_break_simple() {
1315
'b: {

src/test/ui/label_break_value_unlabeled_break.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0695]: unlabeled `break` inside of a labeled block
2-
--> $DIR/label_break_value_unlabeled_break.rs:14:9
2+
--> $DIR/label_break_value_unlabeled_break.rs:16:9
33
|
44
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
55
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label
66

77
error[E0695]: unlabeled `break` inside of a labeled block
8-
--> $DIR/label_break_value_unlabeled_break.rs:22:13
8+
--> $DIR/label_break_value_unlabeled_break.rs:24:13
99
|
1010
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
1111
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label

0 commit comments

Comments
 (0)