Skip to content

Commit 2e86c00

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 b41a62e + a6030ff commit 2e86c00

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

+1-1
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

+1-1
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

-1
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

+3-2
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

+13-16
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

+1-1
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

+3-14
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

+2-2
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

+2-2
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

+4-4
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)[..] {

src/librustc/middle/entry.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct EntryContext<'a, 'tcx> {
3232

3333
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
3434
fn visit_item(&mut self, item: &'tcx Item) {
35-
let def_id = self.map.local_def_id_from_hir_id(item.hir_id);
35+
let def_id = self.map.local_def_id(item.hir_id);
3636
let def_key = self.map.def_key(def_id);
3737
let at_root = def_key.parent == Some(CRATE_DEF_INDEX);
3838
find_item(item, self, at_root);
@@ -142,11 +142,11 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
142142

143143
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(DefId, EntryFnType)> {
144144
if let Some((hir_id, _)) = visitor.start_fn {
145-
Some((tcx.hir().local_def_id_from_hir_id(hir_id), EntryFnType::Start))
145+
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Start))
146146
} else if let Some((hir_id, _)) = visitor.attr_main_fn {
147-
Some((tcx.hir().local_def_id_from_hir_id(hir_id), EntryFnType::Main))
147+
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
148148
} else if let Some((hir_id, _)) = visitor.main_fn {
149-
Some((tcx.hir().local_def_id_from_hir_id(hir_id), EntryFnType::Main))
149+
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
150150
} else {
151151
// No main function
152152
let mut err = struct_err!(tcx.sess, E0601,

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
930930
fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
931931
debug!("walk_captures({:?})", closure_expr);
932932

933-
let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id);
933+
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);
934934
if let Some(upvars) = self.tcx().upvars(closure_def_id) {
935935
for (&var_id, upvar) in upvars.iter() {
936936
let upvar_id = ty::UpvarId {

src/librustc/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
118118
match self.item_refs.get(&*value.as_str()).cloned() {
119119
// Known lang item with attribute on correct target.
120120
Some((item_index, expected_target)) if actual_target == expected_target => {
121-
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
121+
let def_id = self.tcx.hir().local_def_id(item.hir_id);
122122
self.collect_item(item_index, def_id);
123123
},
124124
// Known lang item with attribute on incorrect target.

src/librustc/middle/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn visit_fn<'tcx>(
363363
debug!("visit_fn");
364364

365365
// swap in a new set of IR maps for this function body:
366-
let def_id = ir.tcx.hir().local_def_id_from_hir_id(id);
366+
let def_id = ir.tcx.hir().local_def_id(id);
367367
let mut fn_maps = IrMaps::new(ir.tcx, def_id);
368368

369369
// Don't run unused pass for #[derive()]
@@ -494,7 +494,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr) {
494494
// in better error messages than just pointing at the closure
495495
// construction site.
496496
let mut call_caps = Vec::new();
497-
let closure_def_id = ir.tcx.hir().local_def_id_from_hir_id(expr.hir_id);
497+
let closure_def_id = ir.tcx.hir().local_def_id(expr.hir_id);
498498
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
499499
let parent_upvars = ir.tcx.upvars(ir.body_owner);
500500
call_caps.extend(upvars.iter().filter_map(|(&var_id, upvar)| {

src/librustc/middle/reachable.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item, attrs: CodegenFnAt
3535
match item.node {
3636
hir::ItemKind::Impl(..) |
3737
hir::ItemKind::Fn(..) => {
38-
let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(item.hir_id));
38+
let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id));
3939
generics.requires_monomorphization(tcx)
4040
}
4141
_ => false,
@@ -48,7 +48,7 @@ fn method_might_be_inlined(
4848
impl_src: DefId,
4949
) -> bool {
5050
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id.owner_def_id());
51-
let generics = tcx.generics_of(tcx.hir().local_def_id_from_hir_id(impl_item.hir_id));
51+
let generics = tcx.generics_of(tcx.hir().local_def_id(impl_item.hir_id));
5252
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
5353
return true
5454
}
@@ -222,7 +222,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
222222
} else {
223223
false
224224
};
225-
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
225+
let def_id = self.tcx.hir().local_def_id(item.hir_id);
226226
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
227227
let is_extern = codegen_attrs.contains_extern_indicator();
228228
let std_internal = codegen_attrs.flags.contains(
@@ -243,7 +243,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
243243
Node::Item(item) => {
244244
match item.node {
245245
hir::ItemKind::Fn(.., body) => {
246-
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
246+
let def_id = self.tcx.hir().local_def_id(item.hir_id);
247247
if item_might_be_inlined(self.tcx,
248248
&item,
249249
self.tcx.codegen_fn_attrs(def_id)) {
@@ -345,7 +345,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
345345
// Anything which has custom linkage gets thrown on the worklist no
346346
// matter where it is in the crate, along with "special std symbols"
347347
// which are currently akin to allocator symbols.
348-
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
348+
let def_id = self.tcx.hir().local_def_id(item.hir_id);
349349
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
350350
if codegen_attrs.contains_extern_indicator() ||
351351
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) {

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl<'tcx> ScopeTree {
675675
&format!("free_scope: {:?} not recognized by the \
676676
region scope tree for {:?} / {:?}",
677677
param_owner,
678-
self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)),
678+
self.root_parent.map(|id| tcx.hir().local_def_id(id)),
679679
self.root_body.map(|hir_id| DefId::local(hir_id.owner))));
680680
}
681681

0 commit comments

Comments
 (0)