diff options
Diffstat (limited to 'compiler/rustc_borrowck/src/nll.rs')
-rw-r--r-- | compiler/rustc_borrowck/src/nll.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index 59a3ab318..889acb3ac 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -4,11 +4,11 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::LocalDefId; -use rustc_index::vec::IndexSlice; +use rustc_index::IndexSlice; use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere}; use rustc_middle::mir::{ - BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, - Promoted, + Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted, + START_BLOCK, }; use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt}; use rustc_span::symbol::sym; @@ -27,6 +27,7 @@ use rustc_mir_dataflow::ResultsCursor; use crate::{ borrow_set::BorrowSet, constraint_generation, + consumers::ConsumerOptions, diagnostics::RegionErrors, facts::{AllFacts, AllFactsExt, RustcFacts}, invalidation, @@ -61,7 +62,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>( body: &mut Body<'tcx>, promoted: &mut IndexSlice<Promoted, Body<'tcx>>, ) -> UniversalRegions<'tcx> { - let def = body.source.with_opt_param().as_local().unwrap(); + let def = body.source.def_id().expect_local(); debug!(?def); @@ -94,8 +95,8 @@ fn populate_polonius_move_facts( } } - let fn_entry_start = location_table - .start_index(Location { block: BasicBlock::from_u32(0u32), statement_index: 0 }); + let fn_entry_start = + location_table.start_index(Location { block: START_BLOCK, statement_index: 0 }); // initialized_at for init in move_data.inits.iter() { @@ -165,10 +166,14 @@ pub(crate) fn compute_regions<'cx, 'tcx>( move_data: &MoveData<'tcx>, borrow_set: &BorrowSet<'tcx>, upvars: &[Upvar<'tcx>], - use_polonius: bool, + consumer_options: Option<ConsumerOptions>, ) -> NllOutput<'tcx> { + let polonius_input = consumer_options.map(|c| c.polonius_input()).unwrap_or_default() + || infcx.tcx.sess.opts.unstable_opts.polonius; + let polonius_output = consumer_options.map(|c| c.polonius_output()).unwrap_or_default() + || infcx.tcx.sess.opts.unstable_opts.polonius; let mut all_facts = - (use_polonius || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default()); + (polonius_input || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default()); let universal_regions = Rc::new(universal_regions); @@ -189,7 +194,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>( move_data, elements, upvars, - use_polonius, + polonius_input, ); if let Some(all_facts) = &mut all_facts { @@ -235,7 +240,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>( // Create the region inference context, taking ownership of the // region inference data that was contained in `infcx`, and the // base constraints generated by the type-check. - let var_origins = infcx.take_region_var_origins(); + let var_origins = infcx.get_region_var_origins(); let MirTypeckRegionConstraints { placeholder_indices, placeholder_index_to_region: _, @@ -284,7 +289,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>( all_facts.write_to_dir(dir_path, location_table).unwrap(); } - if use_polonius { + if polonius_output { let algorithm = env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid")); let algorithm = Algorithm::from_str(&algorithm).unwrap(); @@ -399,7 +404,7 @@ pub(super) fn dump_annotation<'tcx>( regioncx.annotate(tcx, &mut err); - err.note(&format!( + err.note(format!( "number of external vids: {}", closure_region_requirements.num_external_vids )); @@ -421,7 +426,7 @@ pub(super) fn dump_annotation<'tcx>( }; if !opaque_type_values.is_empty() { - err.note(&format!("Inferred opaque type values:\n{:#?}", opaque_type_values)); + err.note(format!("Inferred opaque type values:\n{:#?}", opaque_type_values)); } errors.buffer_non_error_diag(err); @@ -430,7 +435,7 @@ pub(super) fn dump_annotation<'tcx>( fn for_each_region_constraint<'tcx>( tcx: TyCtxt<'tcx>, closure_region_requirements: &ClosureRegionRequirements<'tcx>, - with_msg: &mut dyn FnMut(&str) -> io::Result<()>, + with_msg: &mut dyn FnMut(String) -> io::Result<()>, ) -> io::Result<()> { for req in &closure_region_requirements.outlives_requirements { let subject = match req.subject { @@ -439,7 +444,7 @@ fn for_each_region_constraint<'tcx>( format!("{:?}", ty.instantiate(tcx, |vid| tcx.mk_re_var(vid))) } }; - with_msg(&format!("where {}: {:?}", subject, req.outlived_free_region,))?; + with_msg(format!("where {}: {:?}", subject, req.outlived_free_region,))?; } Ok(()) } |