test(rust): lock in path-qualifier preservation (#2)#4
Merged
Conversation
The old "strip module qualifiers" step rewrote every `X::` it saw, keeping
only `std`/`core`/`alloc`. Because it inspected just the single token before
`::`, it mangled valid paths:
- std sub-modules: `std::collections::HashMap` -> `std::HashMap`
- associated functions: `HashMap::new()` -> `new()`, `Vec::new()` -> `new()`
- crate-internal paths: `crate::foo::Item` -> `crate::Item`
Wrapping modules in `mod name { ... }` (#1) made every original path valid,
so the stripping step was removed entirely. This adds a fixture exercising
exactly those cases and a regression test (plus an rustc compile check)
asserting all path segments survive preprocessing, guarding against any
future reintroduction of qualifier rewriting.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Closes #2.
Background
The old "strip module qualifiers" step rewrote every
X::it saw, keeping onlystd/core/alloc. Because it inspected just the single token immediately before::, it mangled valid paths:std::collections::HashMap→std::HashMap,std::cmp::Reverse→std::ReverseHashMap::new()→new(),Vec::new()→new()crate::foo::Item→crate::Item…producing code that no longer compiled (
E0432,E0425).Resolution
As the issue itself recommended, the safest fix is to not strip qualifiers at all. Wrapping modules in
mod name { ... }(#1, merged) makes every original path valid, so the stripping step was removed entirely there.This PR locks that behavior in so it can't silently regress:
qualified_pathsfixture exercising exactly the issue's cases —std::collections::HashMap,std::cmp::Reverse,HashMap::new(),Vec::new(), and a crate-internalhelpers::scale::by_twomulti-segment path.std::HashMapdo not appear).rustccompile check on the output (skips automatically whenrustcis unavailable).Tests
Full suite green; the new fixture preprocesses with every qualifier intact and compiles/runs under
rustc(edition 2021).🤖 Generated with Claude Code