Skip to content

Commit

Permalink
Add feature gate label_break_value
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed May 16, 2018
1 parent 128f2b5 commit dfa9831
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/librustc_passes/diagnostics.rs
Expand Up @@ -278,6 +278,7 @@ loop {
Make sure to always label the `break`:
```
# #![feature(label_break_value)]
'l: loop {
'a: {
break 'l;
Expand Down
9 changes: 9 additions & 0 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -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! (
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/label_break_value.rs
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/feature-gate-label_break_value.rs
@@ -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 changes: 11 additions & 0 deletions src/test/ui/feature-gate-label_break_value.stderr
@@ -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`.
2 changes: 2 additions & 0 deletions src/test/ui/label_break_value_continue.rs
Expand Up @@ -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: {
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/label_break_value_continue.stderr
@@ -1,25 +1,25 @@
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
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
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/label_break_value_illegal_uses.rs
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/label_break_value_illegal_uses.stderr
@@ -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`
| -- ^^----
Expand All @@ -14,15 +14,15 @@ 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`
| ^^----
| |
| 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
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/label_break_value_unlabeled_break.rs
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/label_break_value_unlabeled_break.stderr
@@ -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
Expand Down

0 comments on commit dfa9831

Please sign in to comment.