@@ -2090,18 +2090,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2090
2090
obligation. self_ty( ) . skip_binder( )
2091
2091
) ;
2092
2092
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
-
2105
2093
self . probe ( |this, _snapshot| {
2106
2094
// the code below doesn't care about regions, and the
2107
2095
// self-ty here doesn't escape this probe, so just erase
@@ -2123,6 +2111,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2123
2111
data. principal ( ) . with_self_ty ( this. tcx ( ) , self_ty)
2124
2112
}
2125
2113
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
+ }
2126
2125
debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
2127
2126
candidates. ambiguous = true ; // could wind up being an object type
2128
2127
return ;
0 commit comments