about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-06 00:11:47 +0100
committerGitHub <noreply@github.com>2021-12-06 00:11:47 +0100
commitbd98a79eea30a0363beefddbb971b89e2b389660 (patch)
tree07744e4c2ddc81744fe3cb1e77d0ffda27f84781
parente2116acae59654bfab2a9729a024f3e2fd6d4b02 (diff)
parenta8daff2724789ca8be9f2c36bb19be553180bd59 (diff)
downloadrust-bd98a79eea30a0363beefddbb971b89e2b389660.tar.gz
rust-bd98a79eea30a0363beefddbb971b89e2b389660.zip
Rollup merge of #91367 - FabianWolff:issue-91334-ice, r=nagisa
Fix ICE in `check_must_not_suspend_ty()`

Fixes #91334. I have also used `TyS::tuple_fields()` (instead of the `SubstsRef` directly) to get the tuple fields, because that's what [the documentation](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html#variant.Tuple) says, although it doesn't seem to make a difference in practice (this is not what fixed the ICE).
-rw-r--r--compiler/rustc_typeck/src/check/generator_interior.rs24
-rw-r--r--src/test/ui/typeck/issue-91334.rs10
-rw-r--r--src/test/ui/typeck/issue-91334.stderr50
3 files changed, 75 insertions, 9 deletions
diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs
index 2910ce6de68..37e601fa404 100644
--- a/compiler/rustc_typeck/src/check/generator_interior.rs
+++ b/compiler/rustc_typeck/src/check/generator_interior.rs
@@ -536,22 +536,28 @@ pub fn check_must_not_suspend_ty<'tcx>(
             }
             has_emitted
         }
-        ty::Tuple(ref tys) => {
+        ty::Tuple(_) => {
             let mut has_emitted = false;
-            let spans = if let Some(hir::ExprKind::Tup(comps)) = data.expr.map(|e| &e.kind) {
-                debug_assert_eq!(comps.len(), tys.len());
-                comps.iter().map(|e| e.span).collect()
-            } else {
-                vec![]
+            let comps = match data.expr.map(|e| &e.kind) {
+                Some(hir::ExprKind::Tup(comps)) => {
+                    debug_assert_eq!(comps.len(), ty.tuple_fields().count());
+                    Some(comps)
+                }
+                _ => None,
             };
-            for (i, ty) in tys.iter().map(|k| k.expect_ty()).enumerate() {
+            for (i, ty) in ty.tuple_fields().enumerate() {
                 let descr_post = &format!(" in tuple element {}", i);
-                let span = *spans.get(i).unwrap_or(&data.source_span);
+                let span = comps.and_then(|c| c.get(i)).map(|e| e.span).unwrap_or(data.source_span);
                 if check_must_not_suspend_ty(
                     fcx,
                     ty,
                     hir_id,
-                    SuspendCheckData { descr_post, source_span: span, ..data },
+                    SuspendCheckData {
+                        descr_post,
+                        expr: comps.and_then(|comps| comps.get(i)),
+                        source_span: span,
+                        ..data
+                    },
                 ) {
                     has_emitted = true;
                 }
diff --git a/src/test/ui/typeck/issue-91334.rs b/src/test/ui/typeck/issue-91334.rs
new file mode 100644
index 00000000000..bf9a5a62620
--- /dev/null
+++ b/src/test/ui/typeck/issue-91334.rs
@@ -0,0 +1,10 @@
+// Regression test for the ICE described in issue #91334.
+
+// error-pattern: this file contains an unclosed delimiter
+// error-pattern: expected one of
+// error-pattern: mismatched closing delimiter
+// error-pattern: mismatched types
+
+#![feature(generators)]
+
+fn f(){||yield(((){),
diff --git a/src/test/ui/typeck/issue-91334.stderr b/src/test/ui/typeck/issue-91334.stderr
new file mode 100644
index 00000000000..358cc771b7c
--- /dev/null
+++ b/src/test/ui/typeck/issue-91334.stderr
@@ -0,0 +1,50 @@
+error: this file contains an unclosed delimiter
+  --> $DIR/issue-91334.rs:10:23
+   |
+LL | fn f(){||yield(((){),
+   |       -       -       ^
+   |       |       |
+   |       |       unclosed delimiter
+   |       unclosed delimiter
+
+error: this file contains an unclosed delimiter
+  --> $DIR/issue-91334.rs:10:23
+   |
+LL | fn f(){||yield(((){),
+   |       -       -       ^
+   |       |       |
+   |       |       unclosed delimiter
+   |       unclosed delimiter
+
+error: expected one of `)`, `,`, `.`, `?`, or an operator, found `{`
+  --> $DIR/issue-91334.rs:10:19
+   |
+LL | fn f(){||yield(((){),
+   |                   ^
+   |                   |
+   |                   expected one of `)`, `,`, `.`, `?`, or an operator
+   |                   help: missing `,`
+
+error: mismatched closing delimiter: `)`
+  --> $DIR/issue-91334.rs:10:19
+   |
+LL | fn f(){||yield(((){),
+   |                -  ^^ mismatched closing delimiter
+   |                |  |
+   |                |  unclosed delimiter
+   |                closing delimiter possibly meant for this
+
+error[E0308]: mismatched types
+  --> $DIR/issue-91334.rs:10:8
+   |
+LL | fn f(){||yield(((){),
+   |       -^^^^^^^^^^^^^^^ expected `()`, found generator
+   |       |
+   |       help: try adding a return type: `-> [generator@$DIR/issue-91334.rs:10:8: 10:23]`
+   |
+   = note: expected unit type `()`
+              found generator `[generator@$DIR/issue-91334.rs:10:8: 10:23]`
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0308`.