about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Hewson <michael@michaelhewson.ca>2018-09-20 02:56:10 -0400
committerMichael Hewson <michael@michaelhewson.ca>2018-11-01 18:15:19 -0400
commita920036f4fe6403396ea05e7c70d0d87c769ff0a (patch)
tree1c8f887bdf9823ce63d880187c53b935acaa2aaa /src
parentd14af130f60a8e35ea0bf441b33dd9eb6527f859 (diff)
downloadrust-a920036f4fe6403396ea05e7c70d0d87c769ff0a.tar.gz
rust-a920036f4fe6403396ea05e7c70d0d87c769ff0a.zip
move some code around to avoid query cycles
Diffstat (limited to 'src')
-rw-r--r--src/librustc/traits/select.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs
index 2ea16823cc6..0742f377f18 100644
--- a/src/librustc/traits/select.rs
+++ b/src/librustc/traits/select.rs
@@ -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
@@ -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;