@@ -144,7 +144,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
144
144
}
145
145
146
146
ItemKind :: Trait ( _, _, _, self_bounds, ..) | ItemKind :: TraitAlias ( _, self_bounds) => {
147
- is_trait = Some ( self_bounds) ;
147
+ is_trait = Some ( ( self_bounds, item . span ) ) ;
148
148
}
149
149
150
150
ItemKind :: Fn ( sig, _, _) => {
@@ -159,6 +159,34 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
159
159
_ => { }
160
160
}
161
161
} ;
162
+ if let Node :: TraitItem ( item) = node {
163
+ let parent = tcx. local_parent ( item. hir_id ( ) . owner . def_id ) ;
164
+ let Node :: Item ( parent_trait) = tcx. hir_node_by_def_id ( parent) else {
165
+ unreachable ! ( ) ;
166
+ } ;
167
+
168
+ let ( trait_generics, trait_bounds) = match parent_trait. kind {
169
+ hir:: ItemKind :: Trait ( .., generics, supertraits, _) => ( generics, supertraits) ,
170
+ hir:: ItemKind :: TraitAlias ( generics, supertraits) => ( generics, supertraits) ,
171
+ _ => unreachable ! ( ) ,
172
+ } ;
173
+
174
+ // Implicitly add `Self: Trait` clauses on trait associated items.
175
+ // See comment on `add_implicit_super_traits` for more details.
176
+ if !icx. lowerer ( ) . requires_implicit_supertraits ( parent, trait_bounds, trait_generics) {
177
+ let mut bounds = Bounds :: default ( ) ;
178
+ let self_ty_where_predicates = ( parent, item. generics . predicates ) ;
179
+ icx. lowerer ( ) . add_implicit_traits_with_filter (
180
+ & mut bounds,
181
+ tcx. types . self_param ,
182
+ & [ ] ,
183
+ Some ( self_ty_where_predicates) ,
184
+ item. span ,
185
+ |tr| tr != hir:: LangItem :: Sized ,
186
+ ) ;
187
+ predicates. extend ( bounds. clauses ( tcx) ) ;
188
+ }
189
+ }
162
190
163
191
let generics = tcx. generics_of ( def_id) ;
164
192
@@ -167,11 +195,18 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
167
195
// on a trait we must also consider the bounds that follow the trait's name,
168
196
// like `trait Foo: A + B + C`.
169
197
if let Some ( self_bounds) = is_trait {
170
- let bounds = icx. lowerer ( ) . lower_mono_bounds (
198
+ let mut bounds = icx. lowerer ( ) . lower_mono_bounds (
171
199
tcx. types . self_param ,
172
- self_bounds,
200
+ self_bounds. 0 ,
173
201
PredicateFilter :: All ,
174
202
) ;
203
+ icx. lowerer ( ) . add_implicit_super_traits (
204
+ def_id,
205
+ & mut bounds,
206
+ self_bounds. 0 ,
207
+ hir_generics,
208
+ self_bounds. 1 ,
209
+ ) ;
175
210
predicates. extend ( bounds. clauses ( tcx) ) ;
176
211
effects_min_tys. extend ( bounds. effects_min_tys ( ) ) ;
177
212
}
@@ -197,8 +232,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
197
232
GenericParamKind :: Type { .. } => {
198
233
let param_ty = icx. lowerer ( ) . lower_ty_param ( param. hir_id ) ;
199
234
let mut bounds = Bounds :: default ( ) ;
200
- // Params are implicitly sized unless a `?Sized ` bound is found
201
- icx. lowerer ( ) . add_sized_bound (
235
+ // Implicit bounds are added to type params unless a `?Trait ` bound is found
236
+ icx. lowerer ( ) . add_implicit_traits (
202
237
& mut bounds,
203
238
param_ty,
204
239
& [ ] ,
@@ -620,7 +655,14 @@ pub(super) fn implied_predicates_with_filter(
620
655
let icx = ItemCtxt :: new ( tcx, trait_def_id) ;
621
656
622
657
let self_param_ty = tcx. types . self_param ;
623
- let superbounds = icx. lowerer ( ) . lower_mono_bounds ( self_param_ty, bounds, filter) ;
658
+ let mut superbounds = icx. lowerer ( ) . lower_mono_bounds ( self_param_ty, bounds, filter) ;
659
+ icx. lowerer ( ) . add_implicit_super_traits (
660
+ trait_def_id,
661
+ & mut superbounds,
662
+ bounds,
663
+ generics,
664
+ item. span ,
665
+ ) ;
624
666
625
667
let where_bounds_that_match = icx. probe_ty_param_bounds_in_generics (
626
668
generics,
0 commit comments