```compile_fail,E0268
fn some_func() {
- break; // error: `break` outside of loop
+ break; // error: `break` outside of a loop
}
```
enum Context {
Normal,
Loop(hir::LoopSource),
- Closure,
- AsyncClosure,
+ Closure(Span),
+ AsyncClosure(Span),
LabeledBlock,
AnonConst,
}
hir::ExprKind::Loop(ref b, _, source) => {
self.with_context(Loop(source), |v| v.visit_block(&b));
}
- hir::ExprKind::Closure(_, ref function_decl, b, _, movability) => {
+ hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => {
let cx = if let Some(GeneratorMovability::Static) = movability {
- AsyncClosure
+ AsyncClosure(span)
} else {
- Closure
+ Closure(span)
};
self.visit_fn_decl(&function_decl);
self.with_context(cx, |v| v.visit_nested_body(b));
}
fn require_break_cx(&self, name: &str, span: Span) {
- match self.cx {
- LabeledBlock | Loop(_) => {}
- Closure => {
- struct_span_err!(self.sess, span, E0267, "`{}` inside of a closure", name)
- .span_label(span, "cannot break inside of a closure")
+ let err_inside_of = |article, r#type, closure_span| {
+ struct_span_err!(self.sess, span, E0267, "`{}` inside of {} {}", name, article, r#type)
+ .span_label(span, format!("cannot `{}` inside of {} {}", name, article, r#type))
+ .span_label(closure_span, &format!("enclosing {}", r#type))
.emit();
- }
- AsyncClosure => {
- struct_span_err!(self.sess, span, E0267, "`{}` inside of an async block", name)
- .span_label(span, "cannot break inside of an async block")
- .emit();
- }
+ };
+
+ match self.cx {
+ LabeledBlock | Loop(_) => {},
+ Closure(closure_span) => err_inside_of("a", "closure", closure_span),
+ AsyncClosure(closure_span) => err_inside_of("an", "`async` block", closure_span),
Normal | AnonConst => {
- struct_span_err!(self.sess, span, E0268, "`{}` outside of loop", name)
- .span_label(span, "cannot break outside of a loop")
+ struct_span_err!(self.sess, span, E0268, "`{}` outside of a loop", name)
+ .span_label(span, format!("cannot `{}` outside of a loop", name))
.emit();
- }
+ },
}
}
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/array-break-length.rs:3:17
|
LL | |_: [_; break]| {}
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
-error[E0268]: `continue` outside of loop
+error[E0268]: `continue` outside of a loop
--> $DIR/array-break-length.rs:8:17
|
LL | |_: [_; continue]| {}
- | ^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^ cannot `continue` outside of a loop
error[E0308]: mismatched types
--> $DIR/array-break-length.rs:3:9
error[E0267]: `break` inside of an async block
--> $DIR/async-block-control-flow-static-semantics.rs:33:9
|
-LL | break 0u8;
- | ^^^^^^^^^ cannot break inside of an async block
+LL | async {
+ | ___________-
+LL | | break 0u8;
+ | | ^^^^^^^^^ cannot `break` inside of an `async` block
+LL | | };
+ | |_____- enclosing `async` block
error[E0267]: `break` inside of an async block
--> $DIR/async-block-control-flow-static-semantics.rs:40:13
|
-LL | break 0u8;
- | ^^^^^^^^^ cannot break inside of an async block
+LL | async {
+ | _______________-
+LL | | break 0u8;
+ | | ^^^^^^^^^ cannot `break` inside of an `async` block
+LL | | };
+ | |_________- enclosing `async` block
error[E0308]: mismatched types
--> $DIR/async-block-control-flow-static-semantics.rs:13:43
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/break-outside-loop.rs:10:15
|
LL | let pth = break;
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
-error[E0268]: `continue` outside of loop
+error[E0268]: `continue` outside of a loop
--> $DIR/break-outside-loop.rs:11:17
|
LL | if cond() { continue }
- | ^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^ cannot `continue` outside of a loop
error[E0267]: `break` inside of a closure
--> $DIR/break-outside-loop.rs:17:25
|
+LL | foo(|| {
+ | -- enclosing closure
LL | if cond() { break }
- | ^^^^^ cannot break inside of a closure
+ | ^^^^^ cannot `break` inside of a closure
error[E0267]: `continue` inside of a closure
--> $DIR/break-outside-loop.rs:18:25
|
+LL | foo(|| {
+ | -- enclosing closure
+LL | if cond() { break }
LL | if cond() { continue }
- | ^^^^^^^^ cannot break inside of a closure
+ | ^^^^^^^^ cannot `continue` inside of a closure
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/break-outside-loop.rs:24:25
|
LL | let unconstrained = break;
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
error: aborting due to 5 previous errors
-error[E0268]: `continue` outside of loop
+error[E0268]: `continue` outside of a loop
--> $DIR/closure-array-break-length.rs:2:13
|
LL | |_: [_; continue]| {};
- | ^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^ cannot `continue` outside of a loop
-error[E0268]: `continue` outside of loop
+error[E0268]: `continue` outside of a loop
--> $DIR/closure-array-break-length.rs:4:19
|
LL | while |_: [_; continue]| {} {}
- | ^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^ cannot `continue` outside of a loop
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/closure-array-break-length.rs:7:19
|
LL | while |_: [_; break]| {} {}
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
error[E0308]: mismatched types
--> $DIR/closure-array-break-length.rs:4:11
--> $DIR/E0267.rs:2:18
|
LL | let w = || { break; };
- | ^^^^^ cannot break inside of a closure
+ | -- ^^^^^ cannot `break` inside of a closure
+ | |
+ | enclosing closure
error: aborting due to previous error
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/E0268.rs:2:5
|
LL | break;
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
error: aborting due to previous error
-error[E0268]: `continue` outside of loop
+error[E0268]: `continue` outside of a loop
--> $DIR/issue-28105.rs:4:5
|
LL | continue
- | ^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^ cannot `continue` outside of a loop
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/issue-28105.rs:6:5
|
LL | break
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
error: aborting due to 2 previous errors
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/issue-43162.rs:3:5
|
LL | break true;
- | ^^^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^^^ cannot `break` outside of a loop
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/issue-43162.rs:7:5
|
LL | break {};
- | ^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^ cannot `break` outside of a loop
error[E0308]: mismatched types
--> $DIR/issue-43162.rs:1:13
LL | |bool: [u8; break 'L]| 0;
| ^^ undeclared label `'L`
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/issue-50576.rs:2:17
|
LL | |bool: [u8; break 'L]| 0;
- | ^^^^^^^^ cannot break outside of a loop
+ | ^^^^^^^^ cannot `break` outside of a loop
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/issue-50576.rs:5:16
|
LL | Vec::<[u8; break]>::new();
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
error: aborting due to 3 previous errors
-error[E0268]: `break` outside of loop
+error[E0268]: `break` outside of a loop
--> $DIR/issue-50581.rs:2:14
|
LL | |_: [u8; break]| ();
- | ^^^^^ cannot break outside of a loop
+ | ^^^^^ cannot `break` outside of a loop
error: aborting due to previous error