Make MIR typeck use LocalDefId
and fix docs
This commit is contained in:
parent
9912925c25
commit
a32463ade4
@ -209,7 +209,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
|||||||
nll_errors,
|
nll_errors,
|
||||||
} = nll::compute_regions(
|
} = nll::compute_regions(
|
||||||
infcx,
|
infcx,
|
||||||
def_id.to_def_id(),
|
def_id,
|
||||||
free_regions,
|
free_regions,
|
||||||
body,
|
body,
|
||||||
&promoted,
|
&promoted,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::Diagnostic;
|
use rustc_errors::Diagnostic;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
@ -157,7 +157,7 @@ fn populate_polonius_move_facts(
|
|||||||
/// This may result in errors being reported.
|
/// This may result in errors being reported.
|
||||||
pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
|
pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
|
||||||
infcx: &InferCtxt<'cx, 'tcx>,
|
infcx: &InferCtxt<'cx, 'tcx>,
|
||||||
def_id: DefId,
|
def_id: LocalDefId,
|
||||||
universal_regions: UniversalRegions<'tcx>,
|
universal_regions: UniversalRegions<'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
promoted: &IndexVec<Promoted, Body<'tcx>>,
|
promoted: &IndexVec<Promoted, Body<'tcx>>,
|
||||||
@ -272,7 +272,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
|
|||||||
// Dump facts if requested.
|
// Dump facts if requested.
|
||||||
let polonius_output = all_facts.and_then(|all_facts| {
|
let polonius_output = all_facts.and_then(|all_facts| {
|
||||||
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
|
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
|
||||||
let def_path = infcx.tcx.def_path(def_id);
|
let def_path = infcx.tcx.def_path(def_id.to_def_id());
|
||||||
let dir_path =
|
let dir_path =
|
||||||
PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
|
PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
|
||||||
all_facts.write_to_dir(dir_path, location_table).unwrap();
|
all_facts.write_to_dir(dir_path, location_table).unwrap();
|
||||||
@ -292,7 +292,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
|
|||||||
|
|
||||||
// Solve the region constraints.
|
// Solve the region constraints.
|
||||||
let (closure_region_requirements, nll_errors) =
|
let (closure_region_requirements, nll_errors) =
|
||||||
regioncx.solve(infcx, &body, def_id, polonius_output.clone());
|
regioncx.solve(infcx, &body, def_id.to_def_id(), polonius_output.clone());
|
||||||
|
|
||||||
if !nll_errors.is_empty() {
|
if !nll_errors.is_empty() {
|
||||||
// Suppress unhelpful extra errors in `infer_opaque_types`.
|
// Suppress unhelpful extra errors in `infer_opaque_types`.
|
||||||
|
@ -33,35 +33,37 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
//
|
//
|
||||||
// e.g., `|x: FxHashMap<_, &'static u32>| ...`
|
// e.g., `|x: FxHashMap<_, &'static u32>| ...`
|
||||||
let user_provided_sig;
|
let user_provided_sig;
|
||||||
if !self.tcx().is_closure(self.mir_def_id) {
|
if !self.tcx().is_closure(self.mir_def_id.to_def_id()) {
|
||||||
user_provided_sig = None;
|
user_provided_sig = None;
|
||||||
} else {
|
} else {
|
||||||
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id.expect_local());
|
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id);
|
||||||
user_provided_sig = match typeck_tables.user_provided_sigs.get(&self.mir_def_id) {
|
user_provided_sig =
|
||||||
None => None,
|
match typeck_tables.user_provided_sigs.get(&self.mir_def_id.to_def_id()) {
|
||||||
Some(user_provided_poly_sig) => {
|
None => None,
|
||||||
// Instantiate the canonicalized variables from
|
Some(user_provided_poly_sig) => {
|
||||||
// user-provided signature (e.g., the `_` in the code
|
// Instantiate the canonicalized variables from
|
||||||
// above) with fresh variables.
|
// user-provided signature (e.g., the `_` in the code
|
||||||
let (poly_sig, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars(
|
// above) with fresh variables.
|
||||||
body.span,
|
let (poly_sig, _) =
|
||||||
&user_provided_poly_sig,
|
self.infcx.instantiate_canonical_with_fresh_inference_vars(
|
||||||
);
|
|
||||||
|
|
||||||
// Replace the bound items in the fn sig with fresh
|
|
||||||
// variables, so that they represent the view from
|
|
||||||
// "inside" the closure.
|
|
||||||
Some(
|
|
||||||
self.infcx
|
|
||||||
.replace_bound_vars_with_fresh_vars(
|
|
||||||
body.span,
|
body.span,
|
||||||
LateBoundRegionConversionTime::FnCall,
|
&user_provided_poly_sig,
|
||||||
&poly_sig,
|
);
|
||||||
)
|
|
||||||
.0,
|
// Replace the bound items in the fn sig with fresh
|
||||||
)
|
// variables, so that they represent the view from
|
||||||
|
// "inside" the closure.
|
||||||
|
Some(
|
||||||
|
self.infcx
|
||||||
|
.replace_bound_vars_with_fresh_vars(
|
||||||
|
body.span,
|
||||||
|
LateBoundRegionConversionTime::FnCall,
|
||||||
|
&poly_sig,
|
||||||
|
)
|
||||||
|
.0,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
@ -120,7 +122,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
if let Err(terr) = self.eq_opaque_type_and_type(
|
if let Err(terr) = self.eq_opaque_type_and_type(
|
||||||
mir_output_ty,
|
mir_output_ty,
|
||||||
normalized_output_ty,
|
normalized_output_ty,
|
||||||
self.mir_def_id,
|
self.mir_def_id.to_def_id(),
|
||||||
Locations::All(output_span),
|
Locations::All(output_span),
|
||||||
ConstraintCategory::BoringNoLocation,
|
ConstraintCategory::BoringNoLocation,
|
||||||
) {
|
) {
|
||||||
@ -143,7 +145,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
if let Err(err) = self.eq_opaque_type_and_type(
|
if let Err(err) = self.eq_opaque_type_and_type(
|
||||||
mir_output_ty,
|
mir_output_ty,
|
||||||
user_provided_output_ty,
|
user_provided_output_ty,
|
||||||
self.mir_def_id,
|
self.mir_def_id.to_def_id(),
|
||||||
Locations::All(output_span),
|
Locations::All(output_span),
|
||||||
ConstraintCategory::BoringNoLocation,
|
ConstraintCategory::BoringNoLocation,
|
||||||
) {
|
) {
|
||||||
|
@ -108,26 +108,22 @@ mod relate_tys;
|
|||||||
///
|
///
|
||||||
/// - `infcx` -- inference context to use
|
/// - `infcx` -- inference context to use
|
||||||
/// - `param_env` -- parameter environment to use for trait solving
|
/// - `param_env` -- parameter environment to use for trait solving
|
||||||
/// - `mir` -- MIR to type-check
|
/// - `body` -- MIR body to type-check
|
||||||
/// - `mir_def_id` -- DefId from which the MIR is derived (must be local)
|
/// - `promoted` -- map of promoted constants within `body`
|
||||||
/// - `region_bound_pairs` -- the implied outlives obligations between type parameters
|
/// - `mir_def_id` -- `LocalDefId` from which the MIR is derived
|
||||||
/// and lifetimes (e.g., `&'a T` implies `T: 'a`)
|
/// - `universal_regions` -- the universal regions from `body`s function signature
|
||||||
/// - `implicit_region_bound` -- a region which all generic parameters are assumed
|
/// - `location_table` -- MIR location map of `body`
|
||||||
/// to outlive; should represent the fn body
|
/// - `borrow_set` -- information about borrows occurring in `body`
|
||||||
/// - `input_tys` -- fully liberated, but **not** normalized, expected types of the arguments;
|
/// - `all_facts` -- when using Polonius, this is the generated set of Polonius facts
|
||||||
/// the types of the input parameters found in the MIR itself will be equated with these
|
|
||||||
/// - `output_ty` -- fully liberated, but **not** normalized, expected return type;
|
|
||||||
/// the type for the RETURN_PLACE will be equated with this
|
|
||||||
/// - `liveness` -- results of a liveness computation on the MIR; used to create liveness
|
|
||||||
/// constraints for the regions in the types of variables
|
|
||||||
/// - `flow_inits` -- results of a maybe-init dataflow analysis
|
/// - `flow_inits` -- results of a maybe-init dataflow analysis
|
||||||
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
|
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
|
||||||
|
/// - `elements` -- MIR region map
|
||||||
pub(crate) fn type_check<'mir, 'tcx>(
|
pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
infcx: &InferCtxt<'_, 'tcx>,
|
infcx: &InferCtxt<'_, 'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
promoted: &IndexVec<Promoted, Body<'tcx>>,
|
promoted: &IndexVec<Promoted, Body<'tcx>>,
|
||||||
mir_def_id: DefId,
|
mir_def_id: LocalDefId,
|
||||||
universal_regions: &Rc<UniversalRegions<'tcx>>,
|
universal_regions: &Rc<UniversalRegions<'tcx>>,
|
||||||
location_table: &LocationTable,
|
location_table: &LocationTable,
|
||||||
borrow_set: &BorrowSet<'tcx>,
|
borrow_set: &BorrowSet<'tcx>,
|
||||||
@ -191,7 +187,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
|||||||
|
|
||||||
fn type_check_internal<'a, 'tcx, R>(
|
fn type_check_internal<'a, 'tcx, R>(
|
||||||
infcx: &'a InferCtxt<'a, 'tcx>,
|
infcx: &'a InferCtxt<'a, 'tcx>,
|
||||||
mir_def_id: DefId,
|
mir_def_id: LocalDefId,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
body: &'a Body<'tcx>,
|
body: &'a Body<'tcx>,
|
||||||
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
|
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
|
||||||
@ -271,7 +267,7 @@ struct TypeVerifier<'a, 'b, 'tcx> {
|
|||||||
body: &'b Body<'tcx>,
|
body: &'b Body<'tcx>,
|
||||||
promoted: &'b IndexVec<Promoted, Body<'tcx>>,
|
promoted: &'b IndexVec<Promoted, Body<'tcx>>,
|
||||||
last_span: Span,
|
last_span: Span,
|
||||||
mir_def_id: DefId,
|
mir_def_id: LocalDefId,
|
||||||
errors_reported: bool,
|
errors_reported: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -815,7 +811,7 @@ struct TypeChecker<'a, 'tcx> {
|
|||||||
/// User type annotations are shared between the main MIR and the MIR of
|
/// User type annotations are shared between the main MIR and the MIR of
|
||||||
/// all of the promoted items.
|
/// all of the promoted items.
|
||||||
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
|
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
|
||||||
mir_def_id: DefId,
|
mir_def_id: LocalDefId,
|
||||||
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
|
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
|
||||||
implicit_region_bound: ty::Region<'tcx>,
|
implicit_region_bound: ty::Region<'tcx>,
|
||||||
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
|
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
|
||||||
@ -963,7 +959,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
fn new(
|
fn new(
|
||||||
infcx: &'a InferCtxt<'a, 'tcx>,
|
infcx: &'a InferCtxt<'a, 'tcx>,
|
||||||
body: &'a Body<'tcx>,
|
body: &'a Body<'tcx>,
|
||||||
mir_def_id: DefId,
|
mir_def_id: LocalDefId,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
|
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
|
||||||
implicit_region_bound: ty::Region<'tcx>,
|
implicit_region_bound: ty::Region<'tcx>,
|
||||||
@ -1142,7 +1138,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
// When you have `let x: impl Foo = ...` in a closure,
|
// When you have `let x: impl Foo = ...` in a closure,
|
||||||
// the resulting inferend values are stored with the
|
// the resulting inferend values are stored with the
|
||||||
// def-id of the base function.
|
// def-id of the base function.
|
||||||
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id);
|
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id.to_def_id());
|
||||||
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
|
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
|
||||||
} else {
|
} else {
|
||||||
return Err(terr);
|
return Err(terr);
|
||||||
@ -1994,7 +1990,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
|
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
|
||||||
let ccx = ConstCx::new_with_param_env(
|
let ccx = ConstCx::new_with_param_env(
|
||||||
tcx,
|
tcx,
|
||||||
self.mir_def_id.expect_local(),
|
self.mir_def_id,
|
||||||
body,
|
body,
|
||||||
self.param_env,
|
self.param_env,
|
||||||
);
|
);
|
||||||
@ -2010,9 +2006,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
&traits::Obligation::new(
|
&traits::Obligation::new(
|
||||||
ObligationCause::new(
|
ObligationCause::new(
|
||||||
span,
|
span,
|
||||||
self.tcx()
|
self.tcx().hir().local_def_id_to_hir_id(self.mir_def_id),
|
||||||
.hir()
|
|
||||||
.local_def_id_to_hir_id(self.mir_def_id.expect_local()),
|
|
||||||
traits::ObligationCauseCode::RepeatVec(should_suggest),
|
traits::ObligationCauseCode::RepeatVec(should_suggest),
|
||||||
),
|
),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user