Auto merge of #77552 - ecstatic-morse:body-def-id, r=lcnr

Replace `(Body, DefId)` with `Body` where possible

Follow-up to #77430.

I `grep`-ed for parameter lists in which a `Body` appeared within a few lines of a `DefId`, so it's possible that I missed some cases, but this should be pretty complete. Most of these changes were mechanical, but there's a few places where I started calling things "caller" and "callee" when multiple `DefId`s were in-scope at once. Also, we should probably have a helper function on `Body` that returns a `LocalDefId`. I can do that in this PR or in a follow-up.
This commit is contained in:
bors 2020-10-05 09:26:32 +00:00
commit 62bfcfd8a3
34 changed files with 201 additions and 273 deletions

View File

@ -336,10 +336,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
};
if let ty::Param(param_ty) = ty.kind() {
let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id);
let generics = tcx.generics_of(self.mir_def_id());
let param = generics.type_param(&param_ty, tcx);
if let Some(generics) =
tcx.hir().get_generics(tcx.closure_base_def_id(self.mir_def_id.to_def_id()))
if let Some(generics) = tcx
.hir()
.get_generics(tcx.closure_base_def_id(self.mir_def_id().to_def_id()))
{
suggest_constraining_type_param(
tcx,
@ -1004,7 +1005,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
format!("`{}` would have to be valid for `{}`...", name, region_name),
);
let fn_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let fn_hir_id = self.mir_hir_id();
err.span_label(
drop_span,
format!(
@ -1019,7 +1020,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
match &self
.infcx
.tcx
.typeck(self.mir_def_id)
.typeck(self.mir_def_id())
.node_type(fn_hir_id)
.kind()
{
@ -1369,7 +1370,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> DiagnosticBuilder<'cx> {
let tcx = self.infcx.tcx;
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id.to_def_id());
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id().to_def_id());
let mut err =
borrowck_errors::borrowed_data_escapes_closure(tcx, escape_span, escapes_from);
@ -1708,15 +1709,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
// Define a fallback for when we can't match a closure.
let fallback = || {
let is_closure = self.infcx.tcx.is_closure(self.mir_def_id.to_def_id());
let is_closure = self.infcx.tcx.is_closure(self.mir_def_id().to_def_id());
if is_closure {
None
} else {
let ty = self.infcx.tcx.type_of(self.mir_def_id);
let ty = self.infcx.tcx.type_of(self.mir_def_id());
match ty.kind() {
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
self.mir_def_id.to_def_id(),
self.infcx.tcx.fn_sig(self.mir_def_id),
self.mir_def_id().to_def_id(),
self.infcx.tcx.fn_sig(self.mir_def_id()),
),
_ => None,
}

View File

@ -331,7 +331,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
self.cannot_move_out_of_interior_noncopy(span, ty, None)
}
ty::Closure(def_id, closure_substs)
if def_id.as_local() == Some(self.mir_def_id) && upvar_field.is_some() =>
if def_id.as_local() == Some(self.mir_def_id()) && upvar_field.is_some() =>
{
let closure_kind_ty = closure_substs.as_closure().kind_ty();
let closure_kind = closure_kind_ty.to_opt_closure_kind();

View File

@ -492,7 +492,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_label(sp, format!("cannot {}", act));
let hir = self.infcx.tcx.hir();
let closure_id = hir.local_def_id_to_hir_id(self.mir_def_id);
let closure_id = self.mir_hir_id();
let fn_call_id = hir.get_parent_node(closure_id);
let node = hir.get(fn_call_id);
let item_id = hir.enclosing_body_owner(fn_call_id);

View File

@ -515,7 +515,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut diag =
self.infcx.tcx.sess.struct_span_err(*span, "lifetime may not live long enough");
let (_, mir_def_name) = self.infcx.tcx.article_and_description(self.mir_def_id.to_def_id());
let (_, mir_def_name) =
self.infcx.tcx.article_and_description(self.mir_def_id().to_def_id());
let fr_name = self.give_region_a_name(*fr).unwrap();
fr_name.highlight_region_name(&mut diag);

View File

@ -147,6 +147,14 @@ impl Display for RegionName {
}
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
crate fn mir_def_id(&self) -> hir::def_id::LocalDefId {
self.body.source.def_id().as_local().unwrap()
}
crate fn mir_hir_id(&self) -> hir::HirId {
self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id())
}
/// Generate a synthetic region named `'N`, where `N` is the next value of the counter. Then,
/// increment the counter.
///
@ -266,12 +274,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
}
ty::BoundRegion::BrEnv => {
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let def_ty = self.regioncx.universal_regions().defining_ty;
if let DefiningTy::Closure(_, substs) = def_ty {
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
tcx.hir().expect_expr(mir_hir_id).kind
tcx.hir().expect_expr(self.mir_hir_id()).kind
{
span
} else {
@ -361,8 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
&self,
argument_index: usize,
) -> Option<&hir::Ty<'tcx>> {
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(self.mir_hir_id())?;
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
match argument_hir_ty.kind {
// This indicates a variable with no type annotation, like
@ -649,9 +655,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
let type_name =
self.infcx.extract_inference_diagnostics_data(return_ty.into(), Some(highlight)).name;
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) {
let (return_span, mir_description) = match tcx.hir().get(self.mir_hir_id()) {
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
..
@ -702,9 +706,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
let type_name =
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let yield_span = match tcx.hir().get(mir_hir_id) {
let yield_span = match tcx.hir().get(self.mir_hir_id()) {
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_, _, _, span, _), ..
}) => (tcx.sess.source_map().end_point(*span)),

View File

@ -111,7 +111,7 @@ fn mir_borrowck<'tcx>(
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
let input_body: &Body<'_> = &input_body.borrow();
let promoted: &IndexVec<_, _> = &promoted.borrow();
do_mir_borrowck(&infcx, input_body, promoted, def)
do_mir_borrowck(&infcx, input_body, promoted)
});
debug!("mir_borrowck done");
@ -122,8 +122,9 @@ fn do_mir_borrowck<'a, 'tcx>(
infcx: &InferCtxt<'a, 'tcx>,
input_body: &Body<'tcx>,
input_promoted: &IndexVec<Promoted, Body<'tcx>>,
def: ty::WithOptConstParam<LocalDefId>,
) -> BorrowCheckResult<'tcx> {
let def = input_body.source.with_opt_param().as_local().unwrap();
debug!("do_mir_borrowck(def = {:?})", def);
let tcx = infcx.tcx;
@ -185,7 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>(
// will have a lifetime tied to the inference context.
let mut body = input_body.clone();
let mut promoted = input_promoted.clone();
let free_regions = nll::replace_regions_in_mir(infcx, def, param_env, &mut body, &mut promoted);
let free_regions = nll::replace_regions_in_mir(infcx, param_env, &mut body, &mut promoted);
let body = &body; // no further changes
let location_table = &LocationTable::new(&body);
@ -203,7 +204,7 @@ fn do_mir_borrowck<'a, 'tcx>(
let mdpe = MoveDataParamEnv { move_data, param_env };
let mut flow_inits = MaybeInitializedPlaces::new(tcx, &body, &mdpe)
.into_engine(tcx, &body, def.did.to_def_id())
.into_engine(tcx, &body)
.pass_name("borrowck")
.iterate_to_fixpoint()
.into_results_cursor(&body);
@ -221,7 +222,6 @@ fn do_mir_borrowck<'a, 'tcx>(
nll_errors,
} = nll::compute_regions(
infcx,
def.did,
free_regions,
body,
&promoted,
@ -242,7 +242,6 @@ fn do_mir_borrowck<'a, 'tcx>(
nll::dump_annotation(
infcx,
&body,
def.did.to_def_id(),
&regioncx,
&opt_closure_req,
&opaque_type_values,
@ -257,15 +256,15 @@ fn do_mir_borrowck<'a, 'tcx>(
let regioncx = Rc::new(regioncx);
let flow_borrows = Borrows::new(tcx, &body, regioncx.clone(), &borrow_set)
.into_engine(tcx, &body, def.did.to_def_id())
.into_engine(tcx, &body)
.pass_name("borrowck")
.iterate_to_fixpoint();
let flow_uninits = MaybeUninitializedPlaces::new(tcx, &body, &mdpe)
.into_engine(tcx, &body, def.did.to_def_id())
.into_engine(tcx, &body)
.pass_name("borrowck")
.iterate_to_fixpoint();
let flow_ever_inits = EverInitializedPlaces::new(tcx, &body, &mdpe)
.into_engine(tcx, &body, def.did.to_def_id())
.into_engine(tcx, &body)
.pass_name("borrowck")
.iterate_to_fixpoint();
@ -286,7 +285,6 @@ fn do_mir_borrowck<'a, 'tcx>(
infcx,
param_env,
body: promoted_body,
mir_def_id: def.did,
move_data: &move_data,
location_table: &LocationTable::new(promoted_body),
movable_generator,
@ -320,7 +318,6 @@ fn do_mir_borrowck<'a, 'tcx>(
infcx,
param_env,
body,
mir_def_id: def.did,
move_data: &mdpe.move_data,
location_table,
movable_generator,
@ -474,7 +471,6 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
crate infcx: &'cx InferCtxt<'cx, 'tcx>,
param_env: ParamEnv<'tcx>,
body: &'cx Body<'tcx>,
mir_def_id: LocalDefId,
move_data: &'cx MoveData<'tcx>,
/// Map from MIR `Location` to `LocationIndex`; created

View File

@ -2,7 +2,7 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::DefId;
use rustc_index::vec::IndexVec;
use rustc_infer::infer::InferCtxt;
use rustc_middle::mir::{
@ -58,11 +58,12 @@ crate struct NllOutput<'tcx> {
/// `compute_regions`.
pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>(
infcx: &InferCtxt<'cx, 'tcx>,
def: ty::WithOptConstParam<LocalDefId>,
param_env: ty::ParamEnv<'tcx>,
body: &mut Body<'tcx>,
promoted: &mut IndexVec<Promoted, Body<'tcx>>,
) -> UniversalRegions<'tcx> {
let def = body.source.with_opt_param().as_local().unwrap();
debug!("replace_regions_in_mir(def={:?})", def);
// Compute named region information. This also renumbers the inputs/outputs.
@ -156,7 +157,6 @@ fn populate_polonius_move_facts(
/// This may result in errors being reported.
pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
infcx: &InferCtxt<'cx, 'tcx>,
def_id: LocalDefId,
universal_regions: UniversalRegions<'tcx>,
body: &Body<'tcx>,
promoted: &IndexVec<Promoted, Body<'tcx>>,
@ -180,7 +180,6 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
param_env,
body,
promoted,
def_id,
&universal_regions,
location_table,
borrow_set,
@ -270,10 +269,12 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
// Generate various additional constraints.
invalidation::generate_invalidates(infcx.tcx, &mut all_facts, location_table, body, borrow_set);
let def_id = body.source.def_id();
// Dump facts if requested.
let polonius_output = all_facts.and_then(|all_facts| {
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
let def_path = infcx.tcx.def_path(def_id.to_def_id());
let def_path = infcx.tcx.def_path(def_id);
let dir_path =
PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
all_facts.write_to_dir(dir_path, location_table).unwrap();
@ -293,7 +294,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
// Solve the region constraints.
let (closure_region_requirements, nll_errors) =
regioncx.solve(infcx, &body, def_id.to_def_id(), polonius_output.clone());
regioncx.solve(infcx, &body, polonius_output.clone());
if !nll_errors.is_empty() {
// Suppress unhelpful extra errors in `infer_opaque_types`.
@ -364,14 +365,13 @@ pub(super) fn dump_mir_results<'a, 'tcx>(
pub(super) fn dump_annotation<'a, 'tcx>(
infcx: &InferCtxt<'a, 'tcx>,
body: &Body<'tcx>,
mir_def_id: DefId,
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
opaque_type_values: &FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
errors_buffer: &mut Vec<Diagnostic>,
) {
let tcx = infcx.tcx;
let base_def_id = tcx.closure_base_def_id(mir_def_id);
let base_def_id = tcx.closure_base_def_id(body.source.def_id());
if !tcx.has_attr(base_def_id, sym::rustc_regions) {
return;
}

View File

@ -548,9 +548,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&mut self,
infcx: &InferCtxt<'_, 'tcx>,
body: &Body<'tcx>,
mir_def_id: DefId,
polonius_output: Option<Rc<PoloniusOutput>>,
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
let mir_def_id = body.source.def_id();
self.propagate_constraints(body, infcx.tcx);
let mut errors_buffer = RegionErrors::new();

View File

@ -28,42 +28,43 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let (&normalized_output_ty, normalized_input_tys) =
normalized_inputs_and_output.split_last().unwrap();
let mir_def_id = body.source.def_id().expect_local();
// If the user explicitly annotated the input types, extract
// those.
//
// e.g., `|x: FxHashMap<_, &'static u32>| ...`
let user_provided_sig;
if !self.tcx().is_closure(self.mir_def_id.to_def_id()) {
if !self.tcx().is_closure(mir_def_id.to_def_id()) {
user_provided_sig = None;
} else {
let typeck_results = self.tcx().typeck(self.mir_def_id);
user_provided_sig =
match typeck_results.user_provided_sigs.get(&self.mir_def_id.to_def_id()) {
None => None,
Some(user_provided_poly_sig) => {
// Instantiate the canonicalized variables from
// user-provided signature (e.g., the `_` in the code
// above) with fresh variables.
let (poly_sig, _) =
self.infcx.instantiate_canonical_with_fresh_inference_vars(
body.span,
&user_provided_poly_sig,
);
let typeck_results = self.tcx().typeck(mir_def_id);
user_provided_sig = match typeck_results.user_provided_sigs.get(&mir_def_id.to_def_id())
{
None => None,
Some(user_provided_poly_sig) => {
// Instantiate the canonicalized variables from
// user-provided signature (e.g., the `_` in the code
// above) with fresh variables.
let (poly_sig, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars(
body.span,
&user_provided_poly_sig,
);
// 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,
)
}
// 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!(
@ -122,7 +123,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(terr) = self.eq_opaque_type_and_type(
mir_output_ty,
normalized_output_ty,
self.mir_def_id,
mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
@ -145,7 +146,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(err) = self.eq_opaque_type_and_type(
mir_output_ty,
user_provided_output_ty,
self.mir_def_id,
mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {

View File

@ -73,7 +73,7 @@ macro_rules! span_mirbug {
$context.last_span,
&format!(
"broken MIR in {:?} ({:?}): {}",
$context.mir_def_id,
$context.body.source.def_id(),
$elem,
format_args!($($message)*),
),
@ -113,7 +113,6 @@ mod relate_tys;
/// - `param_env` -- parameter environment to use for trait solving
/// - `body` -- MIR body to type-check
/// - `promoted` -- map of promoted constants within `body`
/// - `mir_def_id` -- `LocalDefId` from which the MIR is derived
/// - `universal_regions` -- the universal regions from `body`s function signature
/// - `location_table` -- MIR location map of `body`
/// - `borrow_set` -- information about borrows occurring in `body`
@ -126,7 +125,6 @@ pub(crate) fn type_check<'mir, 'tcx>(
param_env: ty::ParamEnv<'tcx>,
body: &Body<'tcx>,
promoted: &IndexVec<Promoted, Body<'tcx>>,
mir_def_id: LocalDefId,
universal_regions: &Rc<UniversalRegions<'tcx>>,
location_table: &LocationTable,
borrow_set: &BorrowSet<'tcx>,
@ -170,7 +168,6 @@ pub(crate) fn type_check<'mir, 'tcx>(
let opaque_type_values = type_check_internal(
infcx,
mir_def_id,
param_env,
body,
promoted,
@ -192,7 +189,6 @@ pub(crate) fn type_check<'mir, 'tcx>(
fn type_check_internal<'a, 'tcx, R>(
infcx: &'a InferCtxt<'a, 'tcx>,
mir_def_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>,
body: &'a Body<'tcx>,
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
@ -205,7 +201,6 @@ fn type_check_internal<'a, 'tcx, R>(
let mut checker = TypeChecker::new(
infcx,
body,
mir_def_id,
param_env,
region_bound_pairs,
implicit_region_bound,
@ -272,7 +267,6 @@ struct TypeVerifier<'a, 'b, 'tcx> {
body: &'b Body<'tcx>,
promoted: &'b IndexVec<Promoted, Body<'tcx>>,
last_span: Span,
mir_def_id: LocalDefId,
errors_reported: bool,
}
@ -460,14 +454,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
body: &'b Body<'tcx>,
promoted: &'b IndexVec<Promoted, Body<'tcx>>,
) -> Self {
TypeVerifier {
body,
promoted,
mir_def_id: cx.mir_def_id,
cx,
last_span: body.span,
errors_reported: false,
}
TypeVerifier { body, promoted, cx, last_span: body.span, errors_reported: false }
}
fn tcx(&self) -> TyCtxt<'tcx> {
@ -816,7 +803,6 @@ struct TypeChecker<'a, 'tcx> {
/// User type annotations are shared between the main MIR and the MIR of
/// all of the promoted items.
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
mir_def_id: LocalDefId,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
@ -965,7 +951,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
fn new(
infcx: &'a InferCtxt<'a, 'tcx>,
body: &'a Body<'tcx>,
mir_def_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
@ -975,7 +960,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let mut checker = Self {
infcx,
last_span: DUMMY_SP,
mir_def_id,
body,
user_type_annotations: &body.user_type_annotations,
param_env,
@ -1145,7 +1129,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// the resulting inferend values are stored with the
// def-id of the base function.
let parent_def_id =
self.tcx().closure_base_def_id(self.mir_def_id.to_def_id()).expect_local();
self.tcx().closure_base_def_id(self.body.source.def_id()).expect_local();
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
} else {
return Err(terr);
@ -1242,7 +1226,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let concrete_opaque_types = &tcx.typeck(anon_owner_def_id).concrete_opaque_types;
let mut opaque_type_values = Vec::new();
debug!("eq_opaque_type_and_type: mir_def_id={:?}", self.mir_def_id);
debug!("eq_opaque_type_and_type: mir_def_id={:?}", body.source.def_id());
let opaque_type_map = self.fully_perform_op(
locations,
category,
@ -2001,12 +1985,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let span = body.source_info(location).span;
let ty = operand.ty(body, tcx);
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
let ccx = ConstCx::new_with_param_env(
tcx,
self.mir_def_id,
body,
self.param_env,
);
let ccx = ConstCx::new_with_param_env(tcx, body, self.param_env);
// To determine if `const_in_array_repeat_expressions` feature gate should
// be mentioned, need to check if the rvalue is promotable.
let should_suggest =
@ -2015,11 +1994,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
debug!("check_rvalue: should_suggest={:?}", should_suggest);
let def_id = body.source.def_id().expect_local();
self.infcx.report_selection_error(
&traits::Obligation::new(
ObligationCause::new(
span,
self.tcx().hir().local_def_id_to_hir_id(self.mir_def_id),
self.tcx().hir().local_def_id_to_hir_id(def_id),
traits::ObligationCauseCode::RepeatVec(should_suggest),
),
self.param_env,

View File

@ -81,7 +81,6 @@ where
{
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
dead_unwinds: Option<&'a BitSet<BasicBlock>>,
entry_sets: IndexVec<BasicBlock, A::Domain>,
pass_name: Option<&'static str>,
@ -103,18 +102,13 @@ where
T: Idx,
{
/// Creates a new `Engine` to solve a gen-kill dataflow problem.
pub fn new_gen_kill(
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
analysis: A,
) -> Self {
pub fn new_gen_kill(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self {
// If there are no back-edges in the control-flow graph, we only ever need to apply the
// transfer function for each block exactly once (assuming that we process blocks in RPO).
//
// In this case, there's no need to compute the block transfer functions ahead of time.
if !body.is_cfg_cyclic() {
return Self::new(tcx, body, def_id, analysis, None);
return Self::new(tcx, body, analysis, None);
}
// Otherwise, compute and store the cumulative transfer function for each block.
@ -131,7 +125,7 @@ where
trans_for_block[bb].apply(state.borrow_mut());
});
Self::new(tcx, body, def_id, analysis, Some(apply_trans as Box<_>))
Self::new(tcx, body, analysis, Some(apply_trans as Box<_>))
}
}
@ -145,19 +139,13 @@ where
///
/// Gen-kill problems should use `new_gen_kill`, which will coalesce transfer functions for
/// better performance.
pub fn new_generic(
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
analysis: A,
) -> Self {
Self::new(tcx, body, def_id, analysis, None)
pub fn new_generic(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self {
Self::new(tcx, body, analysis, None)
}
fn new(
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
def_id: DefId,
analysis: A,
apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
) -> Self {
@ -173,7 +161,6 @@ where
analysis,
tcx,
body,
def_id,
dead_unwinds: None,
pass_name: None,
entry_sets,
@ -209,7 +196,6 @@ where
analysis,
body,
dead_unwinds,
def_id,
mut entry_sets,
tcx,
apply_trans_for_block,
@ -261,7 +247,7 @@ where
let results = Results { analysis, entry_sets };
let res = write_graphviz_results(tcx, def_id, &body, &results, pass_name);
let res = write_graphviz_results(tcx, &body, &results, pass_name);
if let Err(e) = res {
warn!("Failed to write graphviz dataflow results: {}", e);
}
@ -276,7 +262,6 @@ where
/// `rustc_mir` attributes.
fn write_graphviz_results<A>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
body: &mir::Body<'tcx>,
results: &Results<'tcx, A>,
pass_name: Option<&'static str>,
@ -285,6 +270,7 @@ where
A: Analysis<'tcx>,
A::Domain: DebugWithContext<A>,
{
let def_id = body.source.def_id();
let attrs = match RustcMirAttrs::parse(tcx, def_id) {
Ok(attrs) => attrs,
@ -323,7 +309,7 @@ where
debug!("printing dataflow results for {:?} to {}", def_id, path.display());
let mut buf = Vec::new();
let graphviz = graphviz::Formatter::new(body, def_id, results, style);
let graphviz = graphviz::Formatter::new(body, results, style);
let mut render_opts =
vec![dot::RenderOption::Fontname(tcx.sess.opts.debugging_opts.graphviz_font.clone())];
if tcx.sess.opts.debugging_opts.graphviz_dark_mode {

View File

@ -6,7 +6,6 @@ use std::{io, ops, str};
use regex::Regex;
use rustc_graphviz as dot;
use rustc_hir::def_id::DefId;
use rustc_middle::mir::{self, BasicBlock, Body, Location};
use super::fmt::{DebugDiffWithAdapter, DebugWithAdapter, DebugWithContext};
@ -33,7 +32,6 @@ where
A: Analysis<'tcx>,
{
body: &'a Body<'tcx>,
def_id: DefId,
results: &'a Results<'tcx, A>,
style: OutputStyle,
}
@ -42,13 +40,8 @@ impl<A> Formatter<'a, 'tcx, A>
where
A: Analysis<'tcx>,
{
pub fn new(
body: &'a Body<'tcx>,
def_id: DefId,
results: &'a Results<'tcx, A>,
style: OutputStyle,
) -> Self {
Formatter { body, def_id, results, style }
pub fn new(body: &'a Body<'tcx>, results: &'a Results<'tcx, A>, style: OutputStyle) -> Self {
Formatter { body, results, style }
}
}
@ -77,7 +70,7 @@ where
type Edge = CfgEdge;
fn graph_id(&self) -> dot::Id<'_> {
let name = graphviz_safe_def_name(self.def_id);
let name = graphviz_safe_def_name(self.body.source.def_id());
dot::Id::new(format!("graph_for_def_id_{}", name)).unwrap()
}

View File

@ -13,9 +13,9 @@
//! ```ignore(cross-crate-imports)
//! use rustc_mir::dataflow::Analysis; // Makes `into_engine` available.
//!
//! fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>, did: DefId) {
//! fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
//! let analysis = MyAnalysis::new()
//! .into_engine(tcx, body, did)
//! .into_engine(tcx, body)
//! .iterate_to_fixpoint()
//! .into_results_cursor(body);
//!
@ -33,7 +33,6 @@
use std::borrow::BorrowMut;
use std::cmp::Ordering;
use rustc_hir::def_id::DefId;
use rustc_index::bit_set::{BitSet, HybridBitSet};
use rustc_index::vec::Idx;
use rustc_middle::mir::{self, BasicBlock, Location};
@ -218,16 +217,11 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> {
/// .iterate_to_fixpoint()
/// .into_results_cursor(body);
/// ```
fn into_engine(
self,
tcx: TyCtxt<'tcx>,
body: &'mir mir::Body<'tcx>,
def_id: DefId,
) -> Engine<'mir, 'tcx, Self>
fn into_engine(self, tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Engine<'mir, 'tcx, Self>
where
Self: Sized,
{
Engine::new_generic(tcx, body, def_id, self)
Engine::new_generic(tcx, body, self)
}
}
@ -381,16 +375,11 @@ where
/* Extension methods */
fn into_engine(
self,
tcx: TyCtxt<'tcx>,
body: &'mir mir::Body<'tcx>,
def_id: DefId,
) -> Engine<'mir, 'tcx, Self>
fn into_engine(self, tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Engine<'mir, 'tcx, Self>
where
Self: Sized,
{
Engine::new_gen_kill(tcx, body, def_id, self)
Engine::new_gen_kill(tcx, body, self)
}
}

View File

@ -1,4 +1,3 @@
use rustc_hir::def_id::DefId;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
@ -42,20 +41,17 @@ pub struct AddMovesForPackedDrops;
impl<'tcx> MirPass<'tcx> for AddMovesForPackedDrops {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
debug!("add_moves_for_packed_drops({:?} @ {:?})", body.source, body.span);
add_moves_for_packed_drops(tcx, body, body.source.def_id());
add_moves_for_packed_drops(tcx, body);
}
}
pub fn add_moves_for_packed_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, def_id: DefId) {
let patch = add_moves_for_packed_drops_patch(tcx, body, def_id);
pub fn add_moves_for_packed_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let patch = add_moves_for_packed_drops_patch(tcx, body);
patch.apply(body);
}
fn add_moves_for_packed_drops_patch<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
def_id: DefId,
) -> MirPatch<'tcx> {
fn add_moves_for_packed_drops_patch<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> MirPatch<'tcx> {
let def_id = body.source.def_id();
let mut patch = MirPatch::new(body);
let param_env = tcx.param_env(def_id);

View File

@ -24,25 +24,28 @@ pub mod validation;
pub struct ConstCx<'mir, 'tcx> {
pub body: &'mir mir::Body<'tcx>,
pub tcx: TyCtxt<'tcx>,
pub def_id: LocalDefId,
pub param_env: ty::ParamEnv<'tcx>,
pub const_kind: Option<hir::ConstContext>,
}
impl ConstCx<'mir, 'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'mir mir::Body<'tcx>) -> Self {
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Self {
let def_id = body.source.def_id().expect_local();
let param_env = tcx.param_env(def_id);
Self::new_with_param_env(tcx, def_id, body, param_env)
Self::new_with_param_env(tcx, body, param_env)
}
pub fn new_with_param_env(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
body: &'mir mir::Body<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> Self {
let const_kind = tcx.hir().body_const_context(def_id);
ConstCx { body, tcx, def_id: def_id, param_env, const_kind }
let const_kind = tcx.hir().body_const_context(body.source.def_id().expect_local());
ConstCx { body, tcx, param_env, const_kind }
}
pub fn def_id(&self) -> LocalDefId {
self.body.source.def_id().expect_local()
}
/// Returns the kind of const context this `Item` represents (`const`, `static`, etc.).
@ -55,7 +58,7 @@ impl ConstCx<'mir, 'tcx> {
pub fn is_const_stable_const_fn(&self) -> bool {
self.const_kind == Some(hir::ConstContext::ConstFn)
&& self.tcx.features().staged_api
&& is_const_stable_const_fn(self.tcx, self.def_id.to_def_id())
&& is_const_stable_const_fn(self.tcx, self.def_id().to_def_id())
}
/// Returns the function signature of the item being const-checked if it is a `fn` or `const fn`.
@ -64,7 +67,7 @@ impl ConstCx<'mir, 'tcx> {
//
// FIXME: Is this still an issue?
let hir_map = self.tcx.hir();
let hir_id = hir_map.local_def_id_to_hir_id(self.def_id);
let hir_id = hir_map.local_def_id_to_hir_id(self.def_id());
hir_map.fn_sig_by_hir_id(hir_id)
}
}

View File

@ -1,4 +1,3 @@
use rustc_hir::def_id::LocalDefId;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{self, BasicBlock, Location};
use rustc_middle::ty::TyCtxt;
@ -24,13 +23,14 @@ pub fn checking_enabled(ccx: &ConstCx<'_, '_>) -> bool {
///
/// This is separate from the rest of the const checking logic because it must run after drop
/// elaboration.
pub fn check_live_drops(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &mir::Body<'tcx>) {
pub fn check_live_drops(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
let def_id = body.source.def_id().expect_local();
let const_kind = tcx.hir().body_const_context(def_id);
if const_kind.is_none() {
return;
}
let ccx = ConstCx { body, tcx, def_id, const_kind, param_env: tcx.param_env(def_id) };
let ccx = ConstCx { body, tcx, const_kind, param_env: tcx.param_env(def_id) };
if !checking_enabled(&ccx) {
return;
}

View File

@ -126,7 +126,7 @@ impl Qualif for CustomEq {
// because that component may be part of an enum variant (e.g.,
// `Option::<NonStructuralMatchTy>::Some`), in which case some values of this type may be
// structural-match (`Option::None`).
let id = cx.tcx.hir().local_def_id_to_hir_id(cx.def_id);
let id = cx.tcx.hir().local_def_id_to_hir_id(cx.def_id());
traits::search_for_structural_match_violation(id, cx.body.span, cx.tcx, ty).is_some()
}

View File

@ -50,7 +50,7 @@ impl Qualifs<'mir, 'tcx> {
location: Location,
) -> bool {
let indirectly_mutable = self.indirectly_mutable.get_or_insert_with(|| {
let ConstCx { tcx, body, def_id, param_env, .. } = *ccx;
let ConstCx { tcx, body, param_env, .. } = *ccx;
// We can use `unsound_ignore_borrow_on_drop` here because custom drop impls are not
// allowed in a const.
@ -59,7 +59,7 @@ impl Qualifs<'mir, 'tcx> {
// without breaking stable code?
MaybeMutBorrowedLocals::mut_borrows_only(tcx, &body, param_env)
.unsound_ignore_borrow_on_drop()
.into_engine(tcx, &body, def_id.to_def_id())
.into_engine(tcx, &body)
.pass_name("const_qualification")
.iterate_to_fixpoint()
.into_results_cursor(&body)
@ -84,10 +84,10 @@ impl Qualifs<'mir, 'tcx> {
}
let needs_drop = self.needs_drop.get_or_insert_with(|| {
let ConstCx { tcx, body, def_id, .. } = *ccx;
let ConstCx { tcx, body, .. } = *ccx;
FlowSensitiveAnalysis::new(NeedsDrop, ccx)
.into_engine(tcx, &body, def_id.to_def_id())
.into_engine(tcx, &body)
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
@ -111,10 +111,10 @@ impl Qualifs<'mir, 'tcx> {
}
let has_mut_interior = self.has_mut_interior.get_or_insert_with(|| {
let ConstCx { tcx, body, def_id, .. } = *ccx;
let ConstCx { tcx, body, .. } = *ccx;
FlowSensitiveAnalysis::new(HasMutInterior, ccx)
.into_engine(tcx, &body, def_id.to_def_id())
.into_engine(tcx, &body)
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
@ -157,7 +157,7 @@ impl Qualifs<'mir, 'tcx> {
hir::ConstContext::Const | hir::ConstContext::Static(_) => {
let mut cursor = FlowSensitiveAnalysis::new(CustomEq, ccx)
.into_engine(ccx.tcx, &ccx.body, ccx.def_id.to_def_id())
.into_engine(ccx.tcx, &ccx.body)
.iterate_to_fixpoint()
.into_results_cursor(&ccx.body);
@ -205,7 +205,8 @@ impl Validator<'mir, 'tcx> {
}
pub fn check_body(&mut self) {
let ConstCx { tcx, body, def_id, .. } = *self.ccx;
let ConstCx { tcx, body, .. } = *self.ccx;
let def_id = self.ccx.def_id();
// `async` functions cannot be `const fn`. This is checked during AST lowering, so there's
// no need to emit duplicate errors here.
@ -219,7 +220,7 @@ impl Validator<'mir, 'tcx> {
// Prevent const trait methods from being annotated as `stable`.
// FIXME: Do this as part of stability checking.
if self.is_const_stable_const_fn() {
let hir_id = tcx.hir().local_def_id_to_hir_id(self.def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
if crate::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
struct_span_err!(
self.ccx.tcx.sess,
@ -291,7 +292,7 @@ impl Validator<'mir, 'tcx> {
Status::Unstable(gate) if self.tcx.features().enabled(gate) => {
let unstable_in_stable = self.ccx.is_const_stable_const_fn()
&& !super::allow_internal_unstable(self.tcx, self.def_id.to_def_id(), gate);
&& !super::allow_internal_unstable(self.tcx, self.def_id().to_def_id(), gate);
if unstable_in_stable {
emit_unstable_in_stable_error(self.ccx, span, gate);
}
@ -367,9 +368,9 @@ impl Validator<'mir, 'tcx> {
}
fn check_item_predicates(&mut self) {
let ConstCx { tcx, def_id, .. } = *self.ccx;
let ConstCx { tcx, .. } = *self.ccx;
let mut current = def_id.to_def_id();
let mut current = self.def_id().to_def_id();
loop {
let predicates = tcx.predicates_of(current);
for (predicate, _) in predicates.predicates {
@ -736,8 +737,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
match &terminator.kind {
TerminatorKind::Call { func, .. } => {
let ConstCx { tcx, body, def_id: caller, param_env, .. } = *self.ccx;
let caller = caller.to_def_id();
let ConstCx { tcx, body, param_env, .. } = *self.ccx;
let caller = self.def_id().to_def_id();
let fn_ty = func.ty(body, tcx);

View File

@ -408,15 +408,12 @@ impl Conflicts<'a> {
body.local_decls.len(),
);
let def_id = body.source.def_id();
let mut init = MaybeInitializedLocals
.into_engine(tcx, body, def_id)
.iterate_to_fixpoint()
.into_results_cursor(body);
let mut live = MaybeLiveLocals
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.iterate_to_fixpoint()
.into_results_cursor(body);
let mut live =
MaybeLiveLocals.into_engine(tcx, body).iterate_to_fixpoint().into_results_cursor(body);
let mut reachable = None;
dump_mir(tcx, None, "DestinationPropagation-dataflow", &"", body, |pass_where, w| {

View File

@ -10,7 +10,6 @@ use crate::util::elaborate_drops::{elaborate_drop, DropFlagState, Unwind};
use crate::util::elaborate_drops::{DropElaborator, DropFlagMode, DropStyle};
use crate::util::patch::MirPatch;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt};
@ -39,10 +38,10 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
let elaborate_patch = {
let body = &*body;
let env = MoveDataParamEnv { move_data, param_env };
let dead_unwinds = find_dead_unwinds(tcx, body, def_id, &env);
let dead_unwinds = find_dead_unwinds(tcx, body, &env);
let inits = MaybeInitializedPlaces::new(tcx, body, &env)
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.dead_unwinds(&dead_unwinds)
.pass_name("elaborate_drops")
.iterate_to_fixpoint()
@ -50,7 +49,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
let uninits = MaybeUninitializedPlaces::new(tcx, body, &env)
.mark_inactive_variants_as_uninit()
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.dead_unwinds(&dead_unwinds)
.pass_name("elaborate_drops")
.iterate_to_fixpoint()
@ -76,7 +75,6 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
fn find_dead_unwinds<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
def_id: hir::def_id::DefId,
env: &MoveDataParamEnv<'tcx>,
) -> BitSet<BasicBlock> {
debug!("find_dead_unwinds({:?})", body.span);
@ -84,7 +82,7 @@ fn find_dead_unwinds<'tcx>(
// reach cleanup blocks, which can't have unwind edges themselves.
let mut dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &env)
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.pass_name("find_dead_unwinds")
.iterate_to_fixpoint()
.into_results_cursor(body);

View File

@ -61,7 +61,6 @@ use crate::util::expand_aggregate;
use crate::util::storage;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::{BitMatrix, BitSet};
use rustc_index::vec::{Idx, IndexVec};
@ -454,20 +453,19 @@ fn locals_live_across_suspend_points(
always_live_locals: &storage::AlwaysLiveLocals,
movable: bool,
) -> LivenessInfo {
let def_id = body.source.def_id();
let body_ref: &Body<'_> = &body;
// Calculate when MIR locals have live storage. This gives us an upper bound of their
// lifetimes.
let mut storage_live = MaybeStorageLive::new(always_live_locals.clone())
.into_engine(tcx, body_ref, def_id)
.into_engine(tcx, body_ref)
.iterate_to_fixpoint()
.into_results_cursor(body_ref);
// Calculate the MIR locals which have been previously
// borrowed (even if they are still active).
let borrowed_locals_results = MaybeBorrowedLocals::all_borrows()
.into_engine(tcx, body_ref, def_id)
.into_engine(tcx, body_ref)
.pass_name("generator")
.iterate_to_fixpoint();
@ -477,14 +475,14 @@ fn locals_live_across_suspend_points(
// Calculate the MIR locals that we actually need to keep storage around
// for.
let requires_storage_results = MaybeRequiresStorage::new(body, &borrowed_locals_results)
.into_engine(tcx, body_ref, def_id)
.into_engine(tcx, body_ref)
.iterate_to_fixpoint();
let mut requires_storage_cursor =
dataflow::ResultsCursor::new(body_ref, &requires_storage_results);
// Calculate the liveness of MIR locals ignoring borrows.
let mut liveness = MaybeLiveLocals
.into_engine(tcx, body_ref, def_id)
.into_engine(tcx, body_ref)
.pass_name("generator")
.iterate_to_fixpoint()
.into_results_cursor(body_ref);
@ -722,11 +720,11 @@ impl<'body, 'tcx, 's> StorageConflictVisitor<'body, 'tcx, 's> {
fn sanitize_witness<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
did: DefId,
witness: Ty<'tcx>,
upvars: &Vec<Ty<'tcx>>,
saved_locals: &GeneratorSavedLocals,
) {
let did = body.source.def_id();
let allowed_upvars = tcx.erase_regions(upvars);
let allowed = match witness.kind() {
ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(&s),
@ -865,7 +863,7 @@ fn insert_switch<'tcx>(
}
}
fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, body: &mut Body<'tcx>) {
fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
use crate::shim::DropShimElaborator;
use crate::util::elaborate_drops::{elaborate_drop, Unwind};
use crate::util::patch::MirPatch;
@ -874,6 +872,7 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, body: &mut
// this is ok because `open_drop` can only be reached within that own
// generator's resume function.
let def_id = body.source.def_id();
let param_env = tcx.param_env(def_id);
let mut elaborator = DropShimElaborator { body, patch: MirPatch::new(body), tcx, param_env };
@ -1246,8 +1245,6 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
assert!(body.generator_drop.is_none());
let def_id = body.source.def_id();
// The first argument is the generator type passed by value
let gen_ty = body.local_decls.raw[1].ty;
@ -1306,7 +1303,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
let liveness_info =
locals_live_across_suspend_points(tcx, body, &always_live_locals, movable);
sanitize_witness(tcx, body, def_id, interior, &upvars, &liveness_info.saved_locals);
sanitize_witness(tcx, body, interior, &upvars, &liveness_info.saved_locals);
if tcx.sess.opts.debugging_opts.validate_mir {
let mut vis = EnsureGeneratorFieldAssignmentsNeverAlias {
@ -1358,7 +1355,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
// Expand `drop(generator_struct)` to a drop ladder which destroys upvars.
// If any upvars are moved out of, drop elaboration will handle upvar destruction.
// However we need to also elaborate the code generated by `insert_clean_drop`.
elaborate_generator_drops(tcx, def_id, body);
elaborate_generator_drops(tcx, body);
dump_mir(tcx, None, "generator_post-transform", &0, body, |_, _| Ok(()));

View File

@ -229,13 +229,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) ->
return Default::default();
}
let ccx = check_consts::ConstCx {
body,
tcx,
def_id: def.did,
const_kind,
param_env: tcx.param_env(def.did),
};
let ccx = check_consts::ConstCx { body, tcx, const_kind, param_env: tcx.param_env(def.did) };
let mut validator = check_consts::validation::Validator::new(&ccx);
validator.check_body();
@ -346,7 +340,7 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
let mut body = body.steal();
run_post_borrowck_cleanup_passes(tcx, &mut body);
check_consts::post_drop_elaboration::check_live_drops(tcx, def.did, &body);
check_consts::post_drop_elaboration::check_live_drops(tcx, &body);
tcx.alloc_steal_mir(body)
}

View File

@ -60,15 +60,13 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
return;
}
let def = body.source.with_opt_param().expect_local();
let mut rpo = traversal::reverse_postorder(body);
let ccx = ConstCx::new(tcx, def.did, body);
let ccx = ConstCx::new(tcx, body);
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);
let promoted = promote_candidates(def.to_global(), body, tcx, temps, promotable_candidates);
let promoted = promote_candidates(body, tcx, temps, promotable_candidates);
self.promoted_fragments.set(promoted);
}
}
@ -758,7 +756,7 @@ impl<'tcx> Validator<'_, 'tcx> {
ty::FnDef(def_id, _) => {
is_const_fn(self.tcx, def_id)
|| is_unstable_const_fn(self.tcx, def_id).is_some()
|| is_lang_panic_fn(self.tcx, self.def_id.to_def_id())
|| is_lang_panic_fn(self.tcx, def_id)
}
_ => false,
};
@ -970,10 +968,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
fn promote_candidate(
mut self,
def: ty::WithOptConstParam<DefId>,
candidate: Candidate,
next_promoted_id: usize,
) -> Option<Body<'tcx>> {
let def = self.source.source.with_opt_param();
let mut rvalue = {
let promoted = &mut self.promoted;
let promoted_id = Promoted::new(next_promoted_id);
@ -1133,7 +1131,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
}
pub fn promote_candidates<'tcx>(
def: ty::WithOptConstParam<DefId>,
body: &mut Body<'tcx>,
tcx: TyCtxt<'tcx>,
mut temps: IndexVec<Local, TempState>,
@ -1191,7 +1188,7 @@ pub fn promote_candidates<'tcx>(
};
//FIXME(oli-obk): having a `maybe_push()` method on `IndexVec` might be nice
if let Some(mut promoted) = promoter.promote_candidate(def, candidate, promotions.len()) {
if let Some(mut promoted) = promoter.promote_candidate(candidate, promotions.len()) {
promoted.source.promoted = Some(promotions.next_index());
promotions.push(promoted);
}
@ -1250,7 +1247,9 @@ crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>(
debug!(
"should_suggest_const_in_array_repeat_expressions_flag: def_id={:?} \
should_promote={:?} feature_flag={:?}",
validator.ccx.def_id, should_promote, feature_flag
validator.ccx.def_id(),
should_promote,
feature_flag
);
should_promote && !feature_flag
}

View File

@ -1,10 +1,9 @@
//! This pass replaces a drop of a type that does not need dropping, with a goto
use crate::transform::MirPass;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{ParamEnv, TyCtxt};
use super::simplify::simplify_cfg;
@ -16,8 +15,8 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
let mut opt_finder = RemoveUnneededDropsOptimizationFinder {
tcx,
body,
param_env: tcx.param_env(body.source.def_id()),
optimizations: vec![],
def_id: body.source.def_id().expect_local(),
};
opt_finder.visit_body(body);
let should_simplify = !opt_finder.optimizations.is_empty();
@ -40,7 +39,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RemoveUnneededDropsOptimizationFinder<'a, 'tcx>
match terminator.kind {
TerminatorKind::Drop { place, target, .. } => {
let ty = place.ty(self.body, self.tcx);
let needs_drop = ty.ty.needs_drop(self.tcx, self.tcx.param_env(self.def_id));
let needs_drop = ty.ty.needs_drop(self.tcx, self.param_env);
if !needs_drop {
self.optimizations.push((location, target));
}
@ -54,5 +53,5 @@ pub struct RemoveUnneededDropsOptimizationFinder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
body: &'a Body<'tcx>,
optimizations: Vec<(Location, BasicBlock)>,
def_id: LocalDefId,
param_env: ParamEnv<'tcx>,
}

View File

@ -6,7 +6,6 @@ use rustc_span::Span;
use rustc_target::spec::abi::Abi;
use crate::transform::MirPass;
use rustc_hir::def_id::DefId;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{self, Body, Local, Location};
use rustc_middle::ty::{self, Ty, TyCtxt};
@ -41,41 +40,40 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
if has_rustc_mir_with(sess, &attributes, sym::rustc_peek_maybe_init).is_some() {
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.iterate_to_fixpoint();
sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_inits);
sanity_check_via_rustc_peek(tcx, body, &attributes, &flow_inits);
}
if has_rustc_mir_with(sess, &attributes, sym::rustc_peek_maybe_uninit).is_some() {
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.iterate_to_fixpoint();
sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_uninits);
sanity_check_via_rustc_peek(tcx, body, &attributes, &flow_uninits);
}
if has_rustc_mir_with(sess, &attributes, sym::rustc_peek_definite_init).is_some() {
let flow_def_inits = DefinitelyInitializedPlaces::new(tcx, body, &mdpe)
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.iterate_to_fixpoint();
sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_def_inits);
sanity_check_via_rustc_peek(tcx, body, &attributes, &flow_def_inits);
}
if has_rustc_mir_with(sess, &attributes, sym::rustc_peek_indirectly_mutable).is_some() {
let flow_mut_borrowed = MaybeMutBorrowedLocals::mut_borrows_only(tcx, body, param_env)
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.iterate_to_fixpoint();
sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_mut_borrowed);
sanity_check_via_rustc_peek(tcx, body, &attributes, &flow_mut_borrowed);
}
if has_rustc_mir_with(sess, &attributes, sym::rustc_peek_liveness).is_some() {
let flow_liveness =
MaybeLiveLocals.into_engine(tcx, body, def_id).iterate_to_fixpoint();
let flow_liveness = MaybeLiveLocals.into_engine(tcx, body).iterate_to_fixpoint();
sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_liveness);
sanity_check_via_rustc_peek(tcx, body, &attributes, &flow_liveness);
}
if has_rustc_mir_with(sess, &attributes, sym::stop_after_dataflow).is_some() {
@ -103,12 +101,12 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
pub fn sanity_check_via_rustc_peek<'tcx, A>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
def_id: DefId,
_attributes: &[ast::Attribute],
results: &Results<'tcx, A>,
) where
A: RustcPeekAt<'tcx>,
{
let def_id = body.source.def_id();
debug!("sanity_check_via_rustc_peek def_id: {:?}", def_id);
let mut cursor = ResultsCursor::new(body, results);

View File

@ -38,7 +38,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
let always_live_locals = AlwaysLiveLocals::new(body);
let storage_liveness = MaybeStorageLive::new(always_live_locals)
.into_engine(tcx, body, def_id)
.into_engine(tcx, body)
.iterate_to_fixpoint()
.into_results_cursor(body);

View File

@ -72,16 +72,16 @@ where
writeln!(w, r#" edge [{}];"#, content_attrs_str)?;
// Graph label
write_graph_label(tcx, def_id, body, w)?;
write_graph_label(tcx, body, w)?;
// Nodes
for (block, _) in body.basic_blocks().iter_enumerated() {
write_node(def_id, block, body, dark_mode, w)?;
write_node(block, body, dark_mode, w)?;
}
// Edges
for (source, _) in body.basic_blocks().iter_enumerated() {
write_edges(def_id, source, body, w)?;
write_edges(source, body, w)?;
}
writeln!(w, "}}")
}
@ -151,12 +151,12 @@ where
/// Write a graphviz DOT node for the given basic block.
fn write_node<W: Write>(
def_id: DefId,
block: BasicBlock,
body: &Body<'_>,
dark_mode: bool,
w: &mut W,
) -> io::Result<()> {
let def_id = body.source.def_id();
// Start a new node with the label to follow, in one of DOT's pseudo-HTML tables.
write!(w, r#" {} [shape="none", label=<"#, node(def_id, block))?;
write_node_label(block, body, dark_mode, w, 1, |_| Ok(()), |_| Ok(()))?;
@ -165,12 +165,8 @@ fn write_node<W: Write>(
}
/// Write graphviz DOT edges with labels between the given basic block and all of its successors.
fn write_edges<W: Write>(
def_id: DefId,
source: BasicBlock,
body: &Body<'_>,
w: &mut W,
) -> io::Result<()> {
fn write_edges<W: Write>(source: BasicBlock, body: &Body<'_>, w: &mut W) -> io::Result<()> {
let def_id = body.source.def_id();
let terminator = body[source].terminator();
let labels = terminator.kind.fmt_successor_labels();
@ -188,10 +184,11 @@ fn write_edges<W: Write>(
/// all the variables and temporaries.
fn write_graph_label<'tcx, W: Write>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
body: &Body<'_>,
w: &mut W,
) -> io::Result<()> {
let def_id = body.source.def_id();
write!(w, " label=<fn {}(", dot::escape_html(&tcx.def_path_str(def_id)))?;
// fn argument types.

View File

@ -153,7 +153,7 @@ fn dump_matched_mir_node<'tcx, F>(
let mut file =
create_dump_file(tcx, "html", pass_num, pass_name, disambiguator, body.source)?;
if body.source.def_id().is_local() {
write_mir_fn_spanview(tcx, body.source.def_id(), body, spanview, &mut file)?;
write_mir_fn_spanview(tcx, body, spanview, &mut file)?;
}
};
}

View File

@ -90,7 +90,6 @@ pub struct SpanViewable {
/// Write a spanview HTML+CSS file to analyze MIR element spans.
pub fn write_mir_fn_spanview<'tcx, W>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
body: &Body<'tcx>,
spanview: MirSpanview,
w: &mut W,
@ -98,6 +97,7 @@ pub fn write_mir_fn_spanview<'tcx, W>(
where
W: Write,
{
let def_id = body.source.def_id();
let body_span = hir_body(tcx, def_id).value.span;
let mut span_viewables = Vec::new();
for (bb, data) in body.basic_blocks().iter_enumerated() {

View File

@ -205,7 +205,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
build::construct_const(cx, body_id, return_ty, return_ty_span)
};
lints::check(tcx, &body, def.did);
lints::check(tcx, &body);
// The borrow checker will replace all the regions here with its own
// inference variables. There's no point having non-erased regions here.

View File

@ -1,7 +1,6 @@
use rustc_data_structures::graph::iterate::{
ControlFlow, NodeStatus, TriColorDepthFirstSearch, TriColorVisitor,
};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::FnKind;
use rustc_middle::hir::map::blocks::FnLikeNode;
use rustc_middle::mir::{BasicBlock, Body, Operand, TerminatorKind};
@ -10,7 +9,8 @@ use rustc_middle::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt};
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
use rustc_span::Span;
crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: LocalDefId) {
crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
let def_id = body.source.def_id().expect_local();
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) {
@ -30,7 +30,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: LocalDefId) {
_ => &[],
};
let mut vis = Search { tcx, body, def_id, reachable_recursive_calls: vec![], trait_substs };
let mut vis = Search { tcx, body, reachable_recursive_calls: vec![], trait_substs };
if let Some(NonRecursive) = TriColorDepthFirstSearch::new(&body).run_from_start(&mut vis) {
return;
}
@ -57,7 +57,6 @@ struct NonRecursive;
struct Search<'mir, 'tcx> {
tcx: TyCtxt<'tcx>,
body: &'mir Body<'tcx>,
def_id: LocalDefId,
trait_substs: &'tcx [GenericArg<'tcx>],
reachable_recursive_calls: Vec<Span>,
@ -66,16 +65,17 @@ struct Search<'mir, 'tcx> {
impl<'mir, 'tcx> Search<'mir, 'tcx> {
/// Returns `true` if `func` refers to the function we are searching in.
fn is_recursive_call(&self, func: &Operand<'tcx>) -> bool {
let Search { tcx, body, def_id, trait_substs, .. } = *self;
let param_env = tcx.param_env(def_id);
let Search { tcx, body, trait_substs, .. } = *self;
let caller = body.source.def_id();
let param_env = tcx.param_env(caller);
let func_ty = func.ty(body, tcx);
if let ty::FnDef(fn_def_id, substs) = *func_ty.kind() {
let (call_fn_id, call_substs) =
if let Ok(Some(instance)) = Instance::resolve(tcx, param_env, fn_def_id, substs) {
if let ty::FnDef(callee, substs) = *func_ty.kind() {
let (callee, call_substs) =
if let Ok(Some(instance)) = Instance::resolve(tcx, param_env, callee, substs) {
(instance.def_id(), instance.substs)
} else {
(fn_def_id, substs)
(callee, substs)
};
// FIXME(#57965): Make this work across function boundaries
@ -84,8 +84,7 @@ impl<'mir, 'tcx> Search<'mir, 'tcx> {
// calling into an entirely different method (for example, a call from the default
// method in the trait to `<A as Trait<B>>::method`, where `A` and/or `B` are
// specific types).
return call_fn_id == def_id.to_def_id()
&& &call_substs[..trait_substs.len()] == trait_substs;
return callee == caller && &call_substs[..trait_substs.len()] == trait_substs;
}
false

View File

@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
let mir = cx.tcx.optimized_mir(def_id);
if let Err((span, err)) = is_min_const_fn(cx.tcx, def_id.to_def_id(), &mir) {
if let Err((span, err)) = is_min_const_fn(cx.tcx, &mir) {
if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id.to_def_id()) {
cx.tcx.sess.span_err(span, &err);
}

View File

@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
let mir = cx.tcx.optimized_mir(def_id.to_def_id());
let maybe_storage_live_result = MaybeStorageLive
.into_engine(cx.tcx, mir, def_id.to_def_id())
.into_engine(cx.tcx, mir)
.pass_name("redundant_clone")
.iterate_to_fixpoint()
.into_results_cursor(mir);

View File

@ -10,7 +10,8 @@ use std::borrow::Cow;
type McfResult = Result<(), (Span, Cow<'static, str>)>;
pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult {
pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> McfResult {
let def_id = body.source.def_id();
let mut current = def_id;
loop {
let predicates = tcx.predicates_of(current);