Skip to content

Commit 8ddf9a3

Browse files
committed
Accept TyError in analyze_closure to avoid ICE
1 parent 4dc2d74 commit 8ddf9a3

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/librustc_typeck/check/upvar.rs

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
111111
let (closure_def_id, substs) = match self.node_ty(closure_hir_id).sty {
112112
ty::TyClosure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs)),
113113
ty::TyGenerator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)),
114+
ty::TyError => {
115+
// #51714: skip analysis when we have already encountered type errors
116+
return;
117+
}
114118
ref t => {
115119
span_bug!(
116120
span,

src/test/ui/issue-51714.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
|_: [_; return || {}] | {}
13+
//~^ ERROR return statement outside of function body
14+
}
15+
16+
fn foo() {
17+
[(); return || {}];
18+
//~^ ERROR return statement outside of function body
19+
}

src/test/ui/issue-51714.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0572]: return statement outside of function body
2+
--> $DIR/issue-51714.rs:12:14
3+
|
4+
LL | |_: [_; return || {}] | {}
5+
| ^^^^^^^^^^^^
6+
7+
error[E0572]: return statement outside of function body
8+
--> $DIR/issue-51714.rs:17:10
9+
|
10+
LL | [(); return || {}];
11+
| ^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0572`.

0 commit comments

Comments
 (0)