@@ -2107,18 +2107,21 @@ pub(super) fn check_type_bounds<'tcx>(
2107
2107
ObligationCause :: new ( impl_ty_span, impl_ty_def_id, code)
2108
2108
} ;
2109
2109
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 ( ) ;
2118
2120
2119
2121
// Only in a const implementation do we need to check that the `~const` item bounds hold.
2120
2122
if tcx. is_conditionally_const ( impl_ty_def_id) {
2121
- obligations. extend (
2123
+ obligations. extend ( util:: elaborate (
2124
+ tcx,
2122
2125
tcx. explicit_implied_const_bounds ( trait_ty. def_id )
2123
2126
. iter_instantiated_copied ( tcx, rebased_args)
2124
2127
. map ( |( c, span) | {
@@ -2129,34 +2132,27 @@ pub(super) fn check_type_bounds<'tcx>(
2129
2132
c. to_host_effect_clause ( tcx, ty:: BoundConstness :: Maybe ) ,
2130
2133
)
2131
2134
} ) ,
2132
- ) ;
2135
+ ) ) ;
2133
2136
}
2134
2137
debug ! ( item_bounds=?obligations) ;
2135
2138
2136
2139
// Normalize predicates with the assumption that the GAT may always normalize
2137
2140
// to its definition type. This should be the param-env we use to *prove* the
2138
2141
// predicate too, but we don't do that because of performance issues.
2139
2142
// 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 ( ) ;
2142
2143
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
+ }
2157
2151
}
2152
+
2158
2153
// Check that all obligations are satisfied by the implementation's
2159
2154
// version.
2155
+ ocx. register_obligations ( obligations) ;
2160
2156
let errors = ocx. select_all_or_error ( ) ;
2161
2157
if !errors. is_empty ( ) {
2162
2158
let reported = infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
@@ -2168,22 +2164,6 @@ pub(super) fn check_type_bounds<'tcx>(
2168
2164
ocx. resolve_regions_and_report_errors ( impl_ty_def_id, param_env, assumed_wf_types)
2169
2165
}
2170
2166
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
-
2187
2167
/// Install projection predicates that allow GATs to project to their own
2188
2168
/// definition types. This is not allowed in general in cases of default
2189
2169
/// associated types in trait definitions, or when specialization is involved,
0 commit comments