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