diff options
Diffstat (limited to 'compiler/rustc_borrowck/src/nll.rs')
-rw-r--r-- | compiler/rustc_borrowck/src/nll.rs | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index b2d92d0db..96228338a 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -5,16 +5,14 @@ use rustc_data_structures::vec_map::VecMap; use rustc_hir::def_id::LocalDefId; use rustc_index::vec::IndexVec; -use rustc_infer::infer::InferCtxt; use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere}; use rustc_middle::mir::{ BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted, }; -use rustc_middle::ty::{self, OpaqueHiddenType, Region, RegionVid}; +use rustc_middle::ty::{self, OpaqueHiddenType, Region, RegionVid, TyCtxt}; use rustc_span::symbol::sym; use std::env; -use std::fmt::Debug; use std::io; use std::path::PathBuf; use std::rc::Rc; @@ -37,7 +35,7 @@ use crate::{ renumber, type_check::{self, MirTypeckRegionConstraints, MirTypeckResults}, universal_regions::UniversalRegions, - Upvar, + BorrowckInferCtxt, Upvar, }; pub type PoloniusOutput = Output<RustcFacts>; @@ -58,7 +56,7 @@ pub(crate) struct NllOutput<'tcx> { /// `compute_regions`. #[instrument(skip(infcx, param_env, body, promoted), level = "debug")] pub(crate) fn replace_regions_in_mir<'tcx>( - infcx: &InferCtxt<'tcx>, + infcx: &BorrowckInferCtxt<'_, 'tcx>, param_env: ty::ParamEnv<'tcx>, body: &mut Body<'tcx>, promoted: &mut IndexVec<Promoted, Body<'tcx>>, @@ -157,7 +155,7 @@ fn populate_polonius_move_facts( /// /// This may result in errors being reported. pub(crate) fn compute_regions<'cx, 'tcx>( - infcx: &InferCtxt<'tcx>, + infcx: &BorrowckInferCtxt<'_, 'tcx>, universal_regions: UniversalRegions<'tcx>, body: &Body<'tcx>, promoted: &IndexVec<Promoted, Body<'tcx>>, @@ -259,6 +257,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>( ); let mut regioncx = RegionInferenceContext::new( + infcx, var_origins, universal_regions, placeholder_indices, @@ -322,10 +321,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>( } pub(super) fn dump_mir_results<'tcx>( - infcx: &InferCtxt<'tcx>, + infcx: &BorrowckInferCtxt<'_, 'tcx>, body: &Body<'tcx>, regioncx: &RegionInferenceContext<'tcx>, - closure_region_requirements: &Option<ClosureRegionRequirements<'_>>, + closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>, ) { if !dump_enabled(infcx.tcx, "nll", body.source.def_id()) { return; @@ -340,9 +339,11 @@ pub(super) fn dump_mir_results<'tcx>( if let Some(closure_region_requirements) = closure_region_requirements { writeln!(out, "| Free Region Constraints")?; - for_each_region_constraint(closure_region_requirements, &mut |msg| { - writeln!(out, "| {}", msg) - })?; + for_each_region_constraint( + infcx.tcx, + closure_region_requirements, + &mut |msg| writeln!(out, "| {}", msg), + )?; writeln!(out, "|")?; } } @@ -369,11 +370,13 @@ pub(super) fn dump_mir_results<'tcx>( }; } +#[allow(rustc::diagnostic_outside_of_impl)] +#[allow(rustc::untranslatable_diagnostic)] pub(super) fn dump_annotation<'tcx>( - infcx: &InferCtxt<'tcx>, + infcx: &BorrowckInferCtxt<'_, 'tcx>, body: &Body<'tcx>, regioncx: &RegionInferenceContext<'tcx>, - closure_region_requirements: &Option<ClosureRegionRequirements<'_>>, + closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>, opaque_type_values: &VecMap<LocalDefId, OpaqueHiddenType<'tcx>>, errors: &mut crate::error::BorrowckErrors<'tcx>, ) { @@ -403,7 +406,7 @@ pub(super) fn dump_annotation<'tcx>( // Dump the region constraints we are imposing *between* those // newly created variables. - for_each_region_constraint(closure_region_requirements, &mut |msg| { + for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| { err.note(msg); Ok(()) }) @@ -424,16 +427,19 @@ pub(super) fn dump_annotation<'tcx>( errors.buffer_non_error_diag(err); } -fn for_each_region_constraint( - closure_region_requirements: &ClosureRegionRequirements<'_>, +fn for_each_region_constraint<'tcx>( + tcx: TyCtxt<'tcx>, + closure_region_requirements: &ClosureRegionRequirements<'tcx>, with_msg: &mut dyn FnMut(&str) -> io::Result<()>, ) -> io::Result<()> { for req in &closure_region_requirements.outlives_requirements { - let subject: &dyn Debug = match &req.subject { - ClosureOutlivesSubject::Region(subject) => subject, - ClosureOutlivesSubject::Ty(ty) => ty, + let subject = match req.subject { + ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject), + ClosureOutlivesSubject::Ty(ty) => { + 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(()) } |