@@ -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
110105Similarly, 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
114109itself. Often, you know what sort of node ` n ` is – e.g. if you know
115110that ` 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