@@ -19,9 +19,8 @@ use rustc_middle::query::Providers;
1919use rustc_middle:: traits:: solve:: NoSolution ;
2020use rustc_middle:: ty:: trait_def:: TraitSpecializationKind ;
2121use rustc_middle:: ty:: {
22- self , AdtKind , GenericArgKind , GenericArgs , GenericParamDefKind , Ty , TyCtxt , TypeFlags ,
23- TypeFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor , TypingMode ,
24- Upcast ,
22+ self , AdtKind , GenericArgKind , GenericArgs , GenericParamDefKind , Ty , TyCtxt , TypeFoldable ,
23+ TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor , TypingMode , Upcast ,
2524} ;
2625use rustc_middle:: { bug, span_bug} ;
2726use rustc_session:: parse:: feature_err;
@@ -111,16 +110,17 @@ where
111110
112111 let mut wfcx = WfCheckingCtxt { ocx, span, body_def_id, param_env } ;
113112
114- if !tcx. features ( ) . trivial_bounds ( ) {
115- wfcx. check_false_global_bounds ( )
116- }
117113 f ( & mut wfcx) ?;
118114
119115 let errors = wfcx. select_all_or_error ( ) ;
120116 if !errors. is_empty ( ) {
121117 return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ;
122118 }
123119
120+ if !tcx. features ( ) . trivial_bounds ( ) {
121+ wfcx. check_false_global_bounds ( ) ?;
122+ }
123+
124124 let assumed_wf_types = wfcx. ocx . assumed_wf_types_and_report_errors ( param_env, body_def_id) ?;
125125 debug ! ( ?assumed_wf_types) ;
126126
@@ -2274,7 +2274,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
22742274 /// Feature gates RFC 2056 -- trivial bounds, checking for global bounds that
22752275 /// aren't true.
22762276 #[ instrument( level = "debug" , skip( self ) ) ]
2277- fn check_false_global_bounds ( & mut self ) {
2277+ fn check_false_global_bounds ( & mut self ) -> Result < ( ) , ErrorGuaranteed > {
22782278 let tcx = self . ocx . infcx . tcx ;
22792279 let mut span = self . span ;
22802280 let empty_env = ty:: ParamEnv :: empty ( ) ;
@@ -2283,17 +2283,22 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
22832283 // Check elaborated bounds.
22842284 let implied_obligations = traits:: elaborate ( tcx, predicates_with_span) ;
22852285
2286+ let mut global_obligations = vec ! [ ] ;
22862287 for ( pred, obligation_span) in implied_obligations {
22872288 // We lower empty bounds like `Vec<dyn Copy>:` as
22882289 // `WellFormed(Vec<dyn Copy>)`, which will later get checked by
22892290 // regular WF checking
22902291 if let ty:: ClauseKind :: WellFormed ( ..) = pred. kind ( ) . skip_binder ( ) {
22912292 continue ;
22922293 }
2293- // Match the existing behavior.
2294- if pred. is_global ( ) && !pred. has_type_flags ( TypeFlags :: HAS_BINDER_VARS ) {
2295- let pred = self . normalize ( span, None , pred) ;
2296-
2294+ // Match the existing behavior. We normalize first to handle where-bounds
2295+ // like `u32: Trait<Assoc = T>`.
2296+ let clause = ObligationCause :: misc ( span, self . body_def_id ) ;
2297+ let Ok ( pred) = self . deeply_normalize ( & clause, self . param_env , pred) else {
2298+ tcx. dcx ( ) . delayed_bug ( "encountered errors when normalizing where-clauses" ) ;
2299+ continue ;
2300+ } ;
2301+ if pred. is_global ( ) && pred. kind ( ) . bound_vars ( ) . is_empty ( ) {
22972302 // only use the span of the predicate clause (#90869)
22982303 let hir_node = tcx. hir_node_by_def_id ( self . body_def_id ) ;
22992304 if let Some ( hir:: Generics { predicates, .. } ) = hir_node. generics ( ) {
@@ -2315,9 +2320,17 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23152320 empty_env,
23162321 pred,
23172322 ) ;
2318- self . ocx . register_obligation ( obligation) ;
2323+ global_obligations . push ( obligation) ;
23192324 }
23202325 }
2326+
2327+ self . register_obligations ( global_obligations) ;
2328+ let errors = self . select_all_or_error ( ) ;
2329+ if !errors. is_empty ( ) {
2330+ Err ( self . infcx . err_ctxt ( ) . report_fulfillment_errors ( errors) )
2331+ } else {
2332+ Ok ( ( ) )
2333+ }
23212334 }
23222335}
23232336
0 commit comments