Skip to content

Commit

Permalink
Fix #13140: Early/Late Bound related ICEs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pnkfelix committed Mar 26, 2014
1 parent 0908ffa commit 6b5ca8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/librustc/middle/typeck/check/method.rs
Expand Up @@ -263,6 +263,7 @@ fn construct_transformed_self_ty_for_object(
let transformed_self_ty = *method_ty.fty.sig.inputs.get(0);
match ty::get(transformed_self_ty).sty {
ty::ty_rptr(r, mt) => { // must be SelfRegion
let r = r.subst(tcx, &substs); // handle Early-Bound lifetime
ty::mk_trait(tcx, trait_def_id, substs,
RegionTraitStore(r), mt.mutbl,
ty::EmptyBuiltinBounds())
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -329,6 +329,10 @@ fn check_bare_fn(ccx: &CrateCtxt,
id: ast::NodeId,
fty: ty::t,
param_env: ty::ParameterEnvironment) {
// Compute the fty from point of view of inside fn
// (replace any type-scheme with a type)
let fty = fty.subst(ccx.tcx, &param_env.free_substs);

match ty::get(fty).sty {
ty::ty_bare_fn(ref fn_ty) => {
let inh = Inherited::new(ccx.tcx, param_env);
Expand Down Expand Up @@ -678,9 +682,7 @@ fn check_method_body(ccx: &CrateCtxt,
method_generics.region_param_defs(),
method.body.id);

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

check_bare_fn(ccx, method.decl, method.body, method.id, fty, param_env);
}
Expand Down

0 comments on commit 6b5ca8b

Please sign in to comment.