Skip to content

Commit 0b02f67

Browse files
committed
Handle leaked host-effect HRTBs before selection
1 parent f908263 commit 0b02f67

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
876876
}
877877

878878
if let Ok(Some(ImplSource::UserDefined(impl_data))) =
879-
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref.skip_binder()))
879+
self.enter_forall(trait_ref, |trait_ref_for_select| {
880+
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref_for_select))
881+
})
880882
{
881883
let impl_did = impl_data.impl_def_id;
882884
let trait_did = trait_ref.def_id();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/151894
2+
//@ compile-flags: -Znext-solver=globally
3+
4+
#![feature(const_trait_impl)]
5+
6+
const fn with_positive<F: for<'a> [const] Fn(&'a ())>() {}
7+
8+
const _: () = {
9+
with_positive::<()>(); //~ ERROR expected a `Fn(&'a ())` closure, found `()`
10+
};
11+
12+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: expected a `Fn(&'a ())` closure, found `()`
2+
--> $DIR/const-host-effect-hrtb-no-ice.rs:9:21
3+
|
4+
LL | with_positive::<()>();
5+
| ^^ expected an `Fn(&'a ())` closure, found `()`
6+
|
7+
= help: the trait `for<'a> Fn(&'a ())` is not implemented for `()`
8+
note: required by a bound in `with_positive`
9+
--> $DIR/const-host-effect-hrtb-no-ice.rs:6:27
10+
|
11+
LL | const fn with_positive<F: for<'a> [const] Fn(&'a ())>() {}
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `with_positive`
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)