@@ -11,8 +11,7 @@ use rustc_hir::def_id::LocalDefId;
1111use rustc_index:: IndexSlice ;
1212use rustc_middle:: mir:: pretty:: { PrettyPrintMirOptions , dump_mir_with_options} ;
1313use 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,
1615} ;
1716use rustc_middle:: ty:: print:: with_no_trimmed_paths;
1817use rustc_middle:: ty:: { self , OpaqueHiddenType , TyCtxt } ;
@@ -43,7 +42,7 @@ pub(crate) struct NllOutput<'tcx> {
4342 pub opaque_type_values : FxIndexMap < LocalDefId , OpaqueHiddenType < ' tcx > > ,
4443 pub polonius_input : Option < Box < PoloniusFacts > > ,
4544 pub polonius_output : Option < Box < PoloniusOutput > > ,
46- pub opt_closure_req : Option < ClosureRegionRequirements < ' tcx > > ,
45+ pub opt_closure_req : Option < ClosureRequirements < ' tcx > > ,
4746 pub nll_errors : RegionErrors < ' tcx > ,
4847
4948 /// When using `-Zpolonius=next`: the localized typeck and liveness constraints.
@@ -171,22 +170,44 @@ pub(crate) fn compute_regions<'a, 'tcx>(
171170 } ) ;
172171
173172 // Solve the region constraints.
174- let ( closure_region_requirements , nll_errors) =
173+ let ( closure_outlives_requirements , nll_errors) =
175174 regioncx. solve ( infcx, body, polonius_output. clone ( ) ) ;
176175
177176 if let Some ( guar) = nll_errors. has_errors ( ) {
178177 // Suppress unhelpful extra errors in `infer_opaque_types`.
179178 infcx. set_tainted_by_errors ( guar) ;
180179 }
181180
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+ } ;
183204
184205 NllOutput {
185206 regioncx,
186- opaque_type_values : remapped_opaque_tys ,
207+ opaque_type_values,
187208 polonius_input : polonius_facts. map ( Box :: new) ,
188209 polonius_output,
189- opt_closure_req : closure_region_requirements ,
210+ opt_closure_req,
190211 nll_errors,
191212 localized_outlives_constraints,
192213 }
@@ -205,7 +226,7 @@ pub(super) fn dump_nll_mir<'tcx>(
205226 infcx : & BorrowckInferCtxt < ' tcx > ,
206227 body : & Body < ' tcx > ,
207228 regioncx : & RegionInferenceContext < ' tcx > ,
208- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
229+ closure_requirements : & Option < ClosureRequirements < ' tcx > > ,
209230 borrow_set : & BorrowSet < ' tcx > ,
210231) {
211232 let tcx = infcx. tcx ;
@@ -229,7 +250,7 @@ pub(super) fn dump_nll_mir<'tcx>(
229250 & 0 ,
230251 body,
231252 |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)
233254 } ,
234255 options,
235256 ) ;
@@ -251,7 +272,7 @@ pub(super) fn dump_nll_mir<'tcx>(
251272pub ( crate ) fn emit_nll_mir < ' tcx > (
252273 tcx : TyCtxt < ' tcx > ,
253274 regioncx : & RegionInferenceContext < ' tcx > ,
254- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
275+ closure_requirements : & Option < ClosureRequirements < ' tcx > > ,
255276 borrow_set : & BorrowSet < ' tcx > ,
256277 pass_where : PassWhere ,
257278 out : & mut dyn io:: Write ,
@@ -262,9 +283,9 @@ pub(crate) fn emit_nll_mir<'tcx>(
262283 regioncx. dump_mir ( tcx, out) ?;
263284 writeln ! ( out, "|" ) ?;
264285
265- if let Some ( closure_region_requirements ) = closure_region_requirements {
286+ if let Some ( closure_requirements ) = closure_requirements {
266287 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| {
268289 writeln ! ( out, "| {msg}" )
269290 } ) ?;
270291 writeln ! ( out, "|" ) ?;
@@ -298,7 +319,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
298319 infcx : & ' infcx BorrowckInferCtxt < ' tcx > ,
299320 body : & Body < ' tcx > ,
300321 regioncx : & RegionInferenceContext < ' tcx > ,
301- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
322+ closure_requirements : & Option < ClosureRequirements < ' tcx > > ,
302323 opaque_type_values : & FxIndexMap < LocalDefId , OpaqueHiddenType < ' tcx > > ,
303324 diagnostics_buffer : & mut BorrowckDiagnosticsBuffer < ' infcx , ' tcx > ,
304325) {
@@ -316,19 +337,16 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
316337 // better.
317338
318339 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 {
320341 let mut err = infcx. dcx ( ) . struct_span_note ( def_span, "external requirements" ) ;
321342
322343 regioncx. annotate ( tcx, & mut err) ;
323344
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) ) ;
328346
329347 // Dump the region constraints we are imposing *between* those
330348 // newly created variables.
331- for_each_region_constraint ( tcx, closure_region_requirements , & mut |msg| {
349+ for_each_region_constraint ( tcx, closure_requirements , & mut |msg| {
332350 err. note ( msg) ;
333351 Ok ( ( ) )
334352 } )
@@ -351,20 +369,26 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
351369
352370fn for_each_region_constraint < ' tcx > (
353371 tcx : TyCtxt < ' tcx > ,
354- closure_region_requirements : & ClosureRegionRequirements < ' tcx > ,
372+ closure_requirements : & ClosureRequirements < ' tcx > ,
355373 with_msg : & mut dyn FnMut ( String ) -> io:: Result < ( ) > ,
356374) -> 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:?}" ) ) ?;
368392 }
369393 Ok ( ( ) )
370394}
0 commit comments