Skip to content

Commit f922105

Browse files
authored
Unrolled build for #154804
Rollup merge of #154804 - cijiugechu:fix/host-effect-hrtb-ice, r=adwinwhite Fix ICE when reporting host-effect errors for const Fn HRTBs in next trait solver Avoid leaking bound vars into the diagnostic selection path for HRTB host-effect predicates. Closes #151894 .
2 parents 532f8f1 + 0b02f67 commit f922105

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
@@ -874,7 +874,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
874874
}
875875

876876
if let Ok(Some(ImplSource::UserDefined(impl_data))) =
877-
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref.skip_binder()))
877+
self.enter_forall(trait_ref, |trait_ref_for_select| {
878+
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref_for_select))
879+
})
878880
{
879881
let impl_did = impl_data.impl_def_id;
880882
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)