Skip to content

Commit 0c69279

Browse files
committed
rustc: rename DefId::to_local to expect_local and use it instead of LocalDefId::from_def_id.
1 parent 55ed19f commit 0c69279

File tree

10 files changed

+15
-21
lines changed

10 files changed

+15
-21
lines changed

src/librustc/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'tcx> DepNodeParams<'tcx> for LocalDefId {
425425
}
426426

427427
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
428-
dep_node.extract_def_id(tcx).map(|id| id.to_local())
428+
dep_node.extract_def_id(tcx).map(|id| id.expect_local())
429429
}
430430
}
431431

src/librustc/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ impl<'a, 'tcx> SpecializedDecoder<DefId> for CacheDecoder<'a, 'tcx> {
657657
impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for CacheDecoder<'a, 'tcx> {
658658
#[inline]
659659
fn specialized_decode(&mut self) -> Result<LocalDefId, Self::Error> {
660-
Ok(LocalDefId::from_def_id(DefId::decode(self)?))
660+
Ok(DefId::decode(self)?.expect_local())
661661
}
662662
}
663663

src/librustc_metadata/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<'a, 'tcx> SpecializedDecoder<DefIndex> for DecodeContext<'a, 'tcx> {
364364
impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for DecodeContext<'a, 'tcx> {
365365
#[inline]
366366
fn specialized_decode(&mut self) -> Result<LocalDefId, Self::Error> {
367-
self.specialized_decode().map(|i| LocalDefId::from_def_id(i))
367+
Ok(DefId::decode(self)?.expect_local())
368368
}
369369
}
370370

src/librustc_mir/borrow_check/universal_regions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ fn for_each_late_bound_region_defined_on<'tcx>(
774774
fn_def_id: DefId,
775775
mut f: impl FnMut(ty::Region<'tcx>),
776776
) {
777-
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.to_local()) {
777+
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
778778
for late_bound in late_bounds.iter() {
779779
let hir_id = HirId { owner: fn_def_id.index, local_id: *late_bound };
780780
let name = tcx.hir().name(hir_id);

src/librustc_mir/const_eval/fn_queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
8585
pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
8686
let parent_id = tcx.hir().get_parent_did(hir_id);
8787
if !parent_id.is_top_level_module() {
88-
is_const_impl_raw(tcx, LocalDefId::from_def_id(parent_id))
88+
is_const_impl_raw(tcx, parent_id.expect_local())
8989
} else {
9090
false
9191
}
@@ -171,7 +171,7 @@ fn const_fn_is_allowed_fn_ptr(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
171171
pub fn provide(providers: &mut Providers<'_>) {
172172
*providers = Providers {
173173
is_const_fn_raw,
174-
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, LocalDefId::from_def_id(def_id)),
174+
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
175175
is_promotable_const_fn,
176176
const_fn_is_allowed_fn_ptr,
177177
..*providers

src/librustc_mir_build/hair/cx/expr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc::ty::subst::{InternalSubsts, SubstsRef};
1010
use rustc::ty::{self, AdtKind, Ty};
1111
use rustc_hir as hir;
1212
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
13-
use rustc_hir::def_id::LocalDefId;
1413
use rustc_index::vec::Idx;
1514
use rustc_span::Span;
1615

@@ -812,7 +811,7 @@ fn convert_var<'tcx>(
812811
let closure_def_id = cx.body_owner;
813812
let upvar_id = ty::UpvarId {
814813
var_path: ty::UpvarPath { hir_id: var_hir_id },
815-
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
814+
closure_expr_id: closure_def_id.expect_local(),
816815
};
817816
let var_ty = cx.tables().node_type(var_hir_id);
818817

@@ -987,7 +986,7 @@ fn capture_upvar<'tcx>(
987986
) -> ExprRef<'tcx> {
988987
let upvar_id = ty::UpvarId {
989988
var_path: ty::UpvarPath { hir_id: var_hir_id },
990-
closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.hir_id).to_local(),
989+
closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.hir_id).expect_local(),
991990
};
992991
let upvar_capture = cx.tables().upvar_capture(upvar_id);
993992
let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);

src/librustc_span/def_id.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ impl DefId {
164164
}
165165

166166
#[inline]
167-
pub fn to_local(self) -> LocalDefId {
168-
LocalDefId::from_def_id(self)
167+
pub fn expect_local(self) -> LocalDefId {
168+
assert!(self.is_local());
169+
LocalDefId { local_def_index: self.index }
169170
}
170171

171172
pub fn is_top_level_module(self) -> bool {
@@ -216,12 +217,6 @@ pub struct LocalDefId {
216217
}
217218

218219
impl LocalDefId {
219-
#[inline]
220-
pub fn from_def_id(def_id: DefId) -> LocalDefId {
221-
assert!(def_id.is_local());
222-
LocalDefId { local_def_index: def_id.index }
223-
}
224-
225220
#[inline]
226221
pub fn to_def_id(self) -> DefId {
227222
DefId { krate: LOCAL_CRATE, index: self.local_def_index }

src/librustc_typeck/check/upvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
118118
for (&var_hir_id, _) in upvars.iter() {
119119
let upvar_id = ty::UpvarId {
120120
var_path: ty::UpvarPath { hir_id: var_hir_id },
121-
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
121+
closure_expr_id: closure_def_id.expect_local(),
122122
};
123123
debug!("seed upvar_id {:?}", upvar_id);
124124
// Adding the upvar Id to the list of Upvars, which will be added
@@ -228,7 +228,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
228228
let upvar_ty = self.node_ty(var_hir_id);
229229
let upvar_id = ty::UpvarId {
230230
var_path: ty::UpvarPath { hir_id: var_hir_id },
231-
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
231+
closure_expr_id: closure_def_id.expect_local(),
232232
};
233233
let capture = self.tables.borrow().upvar_capture(upvar_id);
234234

src/librustc_typeck/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
519519
for &var_id in upvars.keys() {
520520
let upvar_id = ty::UpvarId {
521521
var_path: ty::UpvarPath { hir_id: var_id },
522-
closure_expr_id: closure_def_id.to_local(),
522+
closure_expr_id: closure_def_id.expect_local(),
523523
};
524524
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
525525
let captured_place = return_if_err!(self.cat_captured_var(

src/librustc_typeck/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
470470

471471
let upvar_id = ty::UpvarId {
472472
var_path: ty::UpvarPath { hir_id: var_id },
473-
closure_expr_id: closure_expr_def_id.to_local(),
473+
closure_expr_id: closure_expr_def_id.expect_local(),
474474
};
475475
let var_ty = self.node_ty(var_id)?;
476476

0 commit comments

Comments
 (0)