Skip to content

Commit

Permalink
Get rid of infer vars in inherent assoc types selection by using probe
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Nov 25, 2023
1 parent 4b26bb5 commit 6312382
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
27 changes: 15 additions & 12 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,19 +1620,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty,
|self_ty| {
let tcx = self.tcx();
let InferOk { value: self_ty, obligations } =
infcx.at(&cause, param_env).normalize(self_ty);

let (impl_, (assoc_item, def_scope)) = self.select_inherent_assoc_type_candidates(
infcx,
name,
span,
self_ty,
cause,
param_env,
obligations,
candidates,
)?;
let (impl_, (assoc_item, def_scope)) = infcx.probe(|_| {
let InferOk { value: self_ty, obligations } =
infcx.at(&cause, param_env).normalize(self_ty);

self.select_inherent_assoc_type_candidates(
infcx,
name,
span,
self_ty,
cause,
param_env,
obligations,
candidates,
)
})?;

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

Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,12 @@ pub fn compute_inherent_assoc_ty_args<'a, 'b, 'tcx>(
// Infer the generic parameters of the impl by unifying the
// impl type with the self type of the projection.
let self_ty = alias_ty.self_ty();
match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, impl_ty, self_ty) {
let infcx = selcx.infcx.at(&cause, param_env);
let InferOk { value: self_ty, obligations: mut normalize_obligations } =
infcx.normalize(self_ty);
obligations.append(&mut normalize_obligations);

match infcx.eq(DefineOpaqueTypes::No, impl_ty, self_ty) {
Ok(mut ok) => obligations.append(&mut ok.obligations),
Err(_) => {
tcx.sess.delay_span_bug(
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/associated-inherent-types/assoc-inherent-late-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// check-pass

#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

struct Foo<T>(T);

impl<'a> Foo<fn(&'a ())> {
type Assoc = &'a ();
}

fn bar(_: for<'a> fn(Foo<fn(Foo<fn(&'static ())>::Assoc)>::Assoc)) {}

fn main() {}

0 comments on commit 6312382

Please sign in to comment.