rustc: rename DefId::to_local to expect_local and use it instead of LocalDefId::from_def_id.

This commit is contained in:
Eduard-Mihai Burtescu 2019-11-03 14:48:52 +02:00
parent 55ed19fe1b
commit 0c692797d7
10 changed files with 15 additions and 21 deletions

View File

@ -425,7 +425,7 @@ impl<'tcx> DepNodeParams<'tcx> for LocalDefId {
}
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
dep_node.extract_def_id(tcx).map(|id| id.to_local())
dep_node.extract_def_id(tcx).map(|id| id.expect_local())
}
}

View File

@ -657,7 +657,7 @@ impl<'a, 'tcx> SpecializedDecoder<DefId> for CacheDecoder<'a, 'tcx> {
impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for CacheDecoder<'a, 'tcx> {
#[inline]
fn specialized_decode(&mut self) -> Result<LocalDefId, Self::Error> {
Ok(LocalDefId::from_def_id(DefId::decode(self)?))
Ok(DefId::decode(self)?.expect_local())
}
}

View File

@ -364,7 +364,7 @@ impl<'a, 'tcx> SpecializedDecoder<DefIndex> for DecodeContext<'a, 'tcx> {
impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for DecodeContext<'a, 'tcx> {
#[inline]
fn specialized_decode(&mut self) -> Result<LocalDefId, Self::Error> {
self.specialized_decode().map(|i| LocalDefId::from_def_id(i))
Ok(DefId::decode(self)?.expect_local())
}
}

View File

@ -774,7 +774,7 @@ fn for_each_late_bound_region_defined_on<'tcx>(
fn_def_id: DefId,
mut f: impl FnMut(ty::Region<'tcx>),
) {
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.to_local()) {
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
for late_bound in late_bounds.iter() {
let hir_id = HirId { owner: fn_def_id.index, local_id: *late_bound };
let name = tcx.hir().name(hir_id);

View File

@ -85,7 +85,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
let parent_id = tcx.hir().get_parent_did(hir_id);
if !parent_id.is_top_level_module() {
is_const_impl_raw(tcx, LocalDefId::from_def_id(parent_id))
is_const_impl_raw(tcx, parent_id.expect_local())
} else {
false
}
@ -171,7 +171,7 @@ fn const_fn_is_allowed_fn_ptr(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers {
is_const_fn_raw,
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, LocalDefId::from_def_id(def_id)),
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
is_promotable_const_fn,
const_fn_is_allowed_fn_ptr,
..*providers

View File

@ -10,7 +10,6 @@ use rustc::ty::subst::{InternalSubsts, SubstsRef};
use rustc::ty::{self, AdtKind, Ty};
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
use rustc_hir::def_id::LocalDefId;
use rustc_index::vec::Idx;
use rustc_span::Span;
@ -812,7 +811,7 @@ fn convert_var<'tcx>(
let closure_def_id = cx.body_owner;
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
closure_expr_id: closure_def_id.expect_local(),
};
let var_ty = cx.tables().node_type(var_hir_id);
@ -987,7 +986,7 @@ fn capture_upvar<'tcx>(
) -> ExprRef<'tcx> {
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.hir_id).to_local(),
closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.hir_id).expect_local(),
};
let upvar_capture = cx.tables().upvar_capture(upvar_id);
let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);

View File

@ -164,8 +164,9 @@ impl DefId {
}
#[inline]
pub fn to_local(self) -> LocalDefId {
LocalDefId::from_def_id(self)
pub fn expect_local(self) -> LocalDefId {
assert!(self.is_local());
LocalDefId { local_def_index: self.index }
}
pub fn is_top_level_module(self) -> bool {
@ -216,12 +217,6 @@ pub struct LocalDefId {
}
impl LocalDefId {
#[inline]
pub fn from_def_id(def_id: DefId) -> LocalDefId {
assert!(def_id.is_local());
LocalDefId { local_def_index: def_id.index }
}
#[inline]
pub fn to_def_id(self) -> DefId {
DefId { krate: LOCAL_CRATE, index: self.local_def_index }

View File

@ -118,7 +118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
for (&var_hir_id, _) in upvars.iter() {
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
closure_expr_id: closure_def_id.expect_local(),
};
debug!("seed upvar_id {:?}", upvar_id);
// Adding the upvar Id to the list of Upvars, which will be added
@ -228,7 +228,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let upvar_ty = self.node_ty(var_hir_id);
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
closure_expr_id: closure_def_id.expect_local(),
};
let capture = self.tables.borrow().upvar_capture(upvar_id);

View File

@ -519,7 +519,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
for &var_id in upvars.keys() {
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_id },
closure_expr_id: closure_def_id.to_local(),
closure_expr_id: closure_def_id.expect_local(),
};
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
let captured_place = return_if_err!(self.cat_captured_var(

View File

@ -470,7 +470,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_id },
closure_expr_id: closure_expr_def_id.to_local(),
closure_expr_id: closure_expr_def_id.expect_local(),
};
let var_ty = self.node_ty(var_id)?;