@@ -11,8 +11,7 @@ use rustc_hir::def_id::LocalDefId;
11
11
use rustc_index:: IndexSlice ;
12
12
use rustc_middle:: mir:: pretty:: { PrettyPrintMirOptions , dump_mir_with_options} ;
13
13
use rustc_middle:: mir:: {
14
- Body , ClosureOutlivesSubject , ClosureRegionRequirements , PassWhere , Promoted , create_dump_file,
15
- dump_enabled, dump_mir,
14
+ Body , ClosureRequirements , PassWhere , Promoted , create_dump_file, dump_enabled, dump_mir,
16
15
} ;
17
16
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
18
17
use rustc_middle:: ty:: { self , OpaqueHiddenType , TyCtxt } ;
@@ -43,7 +42,7 @@ pub(crate) struct NllOutput<'tcx> {
43
42
pub opaque_type_values : FxIndexMap < LocalDefId , OpaqueHiddenType < ' tcx > > ,
44
43
pub polonius_input : Option < Box < PoloniusFacts > > ,
45
44
pub polonius_output : Option < Box < PoloniusOutput > > ,
46
- pub opt_closure_req : Option < ClosureRegionRequirements < ' tcx > > ,
45
+ pub opt_closure_req : Option < ClosureRequirements < ' tcx > > ,
47
46
pub nll_errors : RegionErrors < ' tcx > ,
48
47
49
48
/// When using `-Zpolonius=next`: the localized typeck and liveness constraints.
@@ -171,22 +170,44 @@ pub(crate) fn compute_regions<'a, 'tcx>(
171
170
} ) ;
172
171
173
172
// Solve the region constraints.
174
- let ( closure_region_requirements , nll_errors) =
173
+ let ( closure_outlives_requirements , nll_errors) =
175
174
regioncx. solve ( infcx, body, polonius_output. clone ( ) ) ;
176
175
177
176
if let Some ( guar) = nll_errors. has_errors ( ) {
178
177
// Suppress unhelpful extra errors in `infer_opaque_types`.
179
178
infcx. set_tainted_by_errors ( guar) ;
180
179
}
181
180
182
- let remapped_opaque_tys = regioncx. infer_opaque_types ( infcx, opaque_type_values) ;
181
+ let ( opaque_type_values, opt_closure_req) = if infcx. tcx . is_typeck_child ( body. source . def_id ( ) ) {
182
+ let opaque_types = regioncx. propagate_opaque_types ( infcx, opaque_type_values) ;
183
+ let num_external_vids = regioncx. universal_regions ( ) . num_global_and_external_regions ( ) ;
184
+ let closure_requirements = ClosureRequirements {
185
+ num_external_vids,
186
+ num_existential_external_regions : regioncx
187
+ . universal_regions ( )
188
+ . existential_external_regions
189
+ . len ( ) ,
190
+ outlives_requirements : closure_outlives_requirements. unwrap ( ) ,
191
+ opaque_types,
192
+ } ;
193
+ if closure_requirements. outlives_requirements . is_empty ( )
194
+ && closure_requirements. opaque_types . is_empty ( )
195
+ {
196
+ ( Default :: default ( ) , None )
197
+ } else {
198
+ ( Default :: default ( ) , Some ( closure_requirements) )
199
+ }
200
+ } else {
201
+ assert ! ( closure_outlives_requirements. is_none( ) ) ;
202
+ ( regioncx. infer_opaque_types ( infcx, opaque_type_values) , None )
203
+ } ;
183
204
184
205
NllOutput {
185
206
regioncx,
186
- opaque_type_values : remapped_opaque_tys ,
207
+ opaque_type_values,
187
208
polonius_input : polonius_facts. map ( Box :: new) ,
188
209
polonius_output,
189
- opt_closure_req : closure_region_requirements ,
210
+ opt_closure_req,
190
211
nll_errors,
191
212
localized_outlives_constraints,
192
213
}
@@ -205,7 +226,7 @@ pub(super) fn dump_nll_mir<'tcx>(
205
226
infcx : & BorrowckInferCtxt < ' tcx > ,
206
227
body : & Body < ' tcx > ,
207
228
regioncx : & RegionInferenceContext < ' tcx > ,
208
- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
229
+ closure_requirements : & Option < ClosureRequirements < ' tcx > > ,
209
230
borrow_set : & BorrowSet < ' tcx > ,
210
231
) {
211
232
let tcx = infcx. tcx ;
@@ -229,7 +250,7 @@ pub(super) fn dump_nll_mir<'tcx>(
229
250
& 0 ,
230
251
body,
231
252
|pass_where, out| {
232
- emit_nll_mir ( tcx, regioncx, closure_region_requirements , borrow_set, pass_where, out)
253
+ emit_nll_mir ( tcx, regioncx, closure_requirements , borrow_set, pass_where, out)
233
254
} ,
234
255
options,
235
256
) ;
@@ -251,7 +272,7 @@ pub(super) fn dump_nll_mir<'tcx>(
251
272
pub ( crate ) fn emit_nll_mir < ' tcx > (
252
273
tcx : TyCtxt < ' tcx > ,
253
274
regioncx : & RegionInferenceContext < ' tcx > ,
254
- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
275
+ closure_requirements : & Option < ClosureRequirements < ' tcx > > ,
255
276
borrow_set : & BorrowSet < ' tcx > ,
256
277
pass_where : PassWhere ,
257
278
out : & mut dyn io:: Write ,
@@ -262,9 +283,9 @@ pub(crate) fn emit_nll_mir<'tcx>(
262
283
regioncx. dump_mir ( tcx, out) ?;
263
284
writeln ! ( out, "|" ) ?;
264
285
265
- if let Some ( closure_region_requirements ) = closure_region_requirements {
286
+ if let Some ( closure_requirements ) = closure_requirements {
266
287
writeln ! ( out, "| Free Region Constraints" ) ?;
267
- for_each_region_constraint ( tcx, closure_region_requirements , & mut |msg| {
288
+ for_each_region_constraint ( tcx, closure_requirements , & mut |msg| {
268
289
writeln ! ( out, "| {msg}" )
269
290
} ) ?;
270
291
writeln ! ( out, "|" ) ?;
@@ -298,7 +319,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
298
319
infcx : & ' infcx BorrowckInferCtxt < ' tcx > ,
299
320
body : & Body < ' tcx > ,
300
321
regioncx : & RegionInferenceContext < ' tcx > ,
301
- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
322
+ closure_requirements : & Option < ClosureRequirements < ' tcx > > ,
302
323
opaque_type_values : & FxIndexMap < LocalDefId , OpaqueHiddenType < ' tcx > > ,
303
324
diagnostics_buffer : & mut BorrowckDiagnosticsBuffer < ' infcx , ' tcx > ,
304
325
) {
@@ -316,19 +337,16 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
316
337
// better.
317
338
318
339
let def_span = tcx. def_span ( body. source . def_id ( ) ) ;
319
- let mut err = if let Some ( closure_region_requirements ) = closure_region_requirements {
340
+ let mut err = if let Some ( closure_requirements ) = closure_requirements {
320
341
let mut err = infcx. dcx ( ) . struct_span_note ( def_span, "external requirements" ) ;
321
342
322
343
regioncx. annotate ( tcx, & mut err) ;
323
344
324
- err. note ( format ! (
325
- "number of external vids: {}" ,
326
- closure_region_requirements. num_external_vids
327
- ) ) ;
345
+ err. note ( format ! ( "number of external vids: {}" , closure_requirements. num_external_vids) ) ;
328
346
329
347
// Dump the region constraints we are imposing *between* those
330
348
// newly created variables.
331
- for_each_region_constraint ( tcx, closure_region_requirements , & mut |msg| {
349
+ for_each_region_constraint ( tcx, closure_requirements , & mut |msg| {
332
350
err. note ( msg) ;
333
351
Ok ( ( ) )
334
352
} )
@@ -351,20 +369,26 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
351
369
352
370
fn for_each_region_constraint < ' tcx > (
353
371
tcx : TyCtxt < ' tcx > ,
354
- closure_region_requirements : & ClosureRegionRequirements < ' tcx > ,
372
+ closure_requirements : & ClosureRequirements < ' tcx > ,
355
373
with_msg : & mut dyn FnMut ( String ) -> io:: Result < ( ) > ,
356
374
) -> io:: Result < ( ) > {
357
- for req in & closure_region_requirements. outlives_requirements {
358
- let subject = match req. subject {
359
- ClosureOutlivesSubject :: Region ( subject) => format ! ( "{subject:?}" ) ,
360
- ClosureOutlivesSubject :: Ty ( ty) => {
361
- with_no_trimmed_paths ! ( format!(
362
- "{}" ,
363
- ty. instantiate( tcx, |vid| ty:: Region :: new_var( tcx, vid) )
364
- ) )
365
- }
366
- } ;
367
- with_msg ( format ! ( "where {}: {:?}" , subject, req. outlived_free_region, ) ) ?;
375
+ for req in & closure_requirements. outlives_requirements {
376
+ let subject = with_no_trimmed_paths ! ( format!(
377
+ "{:?}" ,
378
+ req. subject. instantiate( tcx, |vid| ty:: Region :: new_var( tcx, vid) )
379
+ ) ) ;
380
+ // TODO
381
+ with_msg ( format ! (
382
+ "where {}: {:?}" ,
383
+ subject,
384
+ req. outlived_free_region. instantiate( tcx, |vid| ty:: Region :: new_var( tcx, vid) )
385
+ ) ) ?;
386
+ }
387
+
388
+ for data in & closure_requirements. opaque_types {
389
+ // TODO
390
+ let ( key, hidden_ty) = data. instantiate ( tcx, |vid| ty:: Region :: new_var ( tcx, vid) ) ;
391
+ with_msg ( format ! ( "where {key:?} = {hidden_ty:?}" ) ) ?;
368
392
}
369
393
Ok ( ( ) )
370
394
}
0 commit comments