@@ -1364,6 +1364,7 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1364
1364
let node = tcx. hir . get ( node_id) ;
1365
1365
1366
1366
let mut is_trait = None ;
1367
+ let mut is_default_impl_trait = None ;
1367
1368
1368
1369
let icx = ItemCtxt :: new ( tcx, def_id) ;
1369
1370
let no_generics = hir:: Generics :: empty ( ) ;
@@ -1373,8 +1374,13 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1373
1374
1374
1375
NodeItem ( item) => {
1375
1376
match item. node {
1377
+ ItemImpl ( _, _, defaultness, ref generics, ..) => {
1378
+ if defaultness. is_default ( ) {
1379
+ is_default_impl_trait = tcx. impl_trait_ref ( def_id) ;
1380
+ }
1381
+ generics
1382
+ }
1376
1383
ItemFn ( .., ref generics, _) |
1377
- ItemImpl ( _, _, _, ref generics, ..) |
1378
1384
ItemTy ( _, ref generics) |
1379
1385
ItemEnum ( _, ref generics) |
1380
1386
ItemStruct ( _, ref generics) |
@@ -1446,6 +1452,18 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1446
1452
predicates. push ( trait_ref. to_poly_trait_ref ( ) . to_predicate ( ) ) ;
1447
1453
}
1448
1454
1455
+ // In default impls, we can assume that the self type implements
1456
+ // the trait. So in:
1457
+ //
1458
+ // default impl Foo for Bar { .. }
1459
+ //
1460
+ // we add a default where clause `Foo: Bar`. We do a similar thing for traits
1461
+ // (see below). Recall that a default impl is not itself an impl, but rather a
1462
+ // set of defaults that can be incorporated into another impl.
1463
+ if let Some ( trait_ref) = is_default_impl_trait {
1464
+ predicates. push ( trait_ref. to_poly_trait_ref ( ) . to_predicate ( ) ) ;
1465
+ }
1466
+
1449
1467
// Collect the region predicates that were declared inline as
1450
1468
// well. In the case of parameters declared on a fn or method, we
1451
1469
// have to be careful to only iterate over early-bound regions.
0 commit comments