@@ -1340,7 +1340,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
13401340 self . assemble_candidates_from_impls ( obligation, & mut candidates) ?;
13411341
13421342 // 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) ;
13441344 self . assemble_builtin_bound_candidates ( copy_conditions, & mut candidates) ?;
13451345 } else if lang_items. sized_trait ( ) == Some ( def_id) {
13461346 // Sized is never implementable by end-users, it is
@@ -1355,7 +1355,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
13551355 // Same builtin conditions as `Copy`, i.e. every type which has builtin support
13561356 // for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
13571357 // types have builtin support for `Clone`.
1358- let clone_conditions = self . copy_conditions ( obligation) ;
1358+ let clone_conditions = self . copy_clone_conditions ( obligation) ;
13591359 self . assemble_builtin_bound_candidates ( clone_conditions, & mut candidates) ?;
13601360 }
13611361
@@ -2050,7 +2050,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20502050 }
20512051 }
20522052
2053- fn copy_conditions ( & mut self , obligation : & TraitObligation < ' tcx > )
2053+ fn copy_clone_conditions ( & mut self , obligation : & TraitObligation < ' tcx > )
20542054 -> BuiltinImplConditions < ' tcx >
20552055 {
20562056 // NOTE: binder moved to (*)
@@ -2068,8 +2068,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20682068 Where ( ty:: Binder ( Vec :: new ( ) ) )
20692069 }
20702070
2071- ty:: TyDynamic ( ..) | ty:: TyStr | ty:: TySlice ( ..) |
2072- ty:: TyClosure ( ..) | ty:: TyGenerator ( ..) |
2071+ ty:: TyDynamic ( ..) | ty:: TyStr | ty:: TySlice ( ..) | ty:: TyGenerator ( ..) |
20732072 ty:: TyRef ( _, ty:: TypeAndMut { ty : _, mutbl : hir:: MutMutable } ) => {
20742073 Never
20752074 }
@@ -2084,6 +2083,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20842083 Where ( ty:: Binder ( tys. to_vec ( ) ) )
20852084 }
20862085
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+
20872102 ty:: TyAdt ( ..) | ty:: TyProjection ( ..) | ty:: TyParam ( ..) | ty:: TyAnon ( ..) => {
20882103 // Fallback to whatever user-defined impls exist in this case.
20892104 None
@@ -2370,10 +2385,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
23702385 self . sized_conditions ( obligation)
23712386 }
23722387 _ if Some ( trait_def) == lang_items. copy_trait ( ) => {
2373- self . copy_conditions ( obligation)
2388+ self . copy_clone_conditions ( obligation)
23742389 }
23752390 _ if Some ( trait_def) == lang_items. clone_trait ( ) => {
2376- self . copy_conditions ( obligation)
2391+ self . copy_clone_conditions ( obligation)
23772392 }
23782393 _ => bug ! ( "unexpected builtin trait {:?}" , trait_def)
23792394 } ;
0 commit comments