fix(rust): resolve bare calls through exact use bindings - #2308
Open
danusha2345 wants to merge 1 commit into
Open
danusha2345 wants to merge 1 commit into
danusha2345 wants to merge 1 commit into
Conversation
A bare call bound by a `use` (`use crate::util::take; take(3)`, also through `as` aliases, nested groups, `self`/`super`/`crate` paths and block-local imports) now resolves to the item that path names before name matching runs. A parameter, `let` or nested fn of that name still shadows the import. A binding the resolver cannot follow (another workspace crate, a `pub use` re-export, a relative path inside an inline module) keeps the previous resolution. A module path (`crate::util::take(3)`) names the module's own item: never a method, an associated item of an impl or trait body, or a fn-local item. A module-level item wins over an inline module's item reached through a re-export. Includes and supersedes colbymchenry#2259. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
danusha2345
force-pushed
the
codex/rust-exact-use-bindings
branch
from
October 3, 2026 09:09
fa3f3ac to
826c811
Compare
This branch has not been deployed
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
A bare Rust call never looked at the
usethat brought its name in. Withimported()was linked toa::take, andaliased()to the unrelateda::consume, because name matching only sees the local name. The same happened with nested groups (use crate::{util::{take as selected}, a::take as other}),self::/super::imports anduseinside a function body.A call written as a module path had a related problem (this is #2259):
crate::util::take(3),super::util::take(3)orutil::take(3)mapped the module prefix to the right file, then took the first node namedtakein it. Methods were an accepted kind, soimpl Buf { fn take }above the freepub fn takecaught every such call. Paths that end in the caller's own file (self::take(),crate::this_module::f()from inside it) andsuper::Itemfrom a submodule file were not resolved by the module walk at all.Fix
usebindings (rust-use-bindings.ts), parsed once per file per resolution pass and dropped with the other import-resolver memos. It knows whichuseis nearest to a source position (block and module scopes, nested groups,as,self, raw identifiers), and hides comments, strings and char literals. Globs bind no name and are skipped.resolveRustImportedCallruns before name matching for a bare Rust call. When ausebinds the name, the call goes to the item that path names: the module's free function, a crate-root item, an enum variant through its own enum, or a tuple-struct constructor. A parameter, aletalready in effect, or a nested fn of the same name still shadows the import.implortraitbody, never a fn-local item. A module-level item wins; with none, an item of an inline module reached through the module's re-export (#[cfg(…)] mod imp { … }pluspub use imp::*;, a common platform pattern). Two module-level items of one name are#[cfg]variants, and the first one stands for both.super::to the parent module's file, ends in the caller's own file forself::, and goes through an inline module (mod support { pub mod panic; }) to a file-backed submodule, including in Cargo's standalonetests/,examples/andbenches/files.EXTRACTION_VERSION27 → 28, since existing Rust indexes change.This PR includes #2259 (its source change and its whole test file) and supersedes it.
Deliberately left as before
A binding this resolver cannot follow keeps today's resolution, so nothing that resolves now goes unresolved:
use my_core::partition::read_table;),pub usere-export in the module the path names,useinside an inline module (mod tests { use super::parse; }),The exceptions are an alias whose path cannot be followed (
use external::take as consume;) and an enum without that variant: name matching on the local name could only find an unrelated item, so those calls stay unresolved. Glob imports (use super::*) and#[path]modules are left alone; #1892 covers that case and should compose with this.Tests
__tests__/rust-use-bindings.test.ts(17 cases): the binding parser by itself. Groups, aliases,self, raw identifiers, nearest-scope lookup, inline modules, comments and string kinds,letshadowing, UTF-16 columns and CRLF, and inline-module items told apart fromimpl/trait/macro bodies. It also coversimpl Trait + use<'a>(precise capturing), which must not read as an import.__tests__/rust-use-call.test.ts(15 cases) and__tests__/rust-module-path-call.test.ts(5 cases, fix(rust): a module path names the module's free function, not a method #2259's 4 plus an associated-type decoy). Each one indexes a real temporary Cargo project into SQLite: imported vs same-named decoys, aliases, groups,self/super, block-local imports, shadowing, enum variants, crate-root and same-file imports, a workspace crate by package name,mod tests { use super::…; },#[cfg]variants, an inline module's re-export, Unicode columns, and refresh after edit + sync. 17 of the 20 call-level cases fail on main.CODEGRAPH_KERNEL=0, as do the Rust cases ofextraction.test.ts.Real repositories (Rust edges, main → this branch)
super::unowned(…)reaching the test helper through its inline module's re-export, twocrate::sync::watch::channel(…)from insidewatch.rs, and twosupport::mpsc_stream::…from an integration test. 4SendError(value)constructions inmpscmoved frombroadcast::SendErrorto thempsc::error::SendErrortheirusenames. There are also 42 newuseimport edges, all checked, and 0 lost edges.crate::gnsstime::utc_to_gps_time(…)-style calls moved from the same-namedGnssTimeConvertermethods to the module's free functions, plus 7 import edges. All correct.use super::…import edges.🤖 Generated with Claude Code