@@ -1852,18 +1852,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18521852 debug ! ( "assemble_candidates_from_object_ty(self_ty={:?})" ,
18531853 obligation. self_ty( ) . skip_binder( ) ) ;
18541854
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-
18671855 self . probe ( |this, _snapshot| {
18681856 // the code below doesn't care about regions, and the
18691857 // self-ty here doesn't escape this probe, so just erase
@@ -1884,6 +1872,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18841872 }
18851873 }
18861874 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+ }
18871886 debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
18881887 candidates. ambiguous = true ; // could wind up being an object type
18891888 return ;
0 commit comments