Skip to content

Commit 6b5ca8b

Browse files
committed
Fix #13140: Early/Late Bound related ICEs.
The problem was that we need to apply the substitution, so that the formal lifetime parameters get replaced with (unifiable) free-lifetimes that can actually be fed into the constraint solver. Also, refactor code os that substitution for `check_item` and `check_method`, moving both down the control flow into `check_bare_fn`. ---- Finally, there was another (similar) spot where we needed to substitute early-bound lifetimes when invoking an object method of a trait.
1 parent 0908ffa commit 6b5ca8b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/librustc/middle/typeck/check/method.rs

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ fn construct_transformed_self_ty_for_object(
263263
let transformed_self_ty = *method_ty.fty.sig.inputs.get(0);
264264
match ty::get(transformed_self_ty).sty {
265265
ty::ty_rptr(r, mt) => { // must be SelfRegion
266+
let r = r.subst(tcx, &substs); // handle Early-Bound lifetime
266267
ty::mk_trait(tcx, trait_def_id, substs,
267268
RegionTraitStore(r), mt.mutbl,
268269
ty::EmptyBuiltinBounds())

src/librustc/middle/typeck/check/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ fn check_bare_fn(ccx: &CrateCtxt,
329329
id: ast::NodeId,
330330
fty: ty::t,
331331
param_env: ty::ParameterEnvironment) {
332+
// Compute the fty from point of view of inside fn
333+
// (replace any type-scheme with a type)
334+
let fty = fty.subst(ccx.tcx, &param_env.free_substs);
335+
332336
match ty::get(fty).sty {
333337
ty::ty_bare_fn(ref fn_ty) => {
334338
let inh = Inherited::new(ccx.tcx, param_env);
@@ -678,9 +682,7 @@ fn check_method_body(ccx: &CrateCtxt,
678682
method_generics.region_param_defs(),
679683
method.body.id);
680684

681-
// Compute the fty from point of view of inside fn
682685
let fty = ty::node_id_to_type(ccx.tcx, method.id);
683-
let fty = fty.subst(ccx.tcx, &param_env.free_substs);
684686

685687
check_bare_fn(ccx, method.decl, method.body, method.id, fty, param_env);
686688
}

0 commit comments

Comments
 (0)