Skip to content

Commit

Permalink
Reorder erasing/replacing late bound vars and substs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed May 9, 2022
1 parent e14eae6 commit 657499d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
16 changes: 5 additions & 11 deletions compiler/rustc_typeck/src/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {

let sig = self.tcx.fn_sig(def_id);

// Instantiate late-bound regions and substitute the trait
// parameters into the method type to get the actual method type.
//
// N.B., instantiate late-bound regions first so that
// `instantiate_type_scheme` can normalize associated types that
// may reference those regions.
let method_sig = self.replace_bound_vars_with_fresh_vars(sig);
debug!("late-bound lifetimes from method instantiated, method_sig={:?}", method_sig);
let sig = sig.subst(self.tcx, all_substs);
debug!("type scheme substituted, sig={:?}", sig);

let method_sig = method_sig.subst(self.tcx, all_substs);
debug!("type scheme substituted, method_sig={:?}", method_sig);
let sig = self.replace_bound_vars_with_fresh_vars(sig);
debug!("late-bound lifetimes from method instantiated, sig={:?}", sig);

(method_sig, method_predicates)
(sig, method_predicates)
}

fn add_obligations(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// `instantiate_type_scheme` can normalize associated types that
// may reference those regions.
let fn_sig = tcx.fn_sig(def_id);
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;
let fn_sig = fn_sig.subst(self.tcx, substs);
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;

let InferOk { value, obligations: o } = if is_op {
self.normalize_op_associated_types_in_as_infer_ok(span, fn_sig, opt_input_expr)
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1784,12 +1784,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let generics = self.tcx.generics_of(method);
assert_eq!(substs.len(), generics.parent_count as usize);

// Erase any late-bound regions from the method and substitute
// in the values from the substitution.
let xform_fn_sig = self.erase_late_bound_regions(fn_sig);

if generics.params.is_empty() {
xform_fn_sig.subst(self.tcx, substs)
let xform_fn_sig = if generics.params.is_empty() {
fn_sig.subst(self.tcx, substs)
} else {
let substs = InternalSubsts::for_item(self.tcx, method, |param, _| {
let i = param.index as usize;
Expand All @@ -1807,8 +1803,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}
});
xform_fn_sig.subst(self.tcx, substs)
}
fn_sig.subst(self.tcx, substs)
};

self.erase_late_bound_regions(xform_fn_sig)
}

/// Gets the type of an impl and generate substitutions with placeholders.
Expand Down

0 comments on commit 657499d

Please sign in to comment.