Skip to content

Commit 01fe094

Browse files
committed
rustc: rename DefId::to_local to assert_local and use it instead of LocalDefId::from_def_id.
1 parent 4399b2c commit 01fe094

File tree

9 files changed

+17
-23
lines changed

9 files changed

+17
-23
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl RecoverKey<'tcx> for DefId {
449449

450450
impl RecoverKey<'tcx> for LocalDefId {
451451
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
452-
dep_node.extract_def_id(tcx).map(|id| id.to_local())
452+
dep_node.extract_def_id(tcx).map(|id| id.assert_local())
453453
}
454454
}
455455

src/librustc/hir/def_id.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ impl DefId {
139139
}
140140

141141
#[inline]
142-
pub fn to_local(self) -> LocalDefId {
143-
LocalDefId::from_def_id(self)
142+
pub fn assert_local(self) -> LocalDefId {
143+
assert!(self.is_local());
144+
LocalDefId {
145+
index: self.index,
146+
}
144147
}
145148

146149
pub fn describe_as_module(&self, tcx: TyCtxt<'_>) -> String {
@@ -167,14 +170,6 @@ pub struct LocalDefId {
167170
}
168171

169172
impl LocalDefId {
170-
#[inline]
171-
pub fn from_def_id(def_id: DefId) -> LocalDefId {
172-
assert!(def_id.is_local());
173-
LocalDefId {
174-
index: def_id.index,
175-
}
176-
}
177-
178173
#[inline]
179174
pub fn to_def_id(self) -> DefId {
180175
DefId {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
622622
for &var_id in upvars.keys() {
623623
let upvar_id = ty::UpvarId {
624624
var_path: ty::UpvarPath { hir_id: var_id },
625-
closure_expr_id: closure_def_id.to_local(),
625+
closure_expr_id: closure_def_id.assert_local(),
626626
};
627627
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
628628
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,

src/librustc/middle/mem_categorization.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub use self::Note::*;
5959
use self::Aliasability::*;
6060

6161
use crate::middle::region;
62-
use crate::hir::def_id::{DefId, LocalDefId};
62+
use crate::hir::def_id::DefId;
6363
use crate::hir::Node;
6464
use crate::infer::InferCtxt;
6565
use crate::hir::def::{CtorOf, Res, DefKind, CtorKind};
@@ -723,7 +723,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
723723

724724
let closure_expr_def_id = self.body_owner;
725725
let fn_hir_id = self.tcx.hir().local_def_id_to_hir_id(
726-
LocalDefId::from_def_id(closure_expr_def_id),
726+
closure_expr_def_id.assert_local(),
727727
);
728728
let ty = self.node_ty(fn_hir_id)?;
729729
let kind = match ty.kind {
@@ -747,7 +747,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
747747

748748
let upvar_id = ty::UpvarId {
749749
var_path: ty::UpvarPath { hir_id: var_id },
750-
closure_expr_id: closure_expr_def_id.to_local(),
750+
closure_expr_id: closure_expr_def_id.assert_local(),
751751
};
752752

753753
let var_ty = self.node_ty(var_id)?;

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl<'a, 'tcx> SpecializedDecoder<DefId> for CacheDecoder<'a, 'tcx> {
658658
impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for CacheDecoder<'a, 'tcx> {
659659
#[inline]
660660
fn specialized_decode(&mut self) -> Result<LocalDefId, Self::Error> {
661-
Ok(LocalDefId::from_def_id(DefId::decode(self)?))
661+
Ok(DefId::decode(self)?.assert_local())
662662
}
663663
}
664664

src/librustc_metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a, 'tcx> SpecializedDecoder<DefIndex> for DecodeContext<'a, 'tcx> {
287287
impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for DecodeContext<'a, 'tcx> {
288288
#[inline]
289289
fn specialized_decode(&mut self) -> Result<LocalDefId, Self::Error> {
290-
self.specialized_decode().map(|i| LocalDefId::from_def_id(i))
290+
Ok(DefId::decode(self)?.assert_local())
291291
}
292292
}
293293

src/librustc_mir/borrow_check/nll/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ fn for_each_late_bound_region_defined_on<'tcx>(
784784
fn_def_id: DefId,
785785
mut f: impl FnMut(ty::Region<'tcx>),
786786
) {
787-
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.to_local()) {
787+
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.assert_local()) {
788788
for late_bound in late_bounds.iter() {
789789
let hir_id = HirId {
790790
owner: fn_def_id.index,

src/librustc_mir/hair/cx/expr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc::ty::{self, AdtKind, Ty};
1010
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, PointerCast};
1111
use rustc::ty::subst::{InternalSubsts, SubstsRef};
1212
use rustc::hir;
13-
use rustc::hir::def_id::LocalDefId;
1413
use rustc::mir::BorrowKind;
1514
use syntax_pos::Span;
1615

@@ -984,7 +983,7 @@ fn convert_var(
984983
let closure_def_id = cx.body_owner;
985984
let upvar_id = ty::UpvarId {
986985
var_path: ty::UpvarPath {hir_id: var_hir_id},
987-
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
986+
closure_expr_id: closure_def_id.assert_local(),
988987
};
989988
let var_ty = cx.tables().node_type(var_hir_id);
990989

@@ -1185,7 +1184,7 @@ fn capture_upvar<'tcx>(
11851184
) -> ExprRef<'tcx> {
11861185
let upvar_id = ty::UpvarId {
11871186
var_path: ty::UpvarPath { hir_id: var_hir_id },
1188-
closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.hir_id).to_local(),
1187+
closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.hir_id).assert_local(),
11891188
};
11901189
let upvar_capture = cx.tables().upvar_capture(upvar_id);
11911190
let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);

src/librustc_typeck/check/upvar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133133
var_path: ty::UpvarPath {
134134
hir_id: var_hir_id,
135135
},
136-
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
136+
closure_expr_id: closure_def_id.assert_local(),
137137
};
138138
debug!("seed upvar_id {:?}", upvar_id);
139139
// Adding the upvar Id to the list of Upvars, which will be added
@@ -261,7 +261,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
261261
let upvar_ty = self.node_ty(var_hir_id);
262262
let upvar_id = ty::UpvarId {
263263
var_path: ty::UpvarPath { hir_id: var_hir_id },
264-
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
264+
closure_expr_id: closure_def_id.assert_local(),
265265
};
266266
let capture = self.tables.borrow().upvar_capture(upvar_id);
267267

0 commit comments

Comments
 (0)