Skip to content

Commit 37a9f46

Browse files
camelidjyn514
authored andcommitted
Update HIR chapter to use HirId instead of NodeId
`NodeId`s are no longer used in the HIR. See rust-lang#50928 for more information.
1 parent ab15a05 commit 37a9f46

File tree

1 file changed

+7
-12
lines changed
  • src/doc/rustc-dev-guide/src

1 file changed

+7
-12
lines changed

src/doc/rustc-dev-guide/src/hir.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,16 @@ with a HIR node.
9696
[HIR map]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html
9797
[number of methods]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#methods
9898

99-
For example, if you have a [`DefId`], and you would like to convert it
100-
to a [`NodeId`], you can use
101-
[`tcx.hir().as_local_node_id(def_id)`][as_local_node_id]. This returns
102-
an `Option<NodeId>` – this will be `None` if the def-id refers to
103-
something outside of the current crate (since then it has no HIR
104-
node), but otherwise returns `Some(n)` where `n` is the node-id of the
105-
definition.
99+
For example, if you have a [`LocalDefId`], and you would like to convert it
100+
to a [`HirId`], you can use [`tcx.hir().local_def_id_to_hir_id(def_id)`][local_def_id_to_hir_id].
101+
You need a `LocalDefId`, rather than a `DefId`, since only local items have HIR nodes.
106102

107-
[`NodeId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/node_id/struct.NodeId.html
108-
[as_local_node_id]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.as_local_node_id
103+
[local_def_id_to_hir_id]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.local_def_id_to_hir_id
109104

110105
Similarly, you can use [`tcx.hir().find(n)`][find] to lookup the node for a
111-
[`NodeId`]. This returns a `Option<Node<'tcx>>`, where [`Node`] is an enum
112-
defined in the map; by matching on this you can find out what sort of
113-
node the node-id referred to and also get a pointer to the data
106+
[`HirId`]. This returns a `Option<Node<'hir>>`, where [`Node`] is an enum
107+
defined in the map. By matching on this, you can find out what sort of
108+
node the `HirId` referred to and also get a pointer to the data
114109
itself. Often, you know what sort of node `n` is – e.g. if you know
115110
that `n` must be some HIR expression, you can do
116111
[`tcx.hir().expect_expr(n)`][expect_expr], which will extract and return the

0 commit comments

Comments
 (0)