@@ -5,13 +5,11 @@ use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelega
5
5
use rustc_infer:: infer:: region_constraints:: { GenericKind , VerifyBound } ;
6
6
use rustc_infer:: infer:: { self , InferCtxt , SubregionOrigin } ;
7
7
use rustc_middle:: mir:: { ClosureOutlivesSubject , ClosureRegionRequirements , ConstraintCategory } ;
8
+ use rustc_middle:: traits:: query:: NoSolution ;
8
9
use rustc_middle:: traits:: ObligationCause ;
9
- use rustc_middle:: ty:: GenericArgKind ;
10
- use rustc_middle:: ty:: { self , TyCtxt } ;
11
- use rustc_middle:: ty:: { TypeFoldable , TypeVisitableExt } ;
10
+ use rustc_middle:: ty:: { self , GenericArgKind , Ty , TyCtxt , TypeFoldable , TypeVisitableExt } ;
12
11
use rustc_span:: { Span , DUMMY_SP } ;
13
12
use rustc_trait_selection:: solve:: deeply_normalize;
14
- use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt ;
15
13
use rustc_trait_selection:: traits:: query:: type_op:: custom:: CustomTypeOp ;
16
14
use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
17
15
@@ -146,7 +144,6 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
146
144
let ConstraintConversion {
147
145
tcx,
148
146
infcx,
149
- param_env,
150
147
region_bound_pairs,
151
148
implicit_region_bound,
152
149
known_type_outlives_obligations,
@@ -178,43 +175,10 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
178
175
// Normalize the type we receive from a `TypeOutlives` obligation
179
176
// in the new trait solver.
180
177
if infcx. next_trait_solver ( ) {
181
- let result = CustomTypeOp :: new (
182
- |ocx| {
183
- match deeply_normalize (
184
- ocx. infcx . at (
185
- & ObligationCause :: dummy_with_span ( self . span ) ,
186
- param_env,
187
- ) ,
188
- t1,
189
- ) {
190
- Ok ( normalized_ty) => {
191
- t1 = normalized_ty;
192
- }
193
- Err ( e) => {
194
- infcx. err_ctxt ( ) . report_fulfillment_errors ( e) ;
195
- }
196
- }
197
-
198
- Ok ( ( ) )
199
- } ,
200
- "normalize type outlives obligation" ,
201
- )
202
- . fully_perform ( infcx, self . span ) ;
203
-
204
- match result {
205
- Ok ( TypeOpOutput { output : ( ) , constraints, .. } ) => {
206
- if let Some ( constraints) = constraints {
207
- assert ! (
208
- constraints. member_constraints. is_empty( ) ,
209
- "no member constraints expected from normalizing: {:#?}" ,
210
- constraints. member_constraints
211
- ) ;
212
- next_outlives_predicates
213
- . extend ( constraints. outlives . iter ( ) . copied ( ) ) ;
214
- }
215
- }
216
- Err ( _) => { }
217
- }
178
+ t1 = self . normalize_and_add_type_outlives_constraints (
179
+ t1,
180
+ & mut next_outlives_predicates,
181
+ ) ;
218
182
}
219
183
220
184
// we don't actually use this for anything, but
@@ -306,6 +270,42 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
306
270
debug ! ( "add_type_test(type_test={:?})" , type_test) ;
307
271
self . constraints . type_tests . push ( type_test) ;
308
272
}
273
+
274
+ fn normalize_and_add_type_outlives_constraints (
275
+ & self ,
276
+ ty : Ty < ' tcx > ,
277
+ next_outlives_predicates : & mut Vec < (
278
+ ty:: OutlivesPredicate < ty:: GenericArg < ' tcx > , ty:: Region < ' tcx > > ,
279
+ ConstraintCategory < ' tcx > ,
280
+ ) > ,
281
+ ) -> Ty < ' tcx > {
282
+ let result = CustomTypeOp :: new (
283
+ |ocx| {
284
+ deeply_normalize (
285
+ ocx. infcx . at ( & ObligationCause :: dummy_with_span ( self . span ) , self . param_env ) ,
286
+ ty,
287
+ )
288
+ . map_err ( |_| NoSolution )
289
+ } ,
290
+ "normalize type outlives obligation" ,
291
+ )
292
+ . fully_perform ( self . infcx , self . span ) ;
293
+
294
+ match result {
295
+ Ok ( TypeOpOutput { output : ty, constraints, .. } ) => {
296
+ if let Some ( constraints) = constraints {
297
+ assert ! (
298
+ constraints. member_constraints. is_empty( ) ,
299
+ "no member constraints expected from normalizing: {:#?}" ,
300
+ constraints. member_constraints
301
+ ) ;
302
+ next_outlives_predicates. extend ( constraints. outlives . iter ( ) . copied ( ) ) ;
303
+ }
304
+ ty
305
+ }
306
+ Err ( _) => ty,
307
+ }
308
+ }
309
309
}
310
310
311
311
impl < ' a , ' b , ' tcx > TypeOutlivesDelegate < ' tcx > for & ' a mut ConstraintConversion < ' b , ' tcx > {
0 commit comments