Skip to content

Commit f68ee0b

Browse files
committed
Fix an ICE with continue as an array length
1 parent 4fe88c0 commit f68ee0b

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3846,7 +3846,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38463846
}
38473847

38483848
}
3849-
hir::ExprContinue(_) => { tcx.types.never }
3849+
hir::ExprContinue(destination) => {
3850+
if let Ok(_) = destination.target_id {
3851+
tcx.types.never
3852+
} else {
3853+
// There was an error, make typecheck fail
3854+
tcx.types.err
3855+
}
3856+
}
38503857
hir::ExprRet(ref expr_opt) => {
38513858
if self.ret_coercion.is_none() {
38523859
struct_span_err!(self.tcx.sess, expr.span, E0572,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
fn main() {
12+
|_: [_; continue]| {}; //~ ERROR: `continue` outside of loop
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0268]: `continue` outside of loop
2+
--> $DIR/closure-array-break-length.rs:12:13
3+
|
4+
LL | |_: [_; continue]| {}; //~ ERROR: `continue` outside of loop
5+
| ^^^^^^^^ cannot break outside of a loop
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0268`.

0 commit comments

Comments
 (0)