Add feature gate label_break_value
This commit is contained in:
parent
128f2b5870
commit
dfa98318e1
|
@ -278,6 +278,7 @@ loop {
|
|||
Make sure to always label the `break`:
|
||||
|
||||
```
|
||||
# #![feature(label_break_value)]
|
||||
'l: loop {
|
||||
'a: {
|
||||
break 'l;
|
||||
|
|
|
@ -466,6 +466,9 @@ declare_features! (
|
|||
|
||||
// inconsistent bounds in where clauses
|
||||
(active, trivial_bounds, "1.28.0", Some(48214), None),
|
||||
|
||||
// 'a: { break 'a; }
|
||||
(active, label_break_value, "1.28.0", Some(48594), None),
|
||||
);
|
||||
|
||||
declare_features! (
|
||||
|
@ -1696,6 +1699,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
"multiple patterns in `if let` and `while let` are unstable");
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Block(_, opt_label) => {
|
||||
if let Some(label) = opt_label {
|
||||
gate_feature_post!(&self, label_break_value, label.ident.span,
|
||||
"labels on blocks are unstable");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_expr(self, e);
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(label_break_value)]
|
||||
|
||||
// Test control flow to follow label_break_value semantics
|
||||
fn label_break(a: bool, b: bool) -> u32 {
|
||||
let mut v = 0;
|
||||
|
|
15
src/test/ui/feature-gate-label_break_value.rs
Normal file
15
src/test/ui/feature-gate-label_break_value.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
'a: { //~ ERROR labels on blocks are unstable
|
||||
break 'a;
|
||||
}
|
||||
}
|
11
src/test/ui/feature-gate-label_break_value.stderr
Normal file
11
src/test/ui/feature-gate-label_break_value.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error[E0658]: labels on blocks are unstable (see issue #48594)
|
||||
--> $DIR/feature-gate-label_break_value.rs:12:5
|
||||
|
|
||||
LL | 'a: { //~ ERROR labels on blocks are unstable
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(label_break_value)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(label_break_value)]
|
||||
|
||||
// Simple continue pointing to an unlabeled break should yield in an error
|
||||
fn continue_simple() {
|
||||
'b: {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
error[E0695]: unlabeled `continue` inside of a labeled block
|
||||
--> $DIR/label_break_value_continue.rs:14:9
|
||||
--> $DIR/label_break_value_continue.rs:16:9
|
||||
|
|
||||
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
|
||||
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label
|
||||
|
||||
error[E0696]: `continue` pointing to a labeled block
|
||||
--> $DIR/label_break_value_continue.rs:21:9
|
||||
--> $DIR/label_break_value_continue.rs:23:9
|
||||
|
|
||||
LL | continue 'b; //~ ERROR `continue` pointing to a labeled block
|
||||
| ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
|
||||
|
|
||||
note: labeled block the continue points to
|
||||
--> $DIR/label_break_value_continue.rs:20:5
|
||||
--> $DIR/label_break_value_continue.rs:22:5
|
||||
|
|
||||
LL | / 'b: {
|
||||
LL | | continue 'b; //~ ERROR `continue` pointing to a labeled block
|
||||
|
@ -19,7 +19,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error[E0695]: unlabeled `continue` inside of a labeled block
|
||||
--> $DIR/label_break_value_continue.rs:29:13
|
||||
--> $DIR/label_break_value_continue.rs:31:13
|
||||
|
|
||||
LL | continue; //~ ERROR unlabeled `continue` inside of a labeled block
|
||||
| ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(label_break_value)]
|
||||
|
||||
// These are forbidden occurences of label-break-value
|
||||
|
||||
fn labeled_unsafe() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
error: expected one of `extern`, `fn`, or `{`, found `'b`
|
||||
--> $DIR/label_break_value_illegal_uses.rs:14:12
|
||||
--> $DIR/label_break_value_illegal_uses.rs:16:12
|
||||
|
|
||||
LL | unsafe 'b: {} //~ ERROR expected one of `extern`, `fn`, or `{`
|
||||
| ^^ expected one of `extern`, `fn`, or `{` here
|
||||
|
||||
error: expected `{`, found `'b`
|
||||
--> $DIR/label_break_value_illegal_uses.rs:18:13
|
||||
--> $DIR/label_break_value_illegal_uses.rs:20:13
|
||||
|
|
||||
LL | if true 'b: {} //~ ERROR expected `{`, found `'b`
|
||||
| -- ^^----
|
||||
|
@ -14,7 +14,7 @@ LL | if true 'b: {} //~ ERROR expected `{`, found `'b`
|
|||
| this `if` statement has a condition, but no block
|
||||
|
||||
error: expected `{`, found `'b`
|
||||
--> $DIR/label_break_value_illegal_uses.rs:22:21
|
||||
--> $DIR/label_break_value_illegal_uses.rs:24:21
|
||||
|
|
||||
LL | if true {} else 'b: {} //~ ERROR expected `{`, found `'b`
|
||||
| ^^----
|
||||
|
@ -22,7 +22,7 @@ LL | if true {} else 'b: {} //~ ERROR expected `{`, found `'b`
|
|||
| help: try placing this code inside a block: `{ 'b: { } }`
|
||||
|
||||
error: expected one of `.`, `?`, `{`, or an operator, found `'b`
|
||||
--> $DIR/label_break_value_illegal_uses.rs:26:17
|
||||
--> $DIR/label_break_value_illegal_uses.rs:28:17
|
||||
|
|
||||
LL | match false 'b: {} //~ ERROR expected one of `.`, `?`, `{`, or an operator
|
||||
| ^^ expected one of `.`, `?`, `{`, or an operator here
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(label_break_value)]
|
||||
|
||||
// Simple unlabeled break should yield in an error
|
||||
fn unlabeled_break_simple() {
|
||||
'b: {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
error[E0695]: unlabeled `break` inside of a labeled block
|
||||
--> $DIR/label_break_value_unlabeled_break.rs:14:9
|
||||
--> $DIR/label_break_value_unlabeled_break.rs:16:9
|
||||
|
|
||||
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
|
||||
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label
|
||||
|
||||
error[E0695]: unlabeled `break` inside of a labeled block
|
||||
--> $DIR/label_break_value_unlabeled_break.rs:22:13
|
||||
--> $DIR/label_break_value_unlabeled_break.rs:24:13
|
||||
|
|
||||
LL | break; //~ ERROR unlabeled `break` inside of a labeled block
|
||||
| ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label
|
||||
|
|
Loading…
Reference in a new issue