Repository navigation
fix(rust): a same-file path's inline module is read from its braces, not its indentation - #2713
Merged
Merged
Conversation
…not its indentation PR #2711 and PR #2702 landed a way each to tell which inline `mod` a place in a Rust file is in. #2711's isInRustInlineModule scanned lines upward for `mod <name> {` and trusted rustfmt's indentation to find where the block closes. #2702's rustModBlocks scans the braces, skipping strings, raw strings, char literals and comments, and keeps the result in rustUsesOf. isInRustInlineModule now asks rustBlockAt for the innermost block around the candidate, as rustDeclaredItems does, so there is one answer to that question. What changes: - An item written without indentation inside `mod flat { … }` is found through `flat::Flat`. The indentation rule rejected it. - `outer::Shell` is only `outer`'s own `Shell`, not one declared in a `mod deep` inside it. The upward scan accepted any item below the `mod outer {` line. - A file whose braces don't all close says nothing, as it does for the `use` walk of PR #2702. The A/B (main 818e780 vs this change; axum, tokio, clap, serde, ripgrep, gleam, dioxus, and the gin, serilog, flask and express controls) is byte-identical. rust-path-same-file.test.ts gains the two cases. The `flat::Flat` one fails on main. Co-Authored-By: Claude Opus 5.5 <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.
Problem
#2711 and #2702 each landed a way to tell which inline
moda place in a Rust file is in.isInRustInlineModuledecides whether a same-file candidate is what a path likeinner::Cellnames. It scanned lines upward formod <name> {and trusted rustfmt's indentation to find where the block closes.rustModBlocksscans the braces, skipping strings, raw strings, char literals and comments.rustUsesOfkeeps its result, andrustDeclaredItemsand theusewalk read it.Two answers to one question eventually disagree, and the indentation one was already wrong in two shapes:
mod flat { … }was out of reach offlat::Flat.outer::Shellaccepted aShelldeclared in amod deepinsideouter, because any item below themod outer {line counted.Fix
isInRustInlineModulenow asksrustBlockAtfor the innermost block around the candidate, asrustDeclaredItemsdoes. A file whose braces don't all close says nothing, as it does for #2702'susewalk.Verification
__tests__/rust-path-same-file.test.tsgains the two cases (flat::Flat,outer::Shell), on both engines.flat::Flatfails on main.outer::Shellhappens to reachouter's ownShellthrough the Rust framework rule at 0.7, since bothShells were in the running. Now it is the only candidate.tscis clean, and the Rust suites, fix(rust): a name a use brings in is the item of the module its path walks #2702's included, pass.CODEGRAPH_KERNEL_EXPECT=1 --maxWorkers=4 --minWorkers=1and the kernel built: 7,942 tests, 7,860 passed, 0 failed, 82 skipped.A/B on real repos
Arms: main 818e780, and this change on it. The repos are axum, tokio, clap, serde, ripgrep, gleam and dioxus, plus the gin, serilog, flask and express controls. Every dump is byte-identical: no real repo here has an item that the two answers disagree on.
🤖 Generated with Claude Code