Skip to content

test(rust): lock in path-qualifier preservation (#2)#4

Merged
iray-tno merged 1 commit into
mainfrom
feature/2_stop_stripping_module_qualifiers
Jun 3, 2026
Merged

test(rust): lock in path-qualifier preservation (#2)#4
iray-tno merged 1 commit into
mainfrom
feature/2_stop_stripping_module_qualifiers

Conversation

@iray-tno
Copy link
Copy Markdown
Owner

@iray-tno iray-tno commented Jun 3, 2026

Closes #2.

Background

The old "strip module qualifiers" step rewrote every X:: it saw, keeping only std/core/alloc. Because it inspected just the single token immediately before ::, it mangled valid paths:

  • std sub-modules: std::collections::HashMapstd::HashMap, std::cmp::Reversestd::Reverse
  • associated functions: HashMap::new()new(), Vec::new()new()
  • crate-internal paths: crate::foo::Itemcrate::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:

  • Adds a qualified_paths fixture exercising exactly the issue's cases — std::collections::HashMap, std::cmp::Reverse, HashMap::new(), Vec::new(), and a crate-internal helpers::scale::by_two multi-segment path.
  • Adds a regression test asserting all path segments survive preprocessing (and that the mangled forms like std::HashMap do not appear).
  • Adds an rustc compile check on the output (skips automatically when rustc is unavailable).

Tests

Full suite green; the new fixture preprocesses with every qualifier intact and compiles/runs under rustc (edition 2021).

🤖 Generated with Claude Code

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>
@iray-tno iray-tno merged commit 6abc0a8 into main Jun 3, 2026
2 checks passed
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.

rust preprocess: module-qualifier stripping removes valid path segments (std sub-modules, Type::method)

1 participant