From f3ecd64c617585e79956a3bba265e22ff1cad1e4 Mon Sep 17 00:00:00 2001 From: b-naber Date: Mon, 13 Dec 2021 22:24:08 +0100 Subject: [PATCH] use try_normalize_erasing_regions in RevealAllVisitor --- .../rustc_mir_transform/src/reveal_all.rs | 5 ++++- src/test/ui/mir/issue-91745.rs | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/mir/issue-91745.rs diff --git a/compiler/rustc_mir_transform/src/reveal_all.rs b/compiler/rustc_mir_transform/src/reveal_all.rs index a717dd3e0cd8a..ee661793a44aa 100644 --- a/compiler/rustc_mir_transform/src/reveal_all.rs +++ b/compiler/rustc_mir_transform/src/reveal_all.rs @@ -36,6 +36,9 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> { #[inline] fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) { - *ty = self.tcx.normalize_erasing_regions(self.param_env, ty); + // We have to use `try_normalize_erasing_regions` here, since it's + // possible that we visit impossible-to-satisfy where clauses here, + // see #91745 + *ty = self.tcx.try_normalize_erasing_regions(self.param_env, *ty).unwrap_or(ty); } } diff --git a/src/test/ui/mir/issue-91745.rs b/src/test/ui/mir/issue-91745.rs new file mode 100644 index 0000000000000..ca3d66b1c8eb7 --- /dev/null +++ b/src/test/ui/mir/issue-91745.rs @@ -0,0 +1,21 @@ +// check-pass + +pub trait Foo { + type Bar; +} + +pub trait Broken { + type Assoc; + fn broken(&self) where Self::Assoc: Foo; +} + +impl Broken for T { + type Assoc = (); + fn broken(&self) where Self::Assoc: Foo { + let _x: ::Bar; + } +} + +fn main() { + let _m: &dyn Broken = &(); +}