Skip to content

Commit 6312382

Browse files
committed
Get rid of infer vars in inherent assoc types selection by using probe
1 parent 4b26bb5 commit 6312382

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1620,19 +1620,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16201620
self_ty,
16211621
|self_ty| {
16221622
let tcx = self.tcx();
1623-
let InferOk { value: self_ty, obligations } =
1624-
infcx.at(&cause, param_env).normalize(self_ty);
16251623

1626-
let (impl_, (assoc_item, def_scope)) = self.select_inherent_assoc_type_candidates(
1627-
infcx,
1628-
name,
1629-
span,
1630-
self_ty,
1631-
cause,
1632-
param_env,
1633-
obligations,
1634-
candidates,
1635-
)?;
1624+
let (impl_, (assoc_item, def_scope)) = infcx.probe(|_| {
1625+
let InferOk { value: self_ty, obligations } =
1626+
infcx.at(&cause, param_env).normalize(self_ty);
1627+
1628+
self.select_inherent_assoc_type_candidates(
1629+
infcx,
1630+
name,
1631+
span,
1632+
self_ty,
1633+
cause,
1634+
param_env,
1635+
obligations,
1636+
candidates,
1637+
)
1638+
})?;
16361639

16371640
self.check_assoc_ty(assoc_item, name, def_scope, block, span);
16381641

compiler/rustc_trait_selection/src/traits/project.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,12 @@ pub fn compute_inherent_assoc_ty_args<'a, 'b, 'tcx>(
14551455
// Infer the generic parameters of the impl by unifying the
14561456
// impl type with the self type of the projection.
14571457
let self_ty = alias_ty.self_ty();
1458-
match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, impl_ty, self_ty) {
1458+
let infcx = selcx.infcx.at(&cause, param_env);
1459+
let InferOk { value: self_ty, obligations: mut normalize_obligations } =
1460+
infcx.normalize(self_ty);
1461+
obligations.append(&mut normalize_obligations);
1462+
1463+
match infcx.eq(DefineOpaqueTypes::No, impl_ty, self_ty) {
14591464
Ok(mut ok) => obligations.append(&mut ok.obligations),
14601465
Err(_) => {
14611466
tcx.sess.delay_span_bug(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// check-pass
2+
3+
#![feature(inherent_associated_types)]
4+
#![allow(incomplete_features)]
5+
6+
struct Foo<T>(T);
7+
8+
impl<'a> Foo<fn(&'a ())> {
9+
type Assoc = &'a ();
10+
}
11+
12+
fn bar(_: for<'a> fn(Foo<fn(Foo<fn(&'static ())>::Assoc)>::Assoc)) {}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)