-
Couldn't load subscription status.
- Fork 13.9k
Description
During AST->HIR lowering, the method lower_node_id is tasked to transform NodeIds that identify AST nodes into HirIds that identify HIR nodes. This method maintains a node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId> to remember this mapping.
However, this mapping is not entirely useful, and mostly exists (1) to make the developer's life easier, (2) to lower resolutions to local bindings Res::Local in lower_res. The mapping node_id_to_local_id should be removed, and multiple calls to local_node_id with the same NodeId should be forbidden. For usage (2), Res::Local only appears for ident patterns (PatKind::Ident) which are lowered by lower_pat_ident. Hence, lower_res should use a dedicated hash-map filled by lower_pat_ident.
Furthermore, next_id calls lower_node_id with a node_id: NodeId which is entirely local to that function, and will never be known to any other code. Manipulations of node_id_to_local_id there are entirely useless.
Instructions:
- inline
lower_node_idintonext_idand skip manipulations ofnode_id_to_local_id; - replace the
Entry::Occupiedbranch inlower_node_idby apanic!, and fix all the ICEs; - create another mapping
node_id_to_local_id_for_res(name to bikeshed) which is only filled bylower_pat_identand read bylower_res; this mapping should be saved bywith_hir_id_ownerlikenode_id_to_local_idis; - remove
node_id_to_local_id, or eventually keep it only to debug-assert that we don't calllower_node_idtwice on the sameNodeId.