Skip to content

Commit 61964d9

Browse files
committed
replace some uses of NodeId with HirId
1 parent b01a257 commit 61964d9

File tree

26 files changed

+95
-190
lines changed

26 files changed

+95
-190
lines changed

src/librustc/cfg/construct.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG {
4242
let body_exit;
4343

4444
// Find the tables for this body.
45-
let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id()));
45+
let owner_hir_id = tcx.hir().body_owner(body.id());
46+
let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_hir_id);
4647
let tables = tcx.typeck_tables_of(owner_def_id);
4748

4849
let mut cfg_builder = CFGBuilder {

src/librustc/cfg/graphviz.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {
2222
impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
2323
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
2424
assert!(self.cfg.owner_def_id.is_local());
25-
let node_id = self.tcx.hir().hir_to_node_id(hir::HirId {
25+
let hir_id = hir::HirId {
2626
owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
2727
local_id
28-
});
29-
let s = self.tcx.hir().node_to_string(node_id);
28+
};
29+
let s = self.tcx.hir().hir_to_string(hir_id);
3030

3131
// Replacing newlines with \\l causes each line to be left-aligned,
3232
// improving presentation of (long) pretty-printed expressions.

src/librustc/hir/map/hir_id_validator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
122122
.find(|&(_, &entry)| hir_id == entry)
123123
.expect("no node_to_hir_id entry");
124124
let node_id = NodeId::from_usize(node_id);
125+
let hir_id = self.hir_map.node_to_hir_id(node_id);
125126
missing_items.push(format!("[local_id: {}, node:{}]",
126127
local_id,
127-
self.hir_map.node_to_string(node_id)));
128+
self.hir_map.hir_to_string(hir_id)));
128129
}
129130
self.error(|| format!(
130131
"ItemLocalIds not assigned densely in {}. \

src/librustc/hir/map/mod.rs

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,11 @@ impl<'hir> Map<'hir> {
286286
self.definitions.def_index_to_hir_id(def_index)
287287
}
288288

289-
#[inline]
290-
pub fn def_index_to_node_id(&self, def_index: DefIndex) -> NodeId {
291-
self.definitions.def_index_to_node_id(def_index)
292-
}
293-
294289
#[inline]
295290
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
296291
self.definitions.def_index_to_hir_id(def_id.to_def_id().index)
297292
}
298293

299-
#[inline]
300-
pub fn local_def_id_to_node_id(&self, def_id: LocalDefId) -> NodeId {
301-
self.definitions.as_local_node_id(def_id.to_def_id()).unwrap()
302-
}
303-
304294
fn def_kind(&self, node_id: NodeId) -> Option<DefKind> {
305295
let node = if let Some(node) = self.find(node_id) {
306296
node
@@ -422,12 +412,6 @@ impl<'hir> Map<'hir> {
422412
self.forest.krate.body(id)
423413
}
424414

425-
pub fn fn_decl(&self, node_id: ast::NodeId) -> Option<FnDecl> {
426-
let hir_id = self.node_to_hir_id(node_id);
427-
self.fn_decl_by_hir_id(hir_id)
428-
}
429-
430-
// FIXME(@ljedrz): replace the `NodeId` variant.
431415
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<FnDecl> {
432416
if let Some(entry) = self.find_entry(hir_id) {
433417
entry.fn_decl().cloned()
@@ -439,24 +423,18 @@ impl<'hir> Map<'hir> {
439423
/// Returns the `NodeId` that corresponds to the definition of
440424
/// which this is the body of, i.e., a `fn`, `const` or `static`
441425
/// item (possibly associated), a closure, or a `hir::AnonConst`.
442-
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId {
426+
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId {
443427
let parent = self.get_parent_node_by_hir_id(hir_id);
444428
assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id)));
445-
self.hir_to_node_id(parent)
429+
parent
446430
}
447431

448432
pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
449-
self.local_def_id(self.body_owner(id))
433+
self.local_def_id_from_hir_id(self.body_owner(id))
450434
}
451435

452-
/// Given a `NodeId`, returns the `BodyId` associated with it,
436+
/// Given a `HirId`, returns the `BodyId` associated with it,
453437
/// if the node is a body owner, otherwise returns `None`.
454-
pub fn maybe_body_owned_by(&self, id: NodeId) -> Option<BodyId> {
455-
let hir_id = self.node_to_hir_id(id);
456-
self.maybe_body_owned_by_by_hir_id(hir_id)
457-
}
458-
459-
// FIXME(@ljedrz): replace the `NodeId` variant.
460438
pub fn maybe_body_owned_by_by_hir_id(&self, hir_id: HirId) -> Option<BodyId> {
461439
if let Some(entry) = self.find_entry(hir_id) {
462440
if self.dep_graph.is_fully_enabled() {
@@ -479,12 +457,6 @@ impl<'hir> Map<'hir> {
479457
})
480458
}
481459

482-
pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind {
483-
let hir_id = self.node_to_hir_id(id);
484-
self.body_owner_kind_by_hir_id(hir_id)
485-
}
486-
487-
// FIXME(@ljedrz): replace the `NodeId` variant.
488460
pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind {
489461
match self.get_by_hir_id(id) {
490462
Node::Item(&Item { node: ItemKind::Const(..), .. }) |
@@ -793,17 +765,10 @@ impl<'hir> Map<'hir> {
793765
self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok()
794766
}
795767

796-
/// Retrieves the `NodeId` for `id`'s parent item, or `id` itself if no
768+
/// Retrieves the `HirId` for `id`'s parent item, or `id` itself if no
797769
/// parent item is in this map. The "parent item" is the closest parent node
798770
/// in the HIR which is recorded by the map and is an item, either an item
799771
/// in a module, trait, or impl.
800-
pub fn get_parent(&self, id: NodeId) -> NodeId {
801-
let hir_id = self.node_to_hir_id(id);
802-
let parent_hir_id = self.get_parent_item(hir_id);
803-
self.hir_to_node_id(parent_hir_id)
804-
}
805-
806-
// FIXME(@ljedrz): replace the `NodeId` variant.
807772
pub fn get_parent_item(&self, hir_id: HirId) -> HirId {
808773
match self.walk_parent_nodes(hir_id, |node| match *node {
809774
Node::Item(_) |
@@ -819,12 +784,6 @@ impl<'hir> Map<'hir> {
819784

820785
/// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
821786
/// module parent is in this map.
822-
pub fn get_module_parent(&self, id: NodeId) -> DefId {
823-
let hir_id = self.node_to_hir_id(id);
824-
self.get_module_parent_by_hir_id(hir_id)
825-
}
826-
827-
// FIXME(@ljedrz): replace the `NodeId` variant.
828787
pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId {
829788
self.local_def_id_from_hir_id(self.get_module_parent_node(id))
830789
}
@@ -901,22 +860,10 @@ impl<'hir> Map<'hir> {
901860
Some(scope)
902861
}
903862

904-
pub fn get_parent_did(&self, id: NodeId) -> DefId {
905-
let hir_id = self.node_to_hir_id(id);
906-
self.get_parent_did_by_hir_id(hir_id)
907-
}
908-
909-
// FIXME(@ljedrz): replace the `NodeId` variant.
910863
pub fn get_parent_did_by_hir_id(&self, id: HirId) -> DefId {
911864
self.local_def_id_from_hir_id(self.get_parent_item(id))
912865
}
913866

914-
pub fn get_foreign_abi(&self, id: NodeId) -> Abi {
915-
let hir_id = self.node_to_hir_id(id);
916-
self.get_foreign_abi_by_hir_id(hir_id)
917-
}
918-
919-
// FIXME(@ljedrz): replace the `NodeId` variant.
920867
pub fn get_foreign_abi_by_hir_id(&self, hir_id: HirId) -> Abi {
921868
let parent = self.get_parent_item(hir_id);
922869
if let Some(entry) = self.find_entry(parent) {
@@ -930,12 +877,6 @@ impl<'hir> Map<'hir> {
930877
bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent))
931878
}
932879

933-
pub fn expect_item(&self, id: NodeId) -> &'hir Item {
934-
let hir_id = self.node_to_hir_id(id);
935-
self.expect_item_by_hir_id(hir_id)
936-
}
937-
938-
// FIXME(@ljedrz): replace the `NodeId` variant.
939880
pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item {
940881
match self.find_by_hir_id(id) { // read recorded by `find`
941882
Some(Node::Item(item)) => item,
@@ -1024,12 +965,6 @@ impl<'hir> Map<'hir> {
1024965

1025966
/// Given a node ID, gets a list of attributes associated with the AST
1026967
/// corresponding to the node-ID.
1027-
pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
1028-
let hir_id = self.node_to_hir_id(id);
1029-
self.attrs_by_hir_id(hir_id)
1030-
}
1031-
1032-
// FIXME(@ljedrz): replace the `NodeId` variant.
1033968
pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] {
1034969
self.read(id); // reveals attributes on the node
1035970
let attrs = match self.find_entry(id).map(|entry| entry.node) {
@@ -1093,12 +1028,6 @@ impl<'hir> Map<'hir> {
10931028
})
10941029
}
10951030

1096-
pub fn span(&self, id: NodeId) -> Span {
1097-
let hir_id = self.node_to_hir_id(id);
1098-
self.span_by_hir_id(hir_id)
1099-
}
1100-
1101-
// FIXME(@ljedrz): replace the `NodeId` variant.
11021031
pub fn span_by_hir_id(&self, hir_id: HirId) -> Span {
11031032
self.read(hir_id); // reveals span from node
11041033
match self.find_entry(hir_id).map(|entry| entry.node) {
@@ -1139,32 +1068,17 @@ impl<'hir> Map<'hir> {
11391068
}
11401069

11411070
pub fn span_if_local(&self, id: DefId) -> Option<Span> {
1142-
self.as_local_node_id(id).map(|id| self.span(id))
1071+
self.as_local_hir_id(id).map(|id| self.span_by_hir_id(id))
11431072
}
11441073

1145-
pub fn node_to_string(&self, id: NodeId) -> String {
1146-
hir_id_to_string(self, self.node_to_hir_id(id), true)
1147-
}
1148-
1149-
// FIXME(@ljedrz): replace the `NodeId` variant.
11501074
pub fn hir_to_string(&self, id: HirId) -> String {
11511075
hir_id_to_string(self, id, true)
11521076
}
11531077

1154-
pub fn node_to_user_string(&self, id: NodeId) -> String {
1155-
hir_id_to_string(self, self.node_to_hir_id(id), false)
1156-
}
1157-
1158-
// FIXME(@ljedrz): replace the `NodeId` variant.
11591078
pub fn hir_to_user_string(&self, id: HirId) -> String {
11601079
hir_id_to_string(self, id, false)
11611080
}
11621081

1163-
pub fn node_to_pretty_string(&self, id: NodeId) -> String {
1164-
print::to_string(self, |s| s.print_node(self.get(id)))
1165-
}
1166-
1167-
// FIXME(@ljedrz): replace the `NodeId` variant.
11681082
pub fn hir_to_pretty_string(&self, id: HirId) -> String {
11691083
print::to_string(self, |s| s.print_node(self.get_by_hir_id(id)))
11701084
}

src/librustc/hir/upvars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub fn provide(providers: &mut Providers<'_>) {
1414
return None;
1515
}
1616

17-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
18-
let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(node_id)?);
17+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
18+
let body = tcx.hir().body(tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)?);
1919

2020
let mut local_collector = LocalCollector::default();
2121
local_collector.visit_body(body);

src/librustc/infer/error_reporting/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> {
8686
)
8787
};
8888
let span = scope.span(self, region_scope_tree);
89-
let tag = match self.hir().find(scope.node_id(self, region_scope_tree)) {
89+
let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) {
9090
Some(Node::Block(_)) => "block",
9191
Some(Node::Expr(expr)) => match expr.node {
9292
hir::ExprKind::Call(..) => "call",
@@ -1330,15 +1330,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13301330
if !param.is_self() {
13311331
let type_param = generics.type_param(param, self.tcx);
13321332
let hir = &self.tcx.hir();
1333-
hir.as_local_node_id(type_param.def_id).map(|id| {
1333+
hir.as_local_hir_id(type_param.def_id).map(|id| {
13341334
// Get the `hir::Param` to verify whether it already has any bounds.
13351335
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
13361336
// instead we suggest `T: 'a + 'b` in that case.
13371337
let mut has_bounds = false;
1338-
if let Node::GenericParam(ref param) = hir.get(id) {
1338+
if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) {
13391339
has_bounds = !param.bounds.is_empty();
13401340
}
1341-
let sp = hir.span(id);
1341+
let sp = hir.span_by_hir_id(id);
13421342
// `sp` only covers `T`, change it so that it covers
13431343
// `T:` when appropriate
13441344
let is_impl_trait = bound_kind.to_string().starts_with("impl ");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2828
) -> Option<(&hir::Ty, &hir::FnDecl)> {
2929
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3030
let def_id = anon_reg.def_id;
31-
if let Some(node_id) = self.tcx().hir().as_local_node_id(def_id) {
32-
let fndecl = match self.tcx().hir().get(node_id) {
31+
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
32+
let fndecl = match self.tcx().hir().get_by_hir_id(hir_id) {
3333
Node::Item(&hir::Item {
3434
node: hir::ItemKind::Fn(ref fndecl, ..),
3535
..

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4848
if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
4949
&RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
5050
let hir = &self.tcx().hir();
51-
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
51+
if let Some(hir_id) = hir.as_local_hir_id(free_region.scope) {
5252
if let Node::Expr(Expr {
5353
node: Closure(_, _, _, closure_span, None),
5454
..
55-
}) = hir.get(node_id) {
55+
}) = hir.get_by_hir_id(hir_id) {
5656
let sup_sp = sup_origin.span();
5757
let origin_sp = origin.span();
5858
let mut err = self.tcx().sess.struct_span_err(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5151
};
5252

5353
let hir = &self.tcx().hir();
54-
if let Some(node_id) = hir.as_local_node_id(id) {
55-
if let Some(body_id) = hir.maybe_body_owned_by(node_id) {
54+
if let Some(hir_id) = hir.as_local_hir_id(id) {
55+
if let Some(body_id) = hir.maybe_body_owned_by_by_hir_id(hir_id) {
5656
let body = hir.body(body_id);
5757
let owner_id = hir.body_owner(body_id);
58-
let fn_decl = hir.fn_decl(owner_id).unwrap();
58+
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
5959
if let Some(tables) = self.tables {
6060
body.arguments
6161
.iter()
6262
.enumerate()
6363
.filter_map(|(index, arg)| {
6464
// May return None; sometimes the tables are not yet populated.
6565
let ty_hir_id = fn_decl.inputs[index].hir_id;
66-
let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id));
66+
let arg_ty_span = hir.span_by_hir_id(ty_hir_id);
6767
let ty = tables.node_type_opt(arg.hir_id)?;
6868
let mut found_anon_region = false;
6969
let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {

0 commit comments

Comments
 (0)