@@ -1340,7 +1340,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1340
1340
self . assemble_candidates_from_impls ( obligation, & mut candidates) ?;
1341
1341
1342
1342
// For other types, we'll use the builtin rules.
1343
- let copy_conditions = self . copy_conditions ( obligation) ;
1343
+ let copy_conditions = self . copy_clone_conditions ( obligation) ;
1344
1344
self . assemble_builtin_bound_candidates ( copy_conditions, & mut candidates) ?;
1345
1345
} else if lang_items. sized_trait ( ) == Some ( def_id) {
1346
1346
// Sized is never implementable by end-users, it is
@@ -1355,7 +1355,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1355
1355
// Same builtin conditions as `Copy`, i.e. every type which has builtin support
1356
1356
// for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
1357
1357
// types have builtin support for `Clone`.
1358
- let clone_conditions = self . copy_conditions ( obligation) ;
1358
+ let clone_conditions = self . copy_clone_conditions ( obligation) ;
1359
1359
self . assemble_builtin_bound_candidates ( clone_conditions, & mut candidates) ?;
1360
1360
}
1361
1361
@@ -2050,7 +2050,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2050
2050
}
2051
2051
}
2052
2052
2053
- fn copy_conditions ( & mut self , obligation : & TraitObligation < ' tcx > )
2053
+ fn copy_clone_conditions ( & mut self , obligation : & TraitObligation < ' tcx > )
2054
2054
-> BuiltinImplConditions < ' tcx >
2055
2055
{
2056
2056
// NOTE: binder moved to (*)
@@ -2068,8 +2068,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2068
2068
Where ( ty:: Binder ( Vec :: new ( ) ) )
2069
2069
}
2070
2070
2071
- ty:: TyDynamic ( ..) | ty:: TyStr | ty:: TySlice ( ..) |
2072
- ty:: TyClosure ( ..) | ty:: TyGenerator ( ..) |
2071
+ ty:: TyDynamic ( ..) | ty:: TyStr | ty:: TySlice ( ..) | ty:: TyGenerator ( ..) |
2073
2072
ty:: TyRef ( _, ty:: TypeAndMut { ty : _, mutbl : hir:: MutMutable } ) => {
2074
2073
Never
2075
2074
}
@@ -2084,6 +2083,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2084
2083
Where ( ty:: Binder ( tys. to_vec ( ) ) )
2085
2084
}
2086
2085
2086
+ ty:: TyClosure ( def_id, substs) => {
2087
+ let trait_id = obligation. predicate . def_id ( ) ;
2088
+ let copy_closures =
2089
+ Some ( trait_id) == self . tcx ( ) . lang_items ( ) . copy_trait ( ) &&
2090
+ self . tcx ( ) . has_copy_closures ( def_id. krate ) ;
2091
+ let clone_closures =
2092
+ Some ( trait_id) == self . tcx ( ) . lang_items ( ) . clone_trait ( ) &&
2093
+ self . tcx ( ) . has_clone_closures ( def_id. krate ) ;
2094
+
2095
+ if copy_closures || clone_closures {
2096
+ Where ( ty:: Binder ( substs. upvar_tys ( def_id, self . tcx ( ) ) . collect ( ) ) )
2097
+ } else {
2098
+ Never
2099
+ }
2100
+ }
2101
+
2087
2102
ty:: TyAdt ( ..) | ty:: TyProjection ( ..) | ty:: TyParam ( ..) | ty:: TyAnon ( ..) => {
2088
2103
// Fallback to whatever user-defined impls exist in this case.
2089
2104
None
@@ -2370,10 +2385,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2370
2385
self . sized_conditions ( obligation)
2371
2386
}
2372
2387
_ if Some ( trait_def) == lang_items. copy_trait ( ) => {
2373
- self . copy_conditions ( obligation)
2388
+ self . copy_clone_conditions ( obligation)
2374
2389
}
2375
2390
_ if Some ( trait_def) == lang_items. clone_trait ( ) => {
2376
- self . copy_conditions ( obligation)
2391
+ self . copy_clone_conditions ( obligation)
2377
2392
}
2378
2393
_ => bug ! ( "unexpected builtin trait {:?}" , trait_def)
2379
2394
} ;
0 commit comments