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