Skip to content

Commit

Permalink
move some code around to avoid query cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeyhew committed Nov 1, 2018
1 parent d14af13 commit a920036
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/librustc/traits/select.rs
Expand Up @@ -2090,18 +2090,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
obligation.self_ty().skip_binder()
);

// Object-safety candidates are only applicable to object-safe
// traits. Including this check is useful because it helps
// inference in cases of traits like `BorrowFrom`, which are
// not object-safe, and which rely on being able to infer the
// self-type from one of the other inputs. Without this check,
// these cases wind up being considered ambiguous due to a
// (spurious) ambiguity introduced here.
let predicate_trait_ref = obligation.predicate.to_poly_trait_ref();
if !self.tcx().is_object_safe(predicate_trait_ref.def_id()) {
return;
}

self.probe(|this, _snapshot| {
// the code below doesn't care about regions, and the
// self-ty here doesn't escape this probe, so just erase
Expand All @@ -2123,6 +2111,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
data.principal().with_self_ty(this.tcx(), self_ty)
}
ty::Infer(ty::TyVar(_)) => {
// Object-safety candidates are only applicable to object-safe
// traits. Including this check is useful because it helps
// inference in cases of traits like `BorrowFrom`, which are
// not object-safe, and which rely on being able to infer the
// self-type from one of the other inputs. Without this check,
// these cases wind up being considered ambiguous due to a
// (spurious) ambiguity introduced here.
let predicate_trait_ref = obligation.predicate.to_poly_trait_ref();
if !this.tcx().is_object_safe(predicate_trait_ref.def_id()) {
return;
}
debug!("assemble_candidates_from_object_ty: ambiguous");
candidates.ambiguous = true; // could wind up being an object type
return;
Expand Down

0 comments on commit a920036

Please sign in to comment.