Skip to content

refactor: keep the original symbol when renaming an extern declaration - #1945

Merged
ahomescu merged 2 commits into
masterfrom
ahomescu/fix_reorganize_definitions/preserve_extern_link_name
Jul 30, 2026
Merged

ahomescu merged 2 commits into
masterfrom
ahomescu/fix_reorganize_definitions/preserve_extern_link_name

Conversation

@ahomescu

Copy link
Copy Markdown
Contributor

Fresh copy of #1935 since I closed that one.


Stack created with GitHub Stacks CLI • Give Feedback 💬

@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch from be5a534 to 3ba5ded Compare July 25, 2026 03:13
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch from 3ba5ded to c4d9955 Compare July 25, 2026 03:17
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch from c4d9955 to 0f16dcf Compare July 25, 2026 03:26
@ahomescu
ahomescu changed the base branch from ahomescu/fix_reorganize_definitions/non_ascii_idents to master July 25, 2026 05:09
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch from 0f16dcf to 372a77b Compare July 25, 2026 05:09
@ahomescu
ahomescu marked this pull request as ready for review July 25, 2026 05:09
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch from 372a77b to 10fb614 Compare July 25, 2026 05:33
@ahomescu
ahomescu requested a review from thedataking July 25, 2026 05:33
Comment thread c2rust-refactor/src/transform/reorganize_definitions.rs Outdated
Comment thread c2rust-refactor/src/transform/reorganize_definitions.rs
Comment thread c2rust-refactor/src/transform/reorganize_definitions.rs Outdated
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch from 10fb614 to c0eb1ca Compare July 29, 2026 23:18
`test_reorganize_foreign_item_rename` records the wrong output
`reorganize_definitions` currently produces when it renames a foreign item.
Two modules include the same header under different `-D` flags, so their
declarations land in one header module but neither the `static` pair nor the
`fn` pair can be collapsed, and the second of each is renamed to `cfg_1` and
`compute_1`.
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch 2 times, most recently from 2b9dc2b to 37fea26 Compare July 30, 2026 00:31
Comment thread c2rust-refactor/src/transform/reorganize_definitions.rs Outdated
When two declarations of the same name cannot be collapsed, `move_items`
appends a numeric suffix to the second one. That is harmless for a regular
item, which is mangled under its own path, but a foreign function or static
links against its own name, so renaming it points at a symbol that does not
exist and nothing reports it until link time.

`MovedDecl::preserve_link_name` now adds a `#[link_name]` with the original
name before changing the ident. It applies only to `ForeignItemKind::Fn` and
`Static` (an `extern type` has no symbol) and leaves an existing
`#[link_name]` alone.
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch from 37fea26 to 9ad3bea Compare July 30, 2026 22:54
@ahomescu
ahomescu merged commit 908526a into master Jul 30, 2026
@ahomescu
ahomescu deleted the ahomescu/fix_reorganize_definitions/preserve_extern_link_name branch July 30, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants