@@ -10,13 +10,13 @@ use rustc_middle::ty::{
10
10
} ;
11
11
use rustc_middle:: { bug, span_bug} ;
12
12
use rustc_span:: { DUMMY_SP , Ident , Span } ;
13
- use tracing:: { debug, instrument, trace } ;
13
+ use tracing:: { debug, instrument} ;
14
14
15
15
use super :: item_bounds:: explicit_item_bounds_with_filter;
16
16
use crate :: collect:: ItemCtxt ;
17
17
use crate :: constrained_generic_params as cgp;
18
18
use crate :: delegation:: inherit_predicates_for_delegation_item;
19
- use crate :: hir_ty_lowering:: { HirTyLowerer , PredicateFilter , RegionInferReason } ;
19
+ use crate :: hir_ty_lowering:: { HirTyLowerer , PredicateFilter } ;
20
20
21
21
/// Returns a list of all type predicates (explicit and implicit) for the definition with
22
22
/// ID `def_id`. This includes all predicates returned by `explicit_predicates_of`, plus
@@ -183,6 +183,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
183
183
self_bounds,
184
184
& mut bounds,
185
185
ty:: List :: empty ( ) ,
186
+ ty:: ListWithCachedTypeInfo :: empty ( ) ,
186
187
PredicateFilter :: All ,
187
188
) ;
188
189
predicates. extend ( bounds) ;
@@ -200,105 +201,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
200
201
predicates. insert ( ( trait_ref. upcast ( tcx) , tcx. def_span ( def_id) ) ) ;
201
202
}
202
203
203
- // Add implicit predicates that should be treated as if the user has written them,
204
- // including the implicit `T: Sized` for all generic parameters, and `ConstArgHasType`
205
- // for const params.
206
- for param in hir_generics. params {
207
- match param. kind {
208
- GenericParamKind :: Lifetime { .. } => ( ) ,
209
- GenericParamKind :: Type { .. } => {
210
- let param_ty = icx. lowerer ( ) . lower_ty_param ( param. hir_id ) ;
211
- let mut bounds = Vec :: new ( ) ;
212
- // Params are implicitly sized unless a `?Sized` bound is found
213
- icx. lowerer ( ) . add_sized_bound (
214
- & mut bounds,
215
- param_ty,
216
- & [ ] ,
217
- Some ( ( param. def_id , hir_generics. predicates ) ) ,
218
- param. span ,
219
- ) ;
220
- trace ! ( ?bounds) ;
221
- predicates. extend ( bounds) ;
222
- trace ! ( ?predicates) ;
223
- }
224
- hir:: GenericParamKind :: Const { .. } => {
225
- let param_def_id = param. def_id . to_def_id ( ) ;
226
- let ct_ty = tcx. type_of ( param_def_id) . instantiate_identity ( ) ;
227
- let ct = icx. lowerer ( ) . lower_const_param ( param_def_id, param. hir_id ) ;
228
- predicates
229
- . insert ( ( ty:: ClauseKind :: ConstArgHasType ( ct, ct_ty) . upcast ( tcx) , param. span ) ) ;
230
- }
231
- }
232
- }
233
-
234
- trace ! ( ?predicates) ;
235
- // Add inline `<T: Foo>` bounds and bounds in the where clause.
236
- for predicate in hir_generics. predicates {
237
- match predicate. kind {
238
- hir:: WherePredicateKind :: BoundPredicate ( bound_pred) => {
239
- let ty = icx. lowerer ( ) . lower_ty_maybe_return_type_notation ( bound_pred. bounded_ty ) ;
240
-
241
- let bound_vars = tcx. late_bound_vars ( predicate. hir_id ) ;
242
- // Keep the type around in a dummy predicate, in case of no bounds.
243
- // That way, `where Ty:` is not a complete noop (see #53696) and `Ty`
244
- // is still checked for WF.
245
- if bound_pred. bounds . is_empty ( ) {
246
- if let ty:: Param ( _) = ty. kind ( ) {
247
- // This is a `where T:`, which can be in the HIR from the
248
- // transformation that moves `?Sized` to `T`'s declaration.
249
- // We can skip the predicate because type parameters are
250
- // trivially WF, but also we *should*, to avoid exposing
251
- // users who never wrote `where Type:,` themselves, to
252
- // compiler/tooling bugs from not handling WF predicates.
253
- } else {
254
- let span = bound_pred. bounded_ty . span ;
255
- let predicate = ty:: Binder :: bind_with_vars (
256
- ty:: ClauseKind :: WellFormed ( ty. into ( ) ) ,
257
- bound_vars,
258
- ) ;
259
- predicates. insert ( ( predicate. upcast ( tcx) , span) ) ;
260
- }
261
- }
262
-
263
- let mut bounds = Vec :: new ( ) ;
264
- icx. lowerer ( ) . lower_bounds (
265
- ty,
266
- bound_pred. bounds ,
267
- & mut bounds,
268
- bound_vars,
269
- PredicateFilter :: All ,
270
- ) ;
271
- predicates. extend ( bounds) ;
272
- }
273
-
274
- hir:: WherePredicateKind :: RegionPredicate ( region_pred) => {
275
- let r1 = icx
276
- . lowerer ( )
277
- . lower_lifetime ( region_pred. lifetime , RegionInferReason :: RegionPredicate ) ;
278
- predicates. extend ( region_pred. bounds . iter ( ) . map ( |bound| {
279
- let ( r2, span) = match bound {
280
- hir:: GenericBound :: Outlives ( lt) => (
281
- icx. lowerer ( ) . lower_lifetime ( lt, RegionInferReason :: RegionPredicate ) ,
282
- lt. ident . span ,
283
- ) ,
284
- bound => {
285
- span_bug ! (
286
- bound. span( ) ,
287
- "lifetime param bounds must be outlives, but found {bound:?}"
288
- )
289
- }
290
- } ;
291
- let pred =
292
- ty:: ClauseKind :: RegionOutlives ( ty:: OutlivesPredicate ( r1, r2) ) . upcast ( tcx) ;
293
- ( pred, span)
294
- } ) )
295
- }
296
-
297
- hir:: WherePredicateKind :: EqPredicate ( ..) => {
298
- // FIXME(#20041)
299
- }
300
- }
301
- }
204
+ icx. lowerer ( ) . lower_where_predicates (
205
+ hir_generics. params ,
206
+ hir_generics. predicates ,
207
+ & mut predicates,
208
+ ) ;
302
209
303
210
if tcx. features ( ) . generic_const_exprs ( ) {
304
211
predicates. extend ( const_evaluatable_predicates_of ( tcx, def_id, & predicates) ) ;
@@ -623,7 +530,14 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
623
530
624
531
let self_param_ty = tcx. types . self_param ;
625
532
let mut bounds = Vec :: new ( ) ;
626
- icx. lowerer ( ) . lower_bounds ( self_param_ty, superbounds, & mut bounds, ty:: List :: empty ( ) , filter) ;
533
+ icx. lowerer ( ) . lower_bounds (
534
+ self_param_ty,
535
+ superbounds,
536
+ & mut bounds,
537
+ ty:: List :: empty ( ) ,
538
+ ty:: ListWithCachedTypeInfo :: empty ( ) ,
539
+ filter,
540
+ ) ;
627
541
628
542
let where_bounds_that_match =
629
543
icx. probe_ty_param_bounds_in_generics ( generics, item. owner_id . def_id , filter) ;
@@ -923,12 +837,24 @@ impl<'tcx> ItemCtxt<'tcx> {
923
837
924
838
let bound_ty = self . lowerer ( ) . lower_ty_maybe_return_type_notation ( predicate. bounded_ty ) ;
925
839
840
+ let mut bound_assumptions = FxIndexSet :: default ( ) ;
841
+ if self . tcx . features ( ) . non_lifetime_binders ( ) {
842
+ self . lowerer ( ) . lower_where_predicates (
843
+ predicate. bound_generic_params ,
844
+ predicate. bound_assumptions ,
845
+ & mut bound_assumptions,
846
+ ) ;
847
+ }
848
+ let bound_assumptions =
849
+ self . tcx ( ) . mk_clauses_from_iter ( bound_assumptions. into_iter ( ) . map ( |( c, _) | c) ) ;
850
+
926
851
let bound_vars = self . tcx . late_bound_vars ( hir_id) ;
927
852
self . lowerer ( ) . lower_bounds (
928
853
bound_ty,
929
854
predicate. bounds ,
930
855
& mut bounds,
931
856
bound_vars,
857
+ bound_assumptions,
932
858
filter,
933
859
) ;
934
860
}
@@ -1002,12 +928,25 @@ pub(super) fn const_conditions<'tcx>(
1002
928
match pred. kind {
1003
929
hir:: WherePredicateKind :: BoundPredicate ( bound_pred) => {
1004
930
let ty = icx. lowerer ( ) . lower_ty_maybe_return_type_notation ( bound_pred. bounded_ty ) ;
931
+
932
+ let mut bound_assumptions = FxIndexSet :: default ( ) ;
933
+ if tcx. features ( ) . non_lifetime_binders ( ) {
934
+ icx. lowerer ( ) . lower_where_predicates (
935
+ bound_pred. bound_generic_params ,
936
+ bound_pred. bound_assumptions ,
937
+ & mut bound_assumptions,
938
+ ) ;
939
+ }
940
+ let bound_assumptions =
941
+ icx. tcx ( ) . mk_clauses_from_iter ( bound_assumptions. into_iter ( ) . map ( |( c, _) | c) ) ;
942
+
1005
943
let bound_vars = tcx. late_bound_vars ( pred. hir_id ) ;
1006
944
icx. lowerer ( ) . lower_bounds (
1007
945
ty,
1008
946
bound_pred. bounds . iter ( ) ,
1009
947
& mut bounds,
1010
948
bound_vars,
949
+ bound_assumptions,
1011
950
PredicateFilter :: ConstIfConst ,
1012
951
) ;
1013
952
}
@@ -1028,6 +967,7 @@ pub(super) fn const_conditions<'tcx>(
1028
967
supertraits,
1029
968
& mut bounds,
1030
969
ty:: List :: empty ( ) ,
970
+ ty:: ListWithCachedTypeInfo :: empty ( ) ,
1031
971
PredicateFilter :: ConstIfConst ,
1032
972
) ;
1033
973
}
0 commit comments