@@ -1296,6 +1296,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1296
1296
} else if self . tcx ( ) . lang_items . unsize_trait ( ) == Some ( def_id) {
1297
1297
self . assemble_candidates_for_unsizing ( obligation, & mut candidates) ;
1298
1298
} else {
1299
+ if self . tcx ( ) . lang_items . clone_trait ( ) == Some ( def_id) {
1300
+ // Same builtin conditions as `Copy`, i.e. every type which has builtin support
1301
+ // for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
1302
+ // types have builtin support for `Clone`.
1303
+ let clone_conditions = self . copy_conditions ( obligation) ;
1304
+ self . assemble_builtin_bound_candidates ( clone_conditions, & mut candidates) ?;
1305
+ }
1306
+
1299
1307
self . assemble_closure_candidates ( obligation, & mut candidates) ?;
1300
1308
self . assemble_fn_pointer_candidates ( obligation, & mut candidates) ?;
1301
1309
self . assemble_candidates_from_impls ( obligation, & mut candidates) ?;
@@ -2164,8 +2172,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2164
2172
2165
2173
match candidate {
2166
2174
BuiltinCandidate { has_nested } => {
2167
- Ok ( VtableBuiltin (
2168
- self . confirm_builtin_candidate ( obligation , has_nested ) ) )
2175
+ let data = self . confirm_builtin_candidate ( obligation , has_nested ) ;
2176
+ Ok ( VtableBuiltin ( data ) )
2169
2177
}
2170
2178
2171
2179
ParamCandidate ( param) => {
@@ -2257,7 +2265,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2257
2265
fn confirm_builtin_candidate ( & mut self ,
2258
2266
obligation : & TraitObligation < ' tcx > ,
2259
2267
has_nested : bool )
2260
- -> VtableBuiltinData < PredicateObligation < ' tcx > >
2268
+ -> VtableBuiltinData < ' tcx , PredicateObligation < ' tcx > >
2261
2269
{
2262
2270
debug ! ( "confirm_builtin_candidate({:?}, {:?})" ,
2263
2271
obligation, has_nested) ;
@@ -2271,6 +2279,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2271
2279
_ if Some ( trait_def) == self . tcx ( ) . lang_items . copy_trait ( ) => {
2272
2280
self . copy_conditions ( obligation)
2273
2281
}
2282
+ _ if Some ( trait_def) == self . tcx ( ) . lang_items . clone_trait ( ) => {
2283
+ self . copy_conditions ( obligation)
2284
+ }
2274
2285
_ => bug ! ( "unexpected builtin trait {:?}" , trait_def)
2275
2286
} ;
2276
2287
let nested = match conditions {
@@ -2291,7 +2302,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2291
2302
2292
2303
debug ! ( "confirm_builtin_candidate: obligations={:?}" ,
2293
2304
obligations) ;
2294
- VtableBuiltinData { nested : obligations }
2305
+
2306
+ let self_ty = self . infcx . shallow_resolve ( obligation. predicate . skip_binder ( ) . self_ty ( ) ) ;
2307
+ VtableBuiltinData { ty : self_ty, nested : obligations }
2295
2308
}
2296
2309
2297
2310
/// This handles the case where a `impl Foo for ..` impl is being used.
@@ -2598,8 +2611,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2598
2611
2599
2612
fn confirm_builtin_unsize_candidate ( & mut self ,
2600
2613
obligation : & TraitObligation < ' tcx > , )
2601
- -> Result < VtableBuiltinData < PredicateObligation < ' tcx > > ,
2602
- SelectionError < ' tcx > > {
2614
+ -> Result < VtableBuiltinData < ' tcx , PredicateObligation < ' tcx > > , SelectionError < ' tcx > >
2615
+ {
2603
2616
let tcx = self . tcx ( ) ;
2604
2617
2605
2618
// assemble_candidates_for_unsizing should ensure there are no late bound
@@ -2801,7 +2814,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2801
2814
_ => bug ! ( )
2802
2815
} ;
2803
2816
2804
- Ok ( VtableBuiltinData { nested : nested } )
2817
+ Ok ( VtableBuiltinData { ty : source , nested : nested } )
2805
2818
}
2806
2819
2807
2820
///////////////////////////////////////////////////////////////////////////
0 commit comments