@@ -165,12 +165,42 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
165
165
166
166
ItemKind :: Trait ( _, _, _, _, self_bounds, ..)
167
167
| ItemKind :: TraitAlias ( _, _, self_bounds) => {
168
- is_trait = Some ( self_bounds) ;
168
+ is_trait = Some ( ( self_bounds, item . span ) ) ;
169
169
}
170
170
_ => { }
171
171
}
172
172
} ;
173
173
174
+ if let Node :: TraitItem ( item) = node {
175
+ let parent = tcx. local_parent ( item. hir_id ( ) . owner . def_id ) ;
176
+ let Node :: Item ( parent_trait) = tcx. hir_node_by_def_id ( parent) else {
177
+ unreachable ! ( ) ;
178
+ } ;
179
+
180
+ let ( trait_generics, trait_bounds) = match parent_trait. kind {
181
+ hir:: ItemKind :: Trait ( _, _, _, generics, supertraits, _) => ( generics, supertraits) ,
182
+ hir:: ItemKind :: TraitAlias ( _, generics, supertraits) => ( generics, supertraits) ,
183
+ _ => unreachable ! ( ) ,
184
+ } ;
185
+
186
+ // Implicitly add `Self: DefaultAutoTrait` clauses on trait associated items if
187
+ // they are not added as super trait bounds to the trait itself. See comment on
188
+ // `requires_default_supertraits` for more details.
189
+ if !icx. lowerer ( ) . requires_default_supertraits ( trait_bounds, trait_generics) {
190
+ let mut bounds = Vec :: new ( ) ;
191
+ let self_ty_where_predicates = ( parent, item. generics . predicates ) ;
192
+ icx. lowerer ( ) . add_default_traits_with_filter (
193
+ & mut bounds,
194
+ tcx. types . self_param ,
195
+ & [ ] ,
196
+ Some ( self_ty_where_predicates) ,
197
+ item. span ,
198
+ |tr| tr != hir:: LangItem :: Sized ,
199
+ ) ;
200
+ predicates. extend ( bounds) ;
201
+ }
202
+ }
203
+
174
204
let generics = tcx. generics_of ( def_id) ;
175
205
176
206
// Below we'll consider the bounds on the type parameters (including `Self`)
@@ -181,11 +211,18 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
181
211
let mut bounds = Vec :: new ( ) ;
182
212
icx. lowerer ( ) . lower_bounds (
183
213
tcx. types . self_param ,
184
- self_bounds,
214
+ self_bounds. 0 ,
185
215
& mut bounds,
186
216
ty:: List :: empty ( ) ,
187
217
PredicateFilter :: All ,
188
218
) ;
219
+ icx. lowerer ( ) . add_default_super_traits (
220
+ def_id,
221
+ & mut bounds,
222
+ self_bounds. 0 ,
223
+ hir_generics,
224
+ self_bounds. 1 ,
225
+ ) ;
189
226
predicates. extend ( bounds) ;
190
227
}
191
228
@@ -210,8 +247,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
210
247
GenericParamKind :: Type { .. } => {
211
248
let param_ty = icx. lowerer ( ) . lower_ty_param ( param. hir_id ) ;
212
249
let mut bounds = Vec :: new ( ) ;
213
- // Params are implicitly sized unless a `?Sized ` bound is found
214
- icx. lowerer ( ) . add_sized_bound (
250
+ // Implicit bounds are added to type params unless a `?Trait ` bound is found
251
+ icx. lowerer ( ) . add_default_traits (
215
252
& mut bounds,
216
253
param_ty,
217
254
& [ ] ,
@@ -625,6 +662,22 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
625
662
let self_param_ty = tcx. types . self_param ;
626
663
let mut bounds = Vec :: new ( ) ;
627
664
icx. lowerer ( ) . lower_bounds ( self_param_ty, superbounds, & mut bounds, ty:: List :: empty ( ) , filter) ;
665
+ match filter {
666
+ PredicateFilter :: All
667
+ | PredicateFilter :: SelfOnly
668
+ | PredicateFilter :: SelfTraitThatDefines ( _)
669
+ | PredicateFilter :: SelfAndAssociatedTypeBounds => {
670
+ icx. lowerer ( ) . add_default_super_traits (
671
+ trait_def_id,
672
+ & mut bounds,
673
+ superbounds,
674
+ generics,
675
+ item. span ,
676
+ ) ;
677
+ }
678
+ //`ConstIfConst` is only interested in `~const` bounds.
679
+ PredicateFilter :: ConstIfConst | PredicateFilter :: SelfConstIfConst => { }
680
+ }
628
681
629
682
let where_bounds_that_match =
630
683
icx. probe_ty_param_bounds_in_generics ( generics, item. owner_id . def_id , filter) ;
0 commit comments