@@ -10,13 +10,13 @@ use rustc_middle::ty::{
1010} ;
1111use rustc_middle:: { bug, span_bug} ;
1212use rustc_span:: { DUMMY_SP , Ident , Span } ;
13- use tracing:: { debug, instrument, trace } ;
13+ use tracing:: { debug, instrument} ;
1414
1515use super :: item_bounds:: explicit_item_bounds_with_filter;
1616use crate :: collect:: ItemCtxt ;
1717use crate :: constrained_generic_params as cgp;
1818use crate :: delegation:: inherit_predicates_for_delegation_item;
19- use crate :: hir_ty_lowering:: { HirTyLowerer , PredicateFilter , RegionInferReason } ;
19+ use crate :: hir_ty_lowering:: { HirTyLowerer , PredicateFilter } ;
2020
2121/// Returns a list of all type predicates (explicit and implicit) for the definition with
2222/// ID `def_id`. This includes all predicates returned by `explicit_predicates_of`, plus
@@ -184,6 +184,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
184184 self_bounds,
185185 & mut bounds,
186186 ty:: List :: empty ( ) ,
187+ ty:: ListWithCachedTypeInfo :: empty ( ) ,
187188 PredicateFilter :: All ,
188189 ) ;
189190 predicates. extend ( bounds) ;
@@ -201,105 +202,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
201202 predicates. insert ( ( trait_ref. upcast ( tcx) , tcx. def_span ( def_id) ) ) ;
202203 }
203204
204- // Add implicit predicates that should be treated as if the user has written them,
205- // including the implicit `T: Sized` for all generic parameters, and `ConstArgHasType`
206- // for const params.
207- for param in hir_generics. params {
208- match param. kind {
209- GenericParamKind :: Lifetime { .. } => ( ) ,
210- GenericParamKind :: Type { .. } => {
211- let param_ty = icx. lowerer ( ) . lower_ty_param ( param. hir_id ) ;
212- let mut bounds = Vec :: new ( ) ;
213- // Params are implicitly sized unless a `?Sized` bound is found
214- icx. lowerer ( ) . add_sized_bound (
215- & mut bounds,
216- param_ty,
217- & [ ] ,
218- Some ( ( param. def_id , hir_generics. predicates ) ) ,
219- param. span ,
220- ) ;
221- trace ! ( ?bounds) ;
222- predicates. extend ( bounds) ;
223- trace ! ( ?predicates) ;
224- }
225- hir:: GenericParamKind :: Const { .. } => {
226- let param_def_id = param. def_id . to_def_id ( ) ;
227- let ct_ty = tcx. type_of ( param_def_id) . instantiate_identity ( ) ;
228- let ct = icx. lowerer ( ) . lower_const_param ( param_def_id, param. hir_id ) ;
229- predicates
230- . insert ( ( ty:: ClauseKind :: ConstArgHasType ( ct, ct_ty) . upcast ( tcx) , param. span ) ) ;
231- }
232- }
233- }
234-
235- trace ! ( ?predicates) ;
236- // Add inline `<T: Foo>` bounds and bounds in the where clause.
237- for predicate in hir_generics. predicates {
238- match predicate. kind {
239- hir:: WherePredicateKind :: BoundPredicate ( bound_pred) => {
240- let ty = icx. lowerer ( ) . lower_ty_maybe_return_type_notation ( bound_pred. bounded_ty ) ;
241-
242- let bound_vars = tcx. late_bound_vars ( predicate. hir_id ) ;
243- // Keep the type around in a dummy predicate, in case of no bounds.
244- // That way, `where Ty:` is not a complete noop (see #53696) and `Ty`
245- // is still checked for WF.
246- if bound_pred. bounds . is_empty ( ) {
247- if let ty:: Param ( _) = ty. kind ( ) {
248- // This is a `where T:`, which can be in the HIR from the
249- // transformation that moves `?Sized` to `T`'s declaration.
250- // We can skip the predicate because type parameters are
251- // trivially WF, but also we *should*, to avoid exposing
252- // users who never wrote `where Type:,` themselves, to
253- // compiler/tooling bugs from not handling WF predicates.
254- } else {
255- let span = bound_pred. bounded_ty . span ;
256- let predicate = ty:: Binder :: bind_with_vars (
257- ty:: ClauseKind :: WellFormed ( ty. into ( ) ) ,
258- bound_vars,
259- ) ;
260- predicates. insert ( ( predicate. upcast ( tcx) , span) ) ;
261- }
262- }
263-
264- let mut bounds = Vec :: new ( ) ;
265- icx. lowerer ( ) . lower_bounds (
266- ty,
267- bound_pred. bounds ,
268- & mut bounds,
269- bound_vars,
270- PredicateFilter :: All ,
271- ) ;
272- predicates. extend ( bounds) ;
273- }
274-
275- hir:: WherePredicateKind :: RegionPredicate ( region_pred) => {
276- let r1 = icx
277- . lowerer ( )
278- . lower_lifetime ( region_pred. lifetime , RegionInferReason :: RegionPredicate ) ;
279- predicates. extend ( region_pred. bounds . iter ( ) . map ( |bound| {
280- let ( r2, span) = match bound {
281- hir:: GenericBound :: Outlives ( lt) => (
282- icx. lowerer ( ) . lower_lifetime ( lt, RegionInferReason :: RegionPredicate ) ,
283- lt. ident . span ,
284- ) ,
285- bound => {
286- span_bug ! (
287- bound. span( ) ,
288- "lifetime param bounds must be outlives, but found {bound:?}"
289- )
290- }
291- } ;
292- let pred =
293- ty:: ClauseKind :: RegionOutlives ( ty:: OutlivesPredicate ( r1, r2) ) . upcast ( tcx) ;
294- ( pred, span)
295- } ) )
296- }
297-
298- hir:: WherePredicateKind :: EqPredicate ( ..) => {
299- // FIXME(#20041)
300- }
301- }
302- }
205+ icx. lowerer ( ) . lower_where_predicates (
206+ hir_generics. params ,
207+ hir_generics. predicates ,
208+ & mut predicates,
209+ ) ;
303210
304211 if tcx. features ( ) . generic_const_exprs ( ) {
305212 predicates. extend ( const_evaluatable_predicates_of ( tcx, def_id, & predicates) ) ;
@@ -624,7 +531,14 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
624531
625532 let self_param_ty = tcx. types . self_param ;
626533 let mut bounds = Vec :: new ( ) ;
627- icx. lowerer ( ) . lower_bounds ( self_param_ty, superbounds, & mut bounds, ty:: List :: empty ( ) , filter) ;
534+ icx. lowerer ( ) . lower_bounds (
535+ self_param_ty,
536+ superbounds,
537+ & mut bounds,
538+ ty:: List :: empty ( ) ,
539+ ty:: ListWithCachedTypeInfo :: empty ( ) ,
540+ filter,
541+ ) ;
628542
629543 let where_bounds_that_match =
630544 icx. probe_ty_param_bounds_in_generics ( generics, item. owner_id . def_id , filter) ;
@@ -924,12 +838,24 @@ impl<'tcx> ItemCtxt<'tcx> {
924838
925839 let bound_ty = self . lowerer ( ) . lower_ty_maybe_return_type_notation ( predicate. bounded_ty ) ;
926840
841+ let mut bound_assumptions = FxIndexSet :: default ( ) ;
842+ if self . tcx . features ( ) . non_lifetime_binders ( ) {
843+ self . lowerer ( ) . lower_where_predicates (
844+ predicate. bound_generic_params ,
845+ predicate. bound_assumptions ,
846+ & mut bound_assumptions,
847+ ) ;
848+ }
849+ let bound_assumptions =
850+ self . tcx ( ) . mk_clauses_from_iter ( bound_assumptions. into_iter ( ) . map ( |( c, _) | c) ) ;
851+
927852 let bound_vars = self . tcx . late_bound_vars ( hir_id) ;
928853 self . lowerer ( ) . lower_bounds (
929854 bound_ty,
930855 predicate. bounds ,
931856 & mut bounds,
932857 bound_vars,
858+ bound_assumptions,
933859 filter,
934860 ) ;
935861 }
@@ -1003,12 +929,25 @@ pub(super) fn const_conditions<'tcx>(
1003929 match pred. kind {
1004930 hir:: WherePredicateKind :: BoundPredicate ( bound_pred) => {
1005931 let ty = icx. lowerer ( ) . lower_ty_maybe_return_type_notation ( bound_pred. bounded_ty ) ;
932+
933+ let mut bound_assumptions = FxIndexSet :: default ( ) ;
934+ if tcx. features ( ) . non_lifetime_binders ( ) {
935+ icx. lowerer ( ) . lower_where_predicates (
936+ bound_pred. bound_generic_params ,
937+ bound_pred. bound_assumptions ,
938+ & mut bound_assumptions,
939+ ) ;
940+ }
941+ let bound_assumptions =
942+ icx. tcx ( ) . mk_clauses_from_iter ( bound_assumptions. into_iter ( ) . map ( |( c, _) | c) ) ;
943+
1006944 let bound_vars = tcx. late_bound_vars ( pred. hir_id ) ;
1007945 icx. lowerer ( ) . lower_bounds (
1008946 ty,
1009947 bound_pred. bounds . iter ( ) ,
1010948 & mut bounds,
1011949 bound_vars,
950+ bound_assumptions,
1012951 PredicateFilter :: ConstIfConst ,
1013952 ) ;
1014953 }
@@ -1029,6 +968,7 @@ pub(super) fn const_conditions<'tcx>(
1029968 supertraits,
1030969 & mut bounds,
1031970 ty:: List :: empty ( ) ,
971+ ty:: ListWithCachedTypeInfo :: empty ( ) ,
1032972 PredicateFilter :: ConstIfConst ,
1033973 ) ;
1034974 }
0 commit comments