From 4dbb48d2892f46330dfb701fabf4feb9e11c606f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 22 Feb 2024 14:41:32 +1100 Subject: [PATCH] Make "tuple pattern not applied to a tuple" a `span_delayed_bug`. Fixes #121410. --- .../rustc_hir_typeck/src/mem_categorization.rs | 3 ++- tests/ui/typeck/issue-121410.rs | 15 +++++++++++++++ tests/ui/typeck/issue-121410.stderr | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/ui/typeck/issue-121410.rs create mode 100644 tests/ui/typeck/issue-121410.stderr diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index c300ec7444b2e..1a860aa406791 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -582,7 +582,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { match ty.kind() { ty::Tuple(args) => Ok(args.len()), _ => { - self.tcx().dcx().span_bug(span, "tuple pattern not applied to a tuple"); + self.tcx().dcx().span_delayed_bug(span, "tuple pattern not applied to a tuple"); + Err(()) } } } diff --git a/tests/ui/typeck/issue-121410.rs b/tests/ui/typeck/issue-121410.rs new file mode 100644 index 0000000000000..324b398d74f77 --- /dev/null +++ b/tests/ui/typeck/issue-121410.rs @@ -0,0 +1,15 @@ +fn test_missing_unsafe_warning_on_repr_packed() { + struct Foo { + x: String, + } + + let foo = Foo { x: String::new() }; + + let c = || { + let (_, t2) = foo.x; //~ ERROR mismatched types + }; + + c(); +} + +fn main() {} diff --git a/tests/ui/typeck/issue-121410.stderr b/tests/ui/typeck/issue-121410.stderr new file mode 100644 index 0000000000000..430350ac2a2a9 --- /dev/null +++ b/tests/ui/typeck/issue-121410.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-121410.rs:9:13 + | +LL | let (_, t2) = foo.x; + | ^^^^^^^ ----- this expression has type `String` + | | + | expected `String`, found `(_, _)` + | + = note: expected struct `String` + found tuple `(_, _)` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`.