Skip to content

Commit b13272f

Browse files
authored
Rollup merge of rust-lang#66391 - estebank:if-else-async-ice, r=Centril
Do not ICE in `if` without `else` in `async fn` Fix rust-lang#66387.
2 parents 1452a83 + c0a0a7d commit b13272f

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/librustc_typeck/check/generator_interior.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,13 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
244244
// can be reborrowed without needing to spill to a temporary.
245245
// If this were not the case, then we could conceivably have
246246
// to create intermediate temporaries.)
247-
let ty = self.fcx.tables.borrow().expr_ty(expr);
248-
self.record(ty, scope, Some(expr), expr.span);
247+
//
248+
// The type table might not have information for this expression
249+
// if it is in a malformed scope. (#66387)
250+
if let Some(ty) = self.fcx.tables.borrow().expr_ty_opt(expr) {
251+
self.record(ty, scope, Some(expr), expr.span);
252+
} else {
253+
self.fcx.tcx.sess.delay_span_bug(expr.span, "no type for node");
254+
}
249255
}
250256
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// edition:2018
2+
async fn f() -> i32 {
3+
if true { //~ ERROR if may be missing an else clause
4+
return 0;
5+
}
6+
// An `if` block without `else` causes the type table not to have a type for this expr.
7+
// Check that we do not unconditionally access the type table and we don't ICE.
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0317]: if may be missing an else clause
2+
--> $DIR/issue-66387-if-without-else.rs:3:5
3+
|
4+
LL | / if true {
5+
LL | | return 0;
6+
LL | | }
7+
| |_____^ expected (), found i32
8+
|
9+
= note: expected type `()`
10+
found type `i32`
11+
= note: `if` expressions without `else` evaluate to `()`
12+
= help: consider adding an `else` block that evaluates to the expected type
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0317`.

0 commit comments

Comments
 (0)