diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-11-15 18:36:28 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-15 18:36:28 +0900 |
| commit | c5b6dceb68d4f05d26d5b59602d5a0c205ed2233 (patch) | |
| tree | 2e79339628c706cffd77642582a7de723a1620cd | |
| parent | 1baa7724ba45b486d3cadea1a5c0e0c948f1ea81 (diff) | |
| parent | c0a0a7d711b89d89e04a135d6035a2881a7de72e (diff) | |
| download | rust-c5b6dceb68d4f05d26d5b59602d5a0c205ed2233.tar.gz rust-c5b6dceb68d4f05d26d5b59602d5a0c205ed2233.zip | |
Rollup merge of #66391 - estebank:if-else-async-ice, r=Centril
Do not ICE in `if` without `else` in `async fn` Fix #66387.
| -rw-r--r-- | src/librustc_typeck/check/generator_interior.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/async-await/issue-66387-if-without-else.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/async-await/issue-66387-if-without-else.stderr | 16 |
3 files changed, 34 insertions, 2 deletions
diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index ff9c945eec4..6e37c0dbbdf 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 information 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 00000000000..aa5a8db6121 --- /dev/null +++ b/src/test/ui/async-await/issue-66387-if-without-else.rs @@ -0,0 +1,10 @@ +// edition:2018 +async fn f() -> i32 { + if true { //~ ERROR if may be missing an else clause + return 0; + } + // An `if` block without `else` causes the type table not to have a type for this expr. + // Check that we do not unconditionally access the type table and we don't ICE. +} + +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 00000000000..32952059525 --- /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`. |
