Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert more DefIds to LocalDefIds #74027

Merged
merged 3 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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.to_def_id(),
self.mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
Expand All @@ -145,7 +145,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.to_def_id(),
self.mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// When you have `let x: impl Foo = ...` in a closure,
// 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());
let parent_def_id =
self.tcx().closure_base_def_id(self.mir_def_id.to_def_id()).expect_local();
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
} else {
return Err(terr);
Expand Down Expand Up @@ -1208,7 +1209,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&mut self,
revealed_ty: Ty<'tcx>,
anon_ty: Ty<'tcx>,
anon_owner_def_id: DefId,
anon_owner_def_id: LocalDefId,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
Expand Down Expand Up @@ -1238,8 +1239,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let tcx = infcx.tcx;
let param_env = self.param_env;
let body = self.body;
let concrete_opaque_types =
&tcx.typeck_tables_of(anon_owner_def_id.expect_local()).concrete_opaque_types;
let concrete_opaque_types = &tcx.typeck_tables_of(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);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ pub fn const_eval_raw_provider<'tcx>(
}

v
} else if def_id.is_local() {
} else if let Some(def_id) = def_id.as_local() {
// constant defined in this crate, we can figure out a lint level!
match tcx.def_kind(def_id) {
match tcx.def_kind(def_id.to_def_id()) {
// constants never produce a hard error at the definition site. Anything else is
// a backwards compatibility hazard (and will break old versions of winapi for
// sure)
Expand All @@ -346,7 +346,7 @@ pub fn const_eval_raw_provider<'tcx>(
// validation thus preventing such a hard error from being a backwards
// compatibility hazard
DefKind::Const | DefKind::AssocConst => {
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = tcx.hir().as_local_hir_id(def_id);
err.report_as_lint(
tcx.at(tcx.def_span(def_id)),
"any use of this value will cause an error",
Expand All @@ -369,7 +369,7 @@ pub fn const_eval_raw_provider<'tcx>(
err.report_as_lint(
tcx.at(span),
"reaching this expression at runtime will panic or abort",
tcx.hir().as_local_hir_id(def_id.expect_local()),
tcx.hir().as_local_hir_id(def_id),
Some(err.span),
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/check_consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod validation;
pub struct ConstCx<'mir, 'tcx> {
pub body: &'mir mir::Body<'tcx>,
pub tcx: TyCtxt<'tcx>,
pub def_id: DefId,
pub def_id: LocalDefId,
pub param_env: ty::ParamEnv<'tcx>,
pub const_kind: Option<hir::ConstContext>,
}
Expand All @@ -40,7 +40,7 @@ impl ConstCx<'mir, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
) -> Self {
let const_kind = tcx.hir().body_const_context(def_id);
ConstCx { body, tcx, def_id: def_id.to_def_id(), param_env, const_kind }
ConstCx { body, tcx, def_id: def_id, param_env, const_kind }
}

/// Returns the kind of const context this `Item` represents (`const`, `static`, etc.).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ pub fn check_live_drops(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &mir::Body<
return;
}

let ccx = ConstCx {
body,
tcx,
def_id: def_id.to_def_id(),
const_kind,
param_env: tcx.param_env(def_id),
};
let ccx = ConstCx { body, tcx, def_id, const_kind, param_env: tcx.param_env(def_id) };

let mut visitor = CheckLiveDrops { ccx: &ccx, qualifs: Qualifs::default() };

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.as_local().unwrap());
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()
}

Expand Down
18 changes: 9 additions & 9 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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)
.into_engine(tcx, &body, def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
Expand All @@ -83,7 +83,7 @@ impl Qualifs<'mir, 'tcx> {
let ConstCx { tcx, body, def_id, .. } = *ccx;

FlowSensitiveAnalysis::new(NeedsDrop, ccx)
.into_engine(tcx, &body, def_id)
.into_engine(tcx, &body, def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
Expand All @@ -110,7 +110,7 @@ impl Qualifs<'mir, 'tcx> {
let ConstCx { tcx, body, def_id, .. } = *ccx;

FlowSensitiveAnalysis::new(HasMutInterior, ccx)
.into_engine(tcx, &body, def_id)
.into_engine(tcx, &body, def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&body)
});
Expand Down Expand Up @@ -153,7 +153,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)
.into_engine(ccx.tcx, &ccx.body, ccx.def_id.to_def_id())
.iterate_to_fixpoint()
.into_results_cursor(&ccx.body);

Expand Down Expand Up @@ -195,13 +195,13 @@ impl Validator<'mir, 'tcx> {
let ConstCx { tcx, body, def_id, const_kind, .. } = *self.ccx;

let use_min_const_fn_checks = (const_kind == Some(hir::ConstContext::ConstFn)
&& crate::const_eval::is_min_const_fn(tcx, def_id))
&& crate::const_eval::is_min_const_fn(tcx, def_id.to_def_id()))
&& !tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you;

if use_min_const_fn_checks {
// Enforce `min_const_fn` for stable `const fn`s.
use crate::transform::qualify_min_const_fn::is_min_const_fn;
if let Err((span, err)) = is_min_const_fn(tcx, def_id, &body) {
if let Err((span, err)) = is_min_const_fn(tcx, def_id.to_def_id(), &body) {
error_min_const_fn_violation(tcx, span, err);
return;
}
Expand All @@ -212,10 +212,10 @@ impl Validator<'mir, 'tcx> {
// Ensure that the end result is `Sync` in a non-thread local `static`.
let should_check_for_sync = const_kind
== Some(hir::ConstContext::Static(hir::Mutability::Not))
&& !tcx.is_thread_local_static(def_id);
&& !tcx.is_thread_local_static(def_id.to_def_id());

if should_check_for_sync {
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = tcx.hir().as_local_hir_id(def_id);
check_return_ty_is_sync(tcx, &body, hir_id);
}
}
Expand Down Expand Up @@ -535,7 +535,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
// `#[allow_internal_unstable]`.
use crate::transform::qualify_min_const_fn::lib_feature_allowed;
if !self.span.allows_unstable(feature)
&& !lib_feature_allowed(self.tcx, self.def_id, feature)
&& !lib_feature_allowed(self.tcx, self.def_id.to_def_id(), feature)
{
self.check_op(ops::FnCallUnstable(def_id, feature));
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ pub fn run_passes(
}

fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
let const_kind = tcx.hir().body_const_context(def_id.expect_local());
let def_id = def_id.expect_local();
let const_kind = tcx.hir().body_const_context(def_id);

// No need to const-check a non-const `fn`.
if const_kind.is_none() {
Expand All @@ -214,7 +215,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
// cannot yet be stolen), because `mir_validated()`, which steals
// from `mir_const(), forces this query to execute before
// performing the steal.
let body = &tcx.mir_const(def_id).borrow();
let body = &tcx.mir_const(def_id.to_def_id()).borrow();

if body.return_ty().references_error() {
tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors");
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
return;
}

let def_id = src.def_id();
let def_id = src.def_id().expect_local();

let mut rpo = traversal::reverse_postorder(body);
let ccx = ConstCx::new(tcx, def_id.expect_local(), body);
let ccx = ConstCx::new(tcx, def_id, 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_id, body, tcx, temps, promotable_candidates);
let promoted =
promote_candidates(def_id.to_def_id(), body, tcx, temps, promotable_candidates);
self.promoted_fragments.set(promoted);
}
}
Expand Down Expand Up @@ -724,7 +725,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)
|| is_lang_panic_fn(self.tcx, self.def_id.to_def_id())
}
_ => false,
};
Expand Down
17 changes: 6 additions & 11 deletions src/librustc_trait_selection/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub enum GenerateMemberConstraints {
pub trait InferCtxtExt<'tcx> {
fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
&self,
parent_def_id: DefId,
parent_def_id: LocalDefId,
body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value: &T,
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// - `value_span` -- the span where the value came from, used in error reporting
fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
&self,
parent_def_id: DefId,
parent_def_id: LocalDefId,
body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value: &T,
Expand Down Expand Up @@ -986,7 +986,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {

struct Instantiator<'a, 'tcx> {
infcx: &'a InferCtxt<'a, 'tcx>,
parent_def_id: DefId,
parent_def_id: LocalDefId,
body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value_span: Span,
Expand Down Expand Up @@ -1043,8 +1043,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
let parent_def_id = self.parent_def_id;
let def_scope_default = || {
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
parent_def_id
== tcx.hir().local_def_id(opaque_parent_hir_id).to_def_id()
parent_def_id == tcx.hir().local_def_id(opaque_parent_hir_id)
};
let (in_definition_scope, origin) = match tcx.hir().find(opaque_hir_id) {
Some(Node::Item(item)) => match item.kind {
Expand All @@ -1053,18 +1052,14 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
impl_trait_fn: Some(parent),
origin,
..
}) => (parent == self.parent_def_id, origin),
}) => (parent == self.parent_def_id.to_def_id(), origin),
// Named `type Foo = impl Bar;`
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: None,
origin,
..
}) => (
may_define_opaque_type(
tcx,
self.parent_def_id.expect_local(),
opaque_hir_id,
),
may_define_opaque_type(tcx, self.parent_def_id, opaque_hir_id),
origin,
),
_ => (def_scope_default(), hir::OpaqueTyOrigin::Misc),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,8 @@ fn check_fn<'a, 'tcx>(
fcx.resume_yield_tys = Some((resume_ty, yield_ty));
}

let outer_def_id = tcx.closure_base_def_id(hir.local_def_id(fn_id).to_def_id());
let outer_hir_id = hir.as_local_hir_id(outer_def_id.expect_local());
let outer_def_id = tcx.closure_base_def_id(hir.local_def_id(fn_id).to_def_id()).expect_local();
let outer_hir_id = hir.as_local_hir_id(outer_def_id);
GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id }.visit_body(body);

// C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
Expand Down Expand Up @@ -3427,7 +3427,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let (value, opaque_type_map) =
self.register_infer_ok_obligations(self.instantiate_opaque_types(
parent_def_id.to_def_id(),
parent_def_id,
self.body_id,
self.param_env,
value,
Expand Down