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