@@ -2105,18 +2105,21 @@ pub(super) fn check_type_bounds<'tcx>(
21052105 ObligationCause :: new ( impl_ty_span, impl_ty_def_id, code)
21062106 } ;
21072107
2108- let mut obligations: Vec < _ > = tcx
2109- . explicit_item_bounds ( trait_ty. def_id )
2110- . iter_instantiated_copied ( tcx, rebased_args)
2111- . map ( |( concrete_ty_bound, span) | {
2112- debug ! ( ?concrete_ty_bound) ;
2113- traits:: Obligation :: new ( tcx, mk_cause ( span) , param_env, concrete_ty_bound)
2114- } )
2115- . collect ( ) ;
2108+ let mut obligations: Vec < _ > = util:: elaborate (
2109+ tcx,
2110+ tcx. explicit_item_bounds ( trait_ty. def_id ) . iter_instantiated_copied ( tcx, rebased_args) . map (
2111+ |( concrete_ty_bound, span) | {
2112+ debug ! ( ?concrete_ty_bound) ;
2113+ traits:: Obligation :: new ( tcx, mk_cause ( span) , param_env, concrete_ty_bound)
2114+ } ,
2115+ ) ,
2116+ )
2117+ . collect ( ) ;
21162118
21172119 // Only in a const implementation do we need to check that the `~const` item bounds hold.
21182120 if tcx. is_conditionally_const ( impl_ty_def_id) {
2119- obligations. extend (
2121+ obligations. extend ( util:: elaborate (
2122+ tcx,
21202123 tcx. explicit_implied_const_bounds ( trait_ty. def_id )
21212124 . iter_instantiated_copied ( tcx, rebased_args)
21222125 . map ( |( c, span) | {
@@ -2127,34 +2130,27 @@ pub(super) fn check_type_bounds<'tcx>(
21272130 c. to_host_effect_clause ( tcx, ty:: BoundConstness :: Maybe ) ,
21282131 )
21292132 } ) ,
2130- ) ;
2133+ ) ) ;
21312134 }
21322135 debug ! ( item_bounds=?obligations) ;
21332136
21342137 // Normalize predicates with the assumption that the GAT may always normalize
21352138 // to its definition type. This should be the param-env we use to *prove* the
21362139 // predicate too, but we don't do that because of performance issues.
21372140 // See <https://github.com/rust-lang/rust/pull/117542#issue-1976337685>.
2138- let trait_projection_ty = Ty :: new_projection_from_args ( tcx, trait_ty. def_id , rebased_args) ;
2139- let impl_identity_ty = tcx. type_of ( impl_ty. def_id ) . instantiate_identity ( ) ;
21402141 let normalize_param_env = param_env_with_gat_bounds ( tcx, impl_ty, impl_trait_ref) ;
2141- for mut obligation in util:: elaborate ( tcx, obligations) {
2142- let normalized_predicate = if infcx. next_trait_solver ( ) {
2143- obligation. predicate . fold_with ( & mut ReplaceTy {
2144- tcx,
2145- from : trait_projection_ty,
2146- to : impl_identity_ty,
2147- } )
2148- } else {
2149- ocx. normalize ( & normalize_cause, normalize_param_env, obligation. predicate )
2150- } ;
2151- debug ! ( ?normalized_predicate) ;
2152- obligation. predicate = normalized_predicate;
2153-
2154- ocx. register_obligation ( obligation) ;
2142+ for obligation in & mut obligations {
2143+ match ocx. deeply_normalize ( & normalize_cause, normalize_param_env, obligation. predicate ) {
2144+ Ok ( pred) => obligation. predicate = pred,
2145+ Err ( e) => {
2146+ return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( e) ) ;
2147+ }
2148+ }
21552149 }
2150+
21562151 // Check that all obligations are satisfied by the implementation's
21572152 // version.
2153+ ocx. register_obligations ( obligations) ;
21582154 let errors = ocx. select_all_or_error ( ) ;
21592155 if !errors. is_empty ( ) {
21602156 let reported = infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
@@ -2166,22 +2162,6 @@ pub(super) fn check_type_bounds<'tcx>(
21662162 ocx. resolve_regions_and_report_errors ( impl_ty_def_id, param_env, assumed_wf_types)
21672163}
21682164
2169- struct ReplaceTy < ' tcx > {
2170- tcx : TyCtxt < ' tcx > ,
2171- from : Ty < ' tcx > ,
2172- to : Ty < ' tcx > ,
2173- }
2174-
2175- impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for ReplaceTy < ' tcx > {
2176- fn cx ( & self ) -> TyCtxt < ' tcx > {
2177- self . tcx
2178- }
2179-
2180- fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
2181- if self . from == ty { self . to } else { ty. super_fold_with ( self ) }
2182- }
2183- }
2184-
21852165/// Install projection predicates that allow GATs to project to their own
21862166/// definition types. This is not allowed in general in cases of default
21872167/// associated types in trait definitions, or when specialization is involved,
0 commit comments