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