@@ -96,21 +96,16 @@ with a HIR node.
96
96
[ HIR map ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html
97
97
[ number of methods ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#methods
98
98
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.
106
102
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
109
104
110
105
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
114
109
itself. Often, you know what sort of node ` n ` is – e.g. if you know
115
110
that ` n ` must be some HIR expression, you can do
116
111
[ ` tcx.hir().expect_expr(n) ` ] [ expect_expr ] , which will extract and return the
0 commit comments