From 4042f550795c042aee3087b0e0dcb7083e7a9e00 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 17 Dec 2022 19:20:29 +0000 Subject: [PATCH] Don't ICE in check_must_not_suspend_ty for mismatched tuple arity --- .../rustc_hir_typeck/src/generator_interior/mod.rs | 5 +---- src/test/ui/lint/must_not_suspend/tuple-mismatch.rs | 9 +++++++++ .../ui/lint/must_not_suspend/tuple-mismatch.stderr | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/lint/must_not_suspend/tuple-mismatch.rs create mode 100644 src/test/ui/lint/must_not_suspend/tuple-mismatch.stderr diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 93f2ceed777b5..e4ac91befac61 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -607,10 +607,7 @@ fn check_must_not_suspend_ty<'tcx>( ty::Tuple(fields) => { let mut has_emitted = false; let comps = match data.expr.map(|e| &e.kind) { - Some(hir::ExprKind::Tup(comps)) => { - debug_assert_eq!(comps.len(), fields.len()); - Some(comps) - } + Some(hir::ExprKind::Tup(comps)) if comps.len() == fields.len() => Some(comps), _ => None, }; for (i, ty) in fields.iter().enumerate() { diff --git a/src/test/ui/lint/must_not_suspend/tuple-mismatch.rs b/src/test/ui/lint/must_not_suspend/tuple-mismatch.rs new file mode 100644 index 0000000000000..c7e14e4256138 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/tuple-mismatch.rs @@ -0,0 +1,9 @@ +#![feature(generators)] + +fn main() { + let _generator = || { + yield ((), ((), ())); + yield ((), ()); + //~^ ERROR mismatched types + }; +} diff --git a/src/test/ui/lint/must_not_suspend/tuple-mismatch.stderr b/src/test/ui/lint/must_not_suspend/tuple-mismatch.stderr new file mode 100644 index 0000000000000..cca8cd9bd89f1 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/tuple-mismatch.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/tuple-mismatch.rs:6:20 + | +LL | yield ((), ()); + | ^^ expected tuple, found `()` + | + = note: expected tuple `((), ())` + found unit type `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.