@@ -1852,18 +1852,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1852
1852
debug ! ( "assemble_candidates_from_object_ty(self_ty={:?})" ,
1853
1853
obligation. self_ty( ) . skip_binder( ) ) ;
1854
1854
1855
- // Object-safety candidates are only applicable to object-safe
1856
- // traits. Including this check is useful because it helps
1857
- // inference in cases of traits like `BorrowFrom`, which are
1858
- // not object-safe, and which rely on being able to infer the
1859
- // self-type from one of the other inputs. Without this check,
1860
- // these cases wind up being considered ambiguous due to a
1861
- // (spurious) ambiguity introduced here.
1862
- let predicate_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
1863
- if !self . tcx ( ) . is_object_safe ( predicate_trait_ref. def_id ( ) ) {
1864
- return ;
1865
- }
1866
-
1867
1855
self . probe ( |this, _snapshot| {
1868
1856
// the code below doesn't care about regions, and the
1869
1857
// self-ty here doesn't escape this probe, so just erase
@@ -1884,6 +1872,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1884
1872
}
1885
1873
}
1886
1874
ty:: TyInfer ( ty:: TyVar ( _) ) => {
1875
+ // Object-safety candidates are only applicable to object-safe
1876
+ // traits. Including this check is useful because it helps
1877
+ // inference in cases of traits like `BorrowFrom`, which are
1878
+ // not object-safe, and which rely on being able to infer the
1879
+ // self-type from one of the other inputs. Without this check,
1880
+ // these cases wind up being considered ambiguous due to a
1881
+ // (spurious) ambiguity introduced here.
1882
+ let predicate_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
1883
+ if !this. tcx ( ) . is_object_safe ( predicate_trait_ref. def_id ( ) ) {
1884
+ return ;
1885
+ }
1887
1886
debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
1888
1887
candidates. ambiguous = true ; // could wind up being an object type
1889
1888
return ;
0 commit comments