diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index c3f6eaccfabca..df86233c2b055 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -191,7 +191,18 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { variant.fields.iter().map(move |field| { let ty = field.ty(self.tcx, args); // `field.ty()` doesn't normalize after instantiating. - let ty = self.tcx.normalize_erasing_regions(self.typing_env, ty); + let ty = + self.tcx.try_normalize_erasing_regions(self.typing_env, ty).unwrap_or_else(|e| { + self.tcx.dcx().span_delayed_bug( + self.scrut_span, + format!( + "Failed to normalize {:?} in typing_env={:?} while getting variant sub tys for {ty:?}", + e.get_type_for_failure(), + self.typing_env, + ), + ); + ty + }); let ty = self.reveal_opaque_ty(ty); (field, ty) }) diff --git a/tests/ui/pattern/missing-ctor-with-ill-formed-inner-ty-issue-148192.rs b/tests/ui/pattern/missing-ctor-with-ill-formed-inner-ty-issue-148192.rs new file mode 100644 index 0000000000000..4ad47352e0026 --- /dev/null +++ b/tests/ui/pattern/missing-ctor-with-ill-formed-inner-ty-issue-148192.rs @@ -0,0 +1,20 @@ +trait WhereTrait { + type Type; +} + +fn foo(e: Enum) { + if let Enum::Map(_) = e {} + + match e { + //~^ ERROR: non-exhaustive patterns: `Enum::Map2(_)` not covered + Enum::Map(_) => (), + } +} + +enum Enum { + Map(()), + Map2(<() as WhereTrait>::Type), + //~^ ERROR: the trait bound `(): WhereTrait` is not satisfied +} + +fn main() {} diff --git a/tests/ui/pattern/missing-ctor-with-ill-formed-inner-ty-issue-148192.stderr b/tests/ui/pattern/missing-ctor-with-ill-formed-inner-ty-issue-148192.stderr new file mode 100644 index 0000000000000..4e1bd3689e3de --- /dev/null +++ b/tests/ui/pattern/missing-ctor-with-ill-formed-inner-ty-issue-148192.stderr @@ -0,0 +1,37 @@ +error[E0277]: the trait bound `(): WhereTrait` is not satisfied + --> $DIR/missing-ctor-with-ill-formed-inner-ty-issue-148192.rs:16:10 + | +LL | Map2(<() as WhereTrait>::Type), + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `WhereTrait` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/missing-ctor-with-ill-formed-inner-ty-issue-148192.rs:1:1 + | +LL | trait WhereTrait { + | ^^^^^^^^^^^^^^^^ + +error[E0004]: non-exhaustive patterns: `Enum::Map2(_)` not covered + --> $DIR/missing-ctor-with-ill-formed-inner-ty-issue-148192.rs:8:11 + | +LL | match e { + | ^ pattern `Enum::Map2(_)` not covered + | +note: `Enum` defined here + --> $DIR/missing-ctor-with-ill-formed-inner-ty-issue-148192.rs:14:6 + | +LL | enum Enum { + | ^^^^ +LL | Map(()), +LL | Map2(<() as WhereTrait>::Type), + | ---- not covered + = note: the matched value is of type `Enum` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Enum::Map(_) => (), +LL ~ Enum::Map2(_) => todo!(), + | + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0004, E0277. +For more information about an error, try `rustc --explain E0004`.