diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index d0358b03af197..7b2370cdbc74d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -876,7 +876,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } if let Ok(Some(ImplSource::UserDefined(impl_data))) = - SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref.skip_binder())) + self.enter_forall(trait_ref, |trait_ref_for_select| { + SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref_for_select)) + }) { let impl_did = impl_data.impl_def_id; let trait_did = trait_ref.def_id(); diff --git a/tests/ui/traits/next-solver/diagnostics/const-host-effect-hrtb-no-ice.rs b/tests/ui/traits/next-solver/diagnostics/const-host-effect-hrtb-no-ice.rs new file mode 100644 index 0000000000000..4185228a2586f --- /dev/null +++ b/tests/ui/traits/next-solver/diagnostics/const-host-effect-hrtb-no-ice.rs @@ -0,0 +1,12 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/151894 +//@ compile-flags: -Znext-solver=globally + +#![feature(const_trait_impl)] + +const fn with_positive [const] Fn(&'a ())>() {} + +const _: () = { + with_positive::<()>(); //~ ERROR expected a `Fn(&'a ())` closure, found `()` +}; + +fn main() {} diff --git a/tests/ui/traits/next-solver/diagnostics/const-host-effect-hrtb-no-ice.stderr b/tests/ui/traits/next-solver/diagnostics/const-host-effect-hrtb-no-ice.stderr new file mode 100644 index 0000000000000..18f513cea6d49 --- /dev/null +++ b/tests/ui/traits/next-solver/diagnostics/const-host-effect-hrtb-no-ice.stderr @@ -0,0 +1,16 @@ +error[E0277]: expected a `Fn(&'a ())` closure, found `()` + --> $DIR/const-host-effect-hrtb-no-ice.rs:9:21 + | +LL | with_positive::<()>(); + | ^^ expected an `Fn(&'a ())` closure, found `()` + | + = help: the trait `for<'a> Fn(&'a ())` is not implemented for `()` +note: required by a bound in `with_positive` + --> $DIR/const-host-effect-hrtb-no-ice.rs:6:27 + | +LL | const fn with_positive [const] Fn(&'a ())>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `with_positive` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`.