diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index ff9c945eec452..6e254122c0100 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -244,7 +244,13 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { // can be reborrowed without needing to spill to a temporary. // If this were not the case, then we could conceivably have // to create intermediate temporaries.) - let ty = self.fcx.tables.borrow().expr_ty(expr); - self.record(ty, scope, Some(expr), expr.span); + // + // The type table might not have invormation for this expression + // if it is in a malformed scope. (#66387) + if let Some(ty) = self.fcx.tables.borrow().expr_ty_opt(expr) { + self.record(ty, scope, Some(expr), expr.span); + } else { + self.fcx.tcx.sess.delay_span_bug(expr.span, "no type for node"); + } } } diff --git a/src/test/ui/async-await/issue-66387-if-without-else.rs b/src/test/ui/async-await/issue-66387-if-without-else.rs new file mode 100644 index 0000000000000..3602b09c0ece7 --- /dev/null +++ b/src/test/ui/async-await/issue-66387-if-without-else.rs @@ -0,0 +1,8 @@ +// edition:2018 +async fn f() -> i32 { + if true { //~ ERROR if may be missing an else clause + return 0; + } +} + +fn main() {} diff --git a/src/test/ui/async-await/issue-66387-if-without-else.stderr b/src/test/ui/async-await/issue-66387-if-without-else.stderr new file mode 100644 index 0000000000000..32952059525a0 --- /dev/null +++ b/src/test/ui/async-await/issue-66387-if-without-else.stderr @@ -0,0 +1,16 @@ +error[E0317]: if may be missing an else clause + --> $DIR/issue-66387-if-without-else.rs:3:5 + | +LL | / if true { +LL | | return 0; +LL | | } + | |_____^ expected (), found i32 + | + = note: expected type `()` + found type `i32` + = note: `if` expressions without `else` evaluate to `()` + = help: consider adding an `else` block that evaluates to the expected type + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0317`.