Skip to content

Commit 657499d

Browse files
committed
Reorder erasing/replacing late bound vars and substs
1 parent e14eae6 commit 657499d

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

compiler/rustc_typeck/src/check/method/confirm.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
462462

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

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

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

477-
(method_sig, method_predicates)
471+
(sig, method_predicates)
478472
}
479473

480474
fn add_obligations(

compiler/rustc_typeck/src/check/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
461461
// `instantiate_type_scheme` can normalize associated types that
462462
// may reference those regions.
463463
let fn_sig = tcx.fn_sig(def_id);
464-
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;
465464
let fn_sig = fn_sig.subst(self.tcx, substs);
465+
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;
466466

467467
let InferOk { value, obligations: o } = if is_op {
468468
self.normalize_op_associated_types_in_as_infer_ok(span, fn_sig, opt_input_expr)

compiler/rustc_typeck/src/check/method/probe.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1784,12 +1784,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17841784
let generics = self.tcx.generics_of(method);
17851785
assert_eq!(substs.len(), generics.parent_count as usize);
17861786

1787-
// Erase any late-bound regions from the method and substitute
1788-
// in the values from the substitution.
1789-
let xform_fn_sig = self.erase_late_bound_regions(fn_sig);
1790-
1791-
if generics.params.is_empty() {
1792-
xform_fn_sig.subst(self.tcx, substs)
1787+
let xform_fn_sig = if generics.params.is_empty() {
1788+
fn_sig.subst(self.tcx, substs)
17931789
} else {
17941790
let substs = InternalSubsts::for_item(self.tcx, method, |param, _| {
17951791
let i = param.index as usize;
@@ -1807,8 +1803,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18071803
}
18081804
}
18091805
});
1810-
xform_fn_sig.subst(self.tcx, substs)
1811-
}
1806+
fn_sig.subst(self.tcx, substs)
1807+
};
1808+
1809+
self.erase_late_bound_regions(xform_fn_sig)
18121810
}
18131811

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

0 commit comments

Comments
 (0)