Skip to content

Commit a920036

Browse files
committed
move some code around to avoid query cycles
1 parent d14af13 commit a920036

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/librustc/traits/select.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,18 +2090,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20902090
obligation.self_ty().skip_binder()
20912091
);
20922092

2093-
// Object-safety candidates are only applicable to object-safe
2094-
// traits. Including this check is useful because it helps
2095-
// inference in cases of traits like `BorrowFrom`, which are
2096-
// not object-safe, and which rely on being able to infer the
2097-
// self-type from one of the other inputs. Without this check,
2098-
// these cases wind up being considered ambiguous due to a
2099-
// (spurious) ambiguity introduced here.
2100-
let predicate_trait_ref = obligation.predicate.to_poly_trait_ref();
2101-
if !self.tcx().is_object_safe(predicate_trait_ref.def_id()) {
2102-
return;
2103-
}
2104-
21052093
self.probe(|this, _snapshot| {
21062094
// the code below doesn't care about regions, and the
21072095
// self-ty here doesn't escape this probe, so just erase
@@ -2123,6 +2111,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21232111
data.principal().with_self_ty(this.tcx(), self_ty)
21242112
}
21252113
ty::Infer(ty::TyVar(_)) => {
2114+
// Object-safety candidates are only applicable to object-safe
2115+
// traits. Including this check is useful because it helps
2116+
// inference in cases of traits like `BorrowFrom`, which are
2117+
// not object-safe, and which rely on being able to infer the
2118+
// self-type from one of the other inputs. Without this check,
2119+
// these cases wind up being considered ambiguous due to a
2120+
// (spurious) ambiguity introduced here.
2121+
let predicate_trait_ref = obligation.predicate.to_poly_trait_ref();
2122+
if !this.tcx().is_object_safe(predicate_trait_ref.def_id()) {
2123+
return;
2124+
}
21262125
debug!("assemble_candidates_from_object_ty: ambiguous");
21272126
candidates.ambiguous = true; // could wind up being an object type
21282127
return;

0 commit comments

Comments
 (0)