@@ -2107,18 +2107,21 @@ pub(super) fn check_type_bounds<'tcx>(
21072107 ObligationCause :: new ( impl_ty_span, impl_ty_def_id, code)
21082108 } ;
21092109
2110- let mut obligations: Vec < _ > = tcx
2111- . explicit_item_bounds ( trait_ty. def_id )
2112- . iter_instantiated_copied ( tcx, rebased_args)
2113- . map ( |( concrete_ty_bound, span) | {
2114- debug ! ( ?concrete_ty_bound) ;
2115- traits:: Obligation :: new ( tcx, mk_cause ( span) , param_env, concrete_ty_bound)
2116- } )
2117- . collect ( ) ;
2110+ let mut obligations: Vec < _ > = util:: elaborate (
2111+ tcx,
2112+ tcx. explicit_item_bounds ( trait_ty. def_id ) . iter_instantiated_copied ( tcx, rebased_args) . map (
2113+ |( concrete_ty_bound, span) | {
2114+ debug ! ( ?concrete_ty_bound) ;
2115+ traits:: Obligation :: new ( tcx, mk_cause ( span) , param_env, concrete_ty_bound)
2116+ } ,
2117+ ) ,
2118+ )
2119+ . collect ( ) ;
21182120
21192121 // Only in a const implementation do we need to check that the `~const` item bounds hold.
21202122 if tcx. is_conditionally_const ( impl_ty_def_id) {
2121- obligations. extend (
2123+ obligations. extend ( util:: elaborate (
2124+ tcx,
21222125 tcx. explicit_implied_const_bounds ( trait_ty. def_id )
21232126 . iter_instantiated_copied ( tcx, rebased_args)
21242127 . map ( |( c, span) | {
@@ -2129,34 +2132,27 @@ pub(super) fn check_type_bounds<'tcx>(
21292132 c. to_host_effect_clause ( tcx, ty:: BoundConstness :: Maybe ) ,
21302133 )
21312134 } ) ,
2132- ) ;
2135+ ) ) ;
21332136 }
21342137 debug ! ( item_bounds=?obligations) ;
21352138
21362139 // Normalize predicates with the assumption that the GAT may always normalize
21372140 // to its definition type. This should be the param-env we use to *prove* the
21382141 // predicate too, but we don't do that because of performance issues.
21392142 // See <https://github.com/rust-lang/rust/pull/117542#issue-1976337685>.
2140- let trait_projection_ty = Ty :: new_projection_from_args ( tcx, trait_ty. def_id , rebased_args) ;
2141- let impl_identity_ty = tcx. type_of ( impl_ty. def_id ) . instantiate_identity ( ) ;
21422143 let normalize_param_env = param_env_with_gat_bounds ( tcx, impl_ty, impl_trait_ref) ;
2143- for mut obligation in util:: elaborate ( tcx, obligations) {
2144- let normalized_predicate = if infcx. next_trait_solver ( ) {
2145- obligation. predicate . fold_with ( & mut ReplaceTy {
2146- tcx,
2147- from : trait_projection_ty,
2148- to : impl_identity_ty,
2149- } )
2150- } else {
2151- ocx. normalize ( & normalize_cause, normalize_param_env, obligation. predicate )
2152- } ;
2153- debug ! ( ?normalized_predicate) ;
2154- obligation. predicate = normalized_predicate;
2155-
2156- ocx. register_obligation ( obligation) ;
2144+ for obligation in & mut obligations {
2145+ match ocx. deeply_normalize ( & normalize_cause, normalize_param_env, obligation. predicate ) {
2146+ Ok ( pred) => obligation. predicate = pred,
2147+ Err ( e) => {
2148+ return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( e) ) ;
2149+ }
2150+ }
21572151 }
2152+
21582153 // Check that all obligations are satisfied by the implementation's
21592154 // version.
2155+ ocx. register_obligations ( obligations) ;
21602156 let errors = ocx. select_all_or_error ( ) ;
21612157 if !errors. is_empty ( ) {
21622158 let reported = infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
@@ -2168,22 +2164,6 @@ pub(super) fn check_type_bounds<'tcx>(
21682164 ocx. resolve_regions_and_report_errors ( impl_ty_def_id, param_env, assumed_wf_types)
21692165}
21702166
2171- struct ReplaceTy < ' tcx > {
2172- tcx : TyCtxt < ' tcx > ,
2173- from : Ty < ' tcx > ,
2174- to : Ty < ' tcx > ,
2175- }
2176-
2177- impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for ReplaceTy < ' tcx > {
2178- fn cx ( & self ) -> TyCtxt < ' tcx > {
2179- self . tcx
2180- }
2181-
2182- fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
2183- if self . from == ty { self . to } else { ty. super_fold_with ( self ) }
2184- }
2185- }
2186-
21872167/// Install projection predicates that allow GATs to project to their own
21882168/// definition types. This is not allowed in general in cases of default
21892169/// associated types in trait definitions, or when specialization is involved,
0 commit comments