@@ -8,7 +8,6 @@ use rustc_infer::infer::InferCtxt;
8
8
use rustc_middle:: mir:: ConstraintCategory ;
9
9
use rustc_middle:: traits:: query:: OutlivesBound ;
10
10
use rustc_middle:: ty:: { self , RegionVid , Ty } ;
11
- use rustc_span:: Span ;
12
11
use rustc_trait_selection:: traits:: query:: type_op:: { self , TypeOp } ;
13
12
use std:: rc:: Rc ;
14
13
use type_op:: TypeOpOutput ;
@@ -35,16 +34,9 @@ pub(crate) struct UniversalRegionRelations<'tcx> {
35
34
inverse_outlives : TransitiveRelation < RegionVid > ,
36
35
}
37
36
38
- /// As part of computing the free region relations, we also have to
39
- /// normalize the input-output types, which we then need later. So we
40
- /// return those. This vector consists of first the input types and
41
- /// then the output type as the last element.
42
- type NormalizedInputsAndOutput < ' tcx > = Vec < Ty < ' tcx > > ;
43
-
44
37
pub ( crate ) struct CreateResult < ' tcx > {
45
38
pub ( crate ) universal_region_relations : Frozen < UniversalRegionRelations < ' tcx > > ,
46
39
pub ( crate ) region_bound_pairs : RegionBoundPairs < ' tcx > ,
47
- pub ( crate ) normalized_inputs_and_output : NormalizedInputsAndOutput < ' tcx > ,
48
40
}
49
41
50
42
pub ( crate ) fn create < ' tcx > (
@@ -222,68 +214,27 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
222
214
. chain ( Some ( self . universal_regions . unnormalized_output_ty ) ) ;
223
215
224
216
// For each of the input/output types:
225
- // - Normalize the type. This will create some region
226
- // constraints, which we buffer up because we are
227
- // not ready to process them yet.
228
- // - Then compute the implied bounds. This will adjust
217
+ // - Compute the implied bounds. This will adjust
229
218
// the `region_bound_pairs` and so forth.
230
219
// - After this is done, we'll process the constraints, once
231
220
// the `relations` is built.
232
- let mut normalized_inputs_and_output =
233
- Vec :: with_capacity ( self . universal_regions . unnormalized_input_tys . len ( ) + 1 ) ;
234
- let mut constraints = vec ! [ ] ;
235
- for ty in unnormalized_input_output_tys {
236
- debug ! ( "build: input_or_output={:?}" , ty) ;
237
- // We add implied bounds from both the unnormalized and normalized ty.
238
- // See issue #87748
239
- let constraints_unnorm = self . add_implied_bounds ( ty) ;
240
- if let Some ( c) = constraints_unnorm {
241
- constraints. push ( c)
242
- }
243
- let TypeOpOutput { output : norm_ty, constraints : constraints_normalize, .. } = self
244
- . param_env
245
- . and ( type_op:: normalize:: Normalize :: new ( ty) )
246
- . fully_perform ( self . infcx )
247
- . unwrap_or_else ( |_| {
248
- let guar = self
249
- . infcx
250
- . tcx
251
- . sess
252
- . delay_span_bug ( span, & format ! ( "failed to normalize {:?}" , ty) ) ;
253
- TypeOpOutput {
254
- output : self . infcx . tcx . ty_error ( guar) ,
255
- constraints : None ,
256
- error_info : None ,
257
- }
258
- } ) ;
259
- if let Some ( c) = constraints_normalize {
260
- constraints. push ( c)
261
- }
262
-
263
- // Note: we need this in examples like
264
- // ```
265
- // trait Foo {
266
- // type Bar;
267
- // fn foo(&self) -> &Self::Bar;
268
- // }
269
- // impl Foo for () {
270
- // type Bar = ();
271
- // fn foo(&self) ->&() {}
272
- // }
273
- // ```
274
- // Both &Self::Bar and &() are WF
275
- if ty != norm_ty {
276
- let constraints_norm = self . add_implied_bounds ( norm_ty) ;
277
- if let Some ( c) = constraints_norm {
278
- constraints. push ( c)
279
- }
280
- }
281
-
282
- normalized_inputs_and_output. push ( norm_ty) ;
283
- }
284
-
285
- for c in constraints {
286
- self . push_region_constraints ( c, span) ;
221
+ let constraint_sets: Vec < _ > =
222
+ unnormalized_input_output_tys. flat_map ( |ty| self . add_implied_bounds ( ty) ) . collect ( ) ;
223
+
224
+ // Subtle: We can convert constraints only after the relations are built.
225
+ for data in & constraint_sets {
226
+ constraint_conversion:: ConstraintConversion :: new (
227
+ self . infcx ,
228
+ & self . universal_regions ,
229
+ & self . region_bound_pairs ,
230
+ self . implicit_region_bound ,
231
+ self . param_env ,
232
+ Locations :: All ( span) ,
233
+ span,
234
+ ConstraintCategory :: Internal ,
235
+ & mut self . constraints ,
236
+ )
237
+ . convert_all ( data) ;
287
238
}
288
239
289
240
CreateResult {
@@ -293,28 +244,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
293
244
inverse_outlives : self . inverse_outlives . freeze ( ) ,
294
245
} ) ,
295
246
region_bound_pairs : self . region_bound_pairs ,
296
- normalized_inputs_and_output,
297
247
}
298
248
}
299
249
300
- #[ instrument( skip( self , data) , level = "debug" ) ]
301
- fn push_region_constraints ( & mut self , data : & QueryRegionConstraints < ' tcx > , span : Span ) {
302
- debug ! ( "constraints generated: {:#?}" , data) ;
303
-
304
- constraint_conversion:: ConstraintConversion :: new (
305
- self . infcx ,
306
- & self . universal_regions ,
307
- & self . region_bound_pairs ,
308
- self . implicit_region_bound ,
309
- self . param_env ,
310
- Locations :: All ( span) ,
311
- span,
312
- ConstraintCategory :: Internal ,
313
- & mut self . constraints ,
314
- )
315
- . convert_all ( data) ;
316
- }
317
-
318
250
/// Update the type of a single local, which should represent
319
251
/// either the return type of the MIR or one of its arguments. At
320
252
/// the same time, compute and add any implied bounds that come
0 commit comments