diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index ede6cd607b7fe..528b98cf4a1c0 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -508,7 +508,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(def_id, substs) => { + ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.super_fold_with(self), diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index f5c98558a2525..a875ea1578dcb 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -198,7 +198,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(def_id, substs) => { + ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.try_super_fold_with(self), diff --git a/src/test/ui/impl-trait/normalize-tait-in-const.rs b/src/test/ui/impl-trait/normalize-tait-in-const.rs new file mode 100644 index 0000000000000..020bcbb8396c9 --- /dev/null +++ b/src/test/ui/impl-trait/normalize-tait-in-const.rs @@ -0,0 +1,39 @@ +// known-bug: #103507 +// failure-status: 101 +// normalize-stderr-test "note: .*\n\n" -> "" +// normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" +// rustc-env:RUST_BACKTRACE=0 + +#![feature(type_alias_impl_trait)] +#![feature(const_trait_impl)] +#![feature(const_refs_to_cell)] +#![feature(inline_const)] + +use std::marker::Destruct; + +trait T { + type Item; +} + +type Alias<'a> = impl T; + +struct S; +impl<'a> T for &'a S { + type Item = &'a (); +} + +const fn filter_positive<'a>() -> &'a Alias<'a> { + &&S +} + +const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { + fun(filter_positive()); +} + +const fn foo(_: &Alias<'_>) {} + +const BAR: () = { + with_positive(foo); +}; + +fn main() {} diff --git a/src/test/ui/impl-trait/normalize-tait-in-const.stderr b/src/test/ui/impl-trait/normalize-tait-in-const.stderr new file mode 100644 index 0000000000000..b9fc8726ffc0b --- /dev/null +++ b/src/test/ui/impl-trait/normalize-tait-in-const.stderr @@ -0,0 +1,8 @@ +error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:198:90: Failed to normalize fn(&'a Alias<'b>) {foo} as std::ops::FnOnce<(&&S,)>>::Output, maybe try to call `try_normalize_erasing_regions` instead + +query stack during panic: +#0 [eval_to_allocation_raw] const-evaluating + checking `BAR` +#1 [eval_to_const_value_raw] simplifying constant for the type system `BAR` +end of query stack +error: aborting due to previous error + diff --git a/src/tools/miri/tests/pass/issues/issue-miri-2433.rs b/src/tools/miri/tests/pass/issues/issue-miri-2433.rs deleted file mode 100644 index a8281d30bac4a..0000000000000 --- a/src/tools/miri/tests/pass/issues/issue-miri-2433.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![feature(type_alias_impl_trait)] - -trait T { - type Item; -} - -type Alias<'a> = impl T; - -struct S; -impl<'a> T for &'a S { - type Item = &'a (); -} - -fn filter_positive<'a>() -> Alias<'a> { - &S -} - -fn with_positive(fun: impl Fn(Alias<'_>)) { - fun(filter_positive()); -} - -fn main() { - with_positive(|_| ()); -}