refactor: widen definitions that header declarations are matched to - #1937
Open
ahomescu wants to merge 2 commits into
Conversation
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 01:40
8cb0857 to
7a0502c
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 01:58
7a0502c to
5de2b14
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 02:08
5de2b14 to
5918d0c
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 02:11
5918d0c to
f603f8a
Compare
ahomescu
changed the base branch from
ahomescu/fix_reorganize_definitions/compare_extern_fn_sigs
to
ahomescu/fix_reorganize_definitions/canonicalize_moved_paths
July 25, 2026 02:16
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 02:16
f603f8a to
4363bbc
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 02:35
4363bbc to
2713866
Compare
ahomescu
changed the base branch from
ahomescu/fix_reorganize_definitions/canonicalize_moved_paths
to
ahomescu/fix_reorganize_definitions/compare_extern_fn_sigs
July 25, 2026 03:17
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 03:17
2713866 to
158225c
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 05:09
158225c to
7ab6fcf
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 05:33
7ab6fcf to
94479f6
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 05:41
94479f6 to
b9966f7
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 05:42
b9966f7 to
8d4820a
Compare
ahomescu
changed the base branch from
ahomescu/fix_reorganize_definitions/compare_extern_fn_sigs
to
ahomescu/fix_reorganize_definitions/deterministic_externs
July 25, 2026 05:42
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 05:48
8d4820a to
d5e8b27
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 05:52
d5e8b27 to
2e44580
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 05:59
2e44580 to
f942eb6
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 06:05
f942eb6 to
e527aa4
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 06:16
e527aa4 to
74ced24
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
2 times, most recently
from
July 25, 2026 06:43
f243b12 to
713177e
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 25, 2026 06:51
713177e to
4ed9f3d
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
2 times, most recently
from
July 30, 2026 00:19
65b1320 to
c721b16
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
2 times, most recently
from
July 30, 2026 22:54
66c4b7f to
f6d4751
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 30, 2026 22:56
f6d4751 to
724b211
Compare
…ition
Regression test: `test_reorganize_private_no_mangle_def`
(`tests/snapshots/reorganize_private_no_mangle_def.rs`). `def::counter`
carries `#[no_mangle]` but no `pub`, and `user` includes a header declaring
it. `match_defs` only considers definitions that `is_exported` accepts,
which for a value means it carries `#[no_mangle]` or `#[export_name]` — a
statement about the C symbol being visible to another translation unit, not
about Rust visibility. So the declaration is matched to the definition and
`user::read` is rewritten to `crate::def::counter`, naming an item that is
private to `def`:
error[E0603]: static `counter` is private
The recorded output shows the rewritten path next to the still-private
definition, with `new_expect_compile_error` marking the state as broken.
This is the second reason the output of `test_reorganize_definitions` does
not compile, reduced to one definition and one reference.
`match_defs` replaces a header declaration with a definition found elsewhere
in the crate and rewrites every path to the declaration to point at that
definition. It only accepts a definition `is_exported` agrees is exported,
but for a value that asks whether the item carries `#[no_mangle]` or
`#[export_name]` — whether the C symbol reaches another translation unit,
which says nothing about Rust visibility. A `#[no_mangle]` static private to
its module qualifies, and the paths rewritten to name it come from other
modules, which cannot:
error[E0603]: static `counter` is private
`match_defs` now records each matched definition that is not `pub`, and
`widen_matched_defs` joins its visibility with `pub(crate)` — enough because
every path that now points at it is in this crate. This is the pass the
commented-out `imports` field on `HeaderDeclarations` anticipated ("must be
made pub(crate) at least").
With this and the previous commit, the output of `test_reorganize_definitions`
compiles for the first time, so its `new_expect_compile_error` is dropped
too; the only change to that snapshot here is `Bar` gaining `pub(crate)`.
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/widen_matched_defs
branch
from
July 30, 2026 22:58
724b211 to
0f84b7d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack created with GitHub Stacks CLI • Give Feedback 💬