Skip to content

Commit

Permalink
Fix issue rust-lang#24085
Browse files Browse the repository at this point in the history
Insert an inference variable before performing trait selection for
builtin traits.  This prevents overly-restrictive region constraints
that lead to later inference failures.
  • Loading branch information
bkoropoff committed Apr 14, 2015
1 parent f55e66a commit 10a15ad
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/librustc/middle/traits/mod.rs
Expand Up @@ -322,7 +322,17 @@ pub fn evaluate_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
// anyhow).
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);

fulfill_cx.register_builtin_bound(infcx, ty, bound, cause);
// Relax region constraints that result from trait selection by
// inserting an inference variable. This mimics the behavior
// of method confirmation where fresh inference variables are
// substituted into the method self type, which is then unified
// with the adjusted receiver type and handed to trait selection.
let relax_ty = infcx.next_ty_var();
try!(infcx.sub_types(false, infer::Misc(span), ty, relax_ty).map_err(|_| Unimplemented));
let relax_ty = infcx.resolve_type_vars_if_possible(&relax_ty);
debug!("relax_ty: {}", relax_ty.repr(infcx.tcx));

fulfill_cx.register_builtin_bound(infcx, relax_ty, bound, cause);

// Note: we only assume something is `Copy` if we can
// *definitively* show that it implements `Copy`. Otherwise,
Expand Down

0 comments on commit 10a15ad

Please sign in to comment.