Skip to content

Commit 23de4fe

Browse files
authored
Rollup merge of rust-lang#62168 - ljedrz:the_culmination_of_hiridification, r=Zoxc
The (almost) culmination of HirIdification It's finally over. This PR removes old `FIXME`s and renames some functions so that the `HirId` variant has the shorter name. All that remains (and rightfully so) is stuff in `resolve`, `save_analysis` and (as far as I can tell) in a few places where we can't replace `NodeId` with `HirId`.
2 parents 4509e89 + a6030ff commit 23de4fe

File tree

83 files changed

+309
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+309
-321
lines changed

src/librustc/dep_graph/dep_tracking_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
5555
///
5656
/// ```
5757
/// fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
58-
/// let item_def_id = ccx.tcx.hir().local_def_id(it.id);
58+
/// let item_def_id = ccx.tcx.hir().local_def_id(it.hir_id);
5959
/// ccx.tcx.item_types.memoized(item_def_id, || {
6060
/// ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
6161
/// compute_type_of_item(ccx, item)

src/librustc/hir/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl CheckAttrVisitor<'tcx> {
9595
/// Checks any attribute.
9696
fn check_attributes(&self, item: &hir::Item, target: Target) {
9797
if target == Target::Fn || target == Target::Const {
98-
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id_from_hir_id(item.hir_id));
98+
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(item.hir_id));
9999
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name(sym::target_feature)) {
100100
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
101101
.span_label(item.span, "not a function")

src/librustc/hir/map/definitions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ impl Definitions {
371371
None
372372
}
373373

374-
// FIXME(@ljedrz): replace the NodeId variant
375374
#[inline]
376375
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<hir::HirId> {
377376
if def_id.krate == LOCAL_CRATE {

src/librustc/hir/map/hir_id_validator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub fn check_crate(hir_map: &hir::map::Map<'_>) {
1010
let errors = Lock::new(Vec::new());
1111

1212
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
13-
hir_map.visit_item_likes_in_module(hir_map.local_def_id(*module_id), &mut OuterVisitor {
13+
let local_def_id = hir_map.local_def_id_from_node_id(*module_id);
14+
hir_map.visit_item_likes_in_module(local_def_id, &mut OuterVisitor {
1415
hir_map,
1516
errors: &errors,
1617
});
@@ -79,7 +80,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
7980
hir_id: HirId,
8081
walk: F) {
8182
assert!(self.owner_def_index.is_none());
82-
let owner_def_index = self.hir_map.local_def_id_from_hir_id(hir_id).index;
83+
let owner_def_index = self.hir_map.local_def_id(hir_id).index;
8384
self.owner_def_index = Some(owner_def_index);
8485
walk(self);
8586

src/librustc/hir/map/mod.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'hir> Map<'hir> {
219219
}
220220

221221
pub fn def_path_from_hir_id(&self, id: HirId) -> Option<DefPath> {
222-
self.opt_local_def_id_from_hir_id(id).map(|def_id| {
222+
self.opt_local_def_id(id).map(|def_id| {
223223
self.def_path(def_id)
224224
})
225225
}
@@ -230,32 +230,30 @@ impl<'hir> Map<'hir> {
230230
}
231231

232232
#[inline]
233-
pub fn local_def_id(&self, node: NodeId) -> DefId {
234-
self.opt_local_def_id(node).unwrap_or_else(|| {
233+
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
234+
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
235235
let hir_id = self.node_to_hir_id(node);
236-
bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`",
236+
bug!("local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
237237
node, self.find_entry(hir_id))
238238
})
239239
}
240240

241-
// FIXME(@ljedrz): replace the `NodeId` variant.
242241
#[inline]
243-
pub fn local_def_id_from_hir_id(&self, hir_id: HirId) -> DefId {
244-
self.opt_local_def_id_from_hir_id(hir_id).unwrap_or_else(|| {
245-
bug!("local_def_id_from_hir_id: no entry for `{:?}`, which has a map of `{:?}`",
242+
pub fn local_def_id(&self, hir_id: HirId) -> DefId {
243+
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
244+
bug!("local_def_id: no entry for `{:?}`, which has a map of `{:?}`",
246245
hir_id, self.find_entry(hir_id))
247246
})
248247
}
249248

250-
// FIXME(@ljedrz): replace the `NodeId` variant.
251249
#[inline]
252-
pub fn opt_local_def_id_from_hir_id(&self, hir_id: HirId) -> Option<DefId> {
250+
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
253251
let node_id = self.hir_to_node_id(hir_id);
254252
self.definitions.opt_local_def_id(node_id)
255253
}
256254

257255
#[inline]
258-
pub fn opt_local_def_id(&self, node: NodeId) -> Option<DefId> {
256+
pub fn opt_local_def_id_from_node_id(&self, node: NodeId) -> Option<DefId> {
259257
self.definitions.opt_local_def_id(node)
260258
}
261259

@@ -264,7 +262,6 @@ impl<'hir> Map<'hir> {
264262
self.definitions.as_local_node_id(def_id)
265263
}
266264

267-
// FIXME(@ljedrz): replace the `NodeId` variant.
268265
#[inline]
269266
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<HirId> {
270267
self.definitions.as_local_hir_id(def_id)
@@ -429,7 +426,7 @@ impl<'hir> Map<'hir> {
429426
}
430427

431428
pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
432-
self.local_def_id_from_hir_id(self.body_owner(id))
429+
self.local_def_id(self.body_owner(id))
433430
}
434431

435432
/// Given a `HirId`, returns the `BodyId` associated with it,
@@ -765,7 +762,7 @@ impl<'hir> Map<'hir> {
765762
/// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
766763
/// module parent is in this map.
767764
pub fn get_module_parent(&self, id: HirId) -> DefId {
768-
self.local_def_id_from_hir_id(self.get_module_parent_node(id))
765+
self.local_def_id(self.get_module_parent_node(id))
769766
}
770767

771768
/// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no
@@ -841,7 +838,7 @@ impl<'hir> Map<'hir> {
841838
}
842839

843840
pub fn get_parent_did(&self, id: HirId) -> DefId {
844-
self.local_def_id_from_hir_id(self.get_parent_item(id))
841+
self.local_def_id(self.get_parent_item(id))
845842
}
846843

847844
pub fn get_foreign_abi(&self, hir_id: HirId) -> Abi {
@@ -1247,7 +1244,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
12471244
// the user-friendly path, otherwise fall back to stringifying DefPath.
12481245
crate::ty::tls::with_opt(|tcx| {
12491246
if let Some(tcx) = tcx {
1250-
let def_id = map.local_def_id_from_hir_id(id);
1247+
let def_id = map.local_def_id(id);
12511248
tcx.def_path_str(def_id)
12521249
} else if let Some(path) = map.def_path_from_hir_id(id) {
12531250
path.data.into_iter().map(|elem| {

src/librustc/hir/upvars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> {
8383

8484
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
8585
if let hir::ExprKind::Closure(..) = expr.node {
86-
let closure_def_id = self.tcx.hir().local_def_id_from_hir_id(expr.hir_id);
86+
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
8787
if let Some(upvars) = self.tcx.upvars(closure_def_id) {
8888
// Every capture of a closure expression is a local in scope,
8989
// that is moved/copied/borrowed into the closure value, and

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
139139
// error. We will then search the function parameters for a bound
140140
// region at the right depth with the same index
141141
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
142-
debug!(
143-
"EarlyBound self.infcx.tcx.hir().local_def_id(id)={:?} \
144-
def_id={:?}",
145-
id,
146-
def_id
147-
);
142+
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
148143
if id == def_id {
149144
self.found_type = Some(arg);
150145
return; // we can stop visiting now
@@ -162,8 +157,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
162157
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
163158
debruijn_index
164159
);
165-
debug!("self.infcx.tcx.hir().local_def_id(id)={:?}", id);
166-
debug!("def_id={:?}", def_id);
160+
debug!("LateBound id={:?} def_id={:?}", id, def_id);
167161
if debruijn_index == self.current_index && id == def_id {
168162
self.found_type = Some(arg);
169163
return; // we can stop visiting now
@@ -231,12 +225,7 @@ impl Visitor<'tcx> for TyPathVisitor<'tcx> {
231225
}
232226

233227
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
234-
debug!(
235-
"EarlyBound self.infcx.tcx.hir().local_def_id(id)={:?} \
236-
def_id={:?}",
237-
id,
238-
def_id
239-
);
228+
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
240229
if id == def_id {
241230
self.found_it = true;
242231
return; // we can stop visiting now

src/librustc/infer/opaque_types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
951951
let parent_def_id = self.parent_def_id;
952952
let def_scope_default = || {
953953
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
954-
parent_def_id
955-
== tcx.hir().local_def_id_from_hir_id(opaque_parent_hir_id)
954+
parent_def_id == tcx.hir()
955+
.local_def_id(opaque_parent_hir_id)
956956
};
957957
let (in_definition_scope, origin) = match tcx.hir().find(opaque_hir_id) {
958958
Some(Node::Item(item)) => match item.node {

src/librustc/lint/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
926926
{
927927
let old_param_env = self.context.param_env;
928928
self.context.param_env = self.context.tcx.param_env(
929-
self.context.tcx.hir().local_def_id_from_hir_id(id)
929+
self.context.tcx.hir().local_def_id(id)
930930
);
931931
f(self);
932932
self.context.param_env = old_param_env;
@@ -1501,7 +1501,7 @@ pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
15011501
time(tcx.sess, "module lints", || {
15021502
// Run per-module lints
15031503
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
1504-
tcx.ensure().lint_mod(tcx.hir().local_def_id(module));
1504+
tcx.ensure().lint_mod(tcx.hir().local_def_id_from_node_id(module));
15051505
});
15061506
});
15071507
});

src/librustc/middle/dead.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
161161
Node::Item(item) => {
162162
match item.node {
163163
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
164-
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
164+
let def_id = self.tcx.hir().local_def_id(item.hir_id);
165165
let def = self.tcx.adt_def(def_id);
166166
self.repr_has_repr_c = def.repr.c();
167167

@@ -325,7 +325,7 @@ fn has_allow_dead_code_or_lang_attr(
325325
return true;
326326
}
327327

328-
let def_id = tcx.hir().local_def_id_from_hir_id(id);
328+
let def_id = tcx.hir().local_def_id(id);
329329
let cg_attrs = tcx.codegen_fn_attrs(def_id);
330330

331331
// #[used], #[no_mangle], #[export_name], etc also keeps the item alive
@@ -494,7 +494,7 @@ impl DeadVisitor<'tcx> {
494494
}
495495

496496
fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
497-
let field_type = self.tcx.type_of(self.tcx.hir().local_def_id_from_hir_id(field.hir_id));
497+
let field_type = self.tcx.type_of(self.tcx.hir().local_def_id(field.hir_id));
498498
!field.is_positional()
499499
&& !self.symbol_is_live(field.hir_id)
500500
&& !field_type.is_phantom_data()
@@ -525,7 +525,7 @@ impl DeadVisitor<'tcx> {
525525
// This is done to handle the case where, for example, the static
526526
// method of a private type is used, but the type itself is never
527527
// called directly.
528-
let def_id = self.tcx.hir().local_def_id_from_hir_id(id);
528+
let def_id = self.tcx.hir().local_def_id(id);
529529
let inherent_impls = self.tcx.inherent_impls(def_id);
530530
for &impl_did in inherent_impls.iter() {
531531
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {

0 commit comments

Comments
 (0)