Commit 621fc16
authored
Fix NodeId->HirId lookups by carrying structural context (#1445)
c2rust-refactor would fail due to invalid AST node <-> HIR mappings.
This was caused by insufficient disambiguation due to all
c2rust-bitfield-derived expanded code sharing the same span with
call_site. This PR addresses the aforemented issue by threading
structural context through the AST and HIR walkers so NodeId-HirId
lookups stay precise even when spans collide.
- Added `child_slot`, `NodeContextKey`, and `StructuralContext` helpers
to record hierarchical positions for AST nodes; mirrored the same
traversal on the HIR side and stitched the maps together during `HirMap`
construction
- Collapsed wrapper nodes derived accessors and helper shims would erase
array/tuple shells on the expression side, leaving `Leaf` nodes that
conflicted with the HIR/type view where the same values remained wrapped
(e.g. `[u8; 3]` -> `Node([Leaf(u8)])`). We now detect those single-child
wrappers, peel just enough layers to expose the matching field list, and
otherwise panic with a targeted message if the arity still disagrees.
I tried going down another path with more-specific spans, such as using
quote_spanned!(field.field_name.span()), using fresh spans with
Span::def_site().located_at(old_span), and using attribute metadata
(with meta_name_value.lit.span(), but kept running into issues and so
abandoned that path.File tree
4 files changed
+790
-45
lines changed- c2rust-refactor/src
- ast_manip
- transform
4 files changed
+790
-45
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
0 commit comments