Skip to content

Rust: a receiver of a non-std crate type binds a same-named project method (the #2053 guard covers std and seeded crates only) #3007

Open

Description

@madebymlai

Version

v0.12.1 release binary, Linux (x64). The guard is unchanged on main @ cdfdf26.

What happened, and what did you expect?

#2339 (for #2053) stops the registry fallback when the Rust LSP places a call on a std or seeded-crate symbol (cbm_pipeline_rust_external_target). A receiver whose type comes from any other crate, such as an ordinary crates.io dependency, gets no LSP target. The textual registry then binds the call by name to a same-named project method of an unrelated type, at 0.55 here. This happens in both resolvers.

Expected: no CALLS edge from bar.id() to a project method of another type when bar is declared as extcrate::Bar, a path rooted in a dependency rather than in crate/self/super or a workspace crate. A project trait method implemented for that type (impl MyTrait for extcrate::Bar) would remain a valid target.

Reproduction

Cargo.toml ([dependencies] extcrate = "1", never built), src/lib.rs declaring the two modules below.

// src/series.rs
use extcrate::Bar;

pub struct Slice(pub u32);

impl Slice {
    pub fn id(&self) -> u32 {
        self.0
    }
}

pub enum Series {
    Bars(Bar),
}

impl Series {
    /// `bar` is extcrate's Bar: calls Bar::id. Must not bind Slice::id or Series::id.
    pub fn id(&self) -> u32 {
        match self {
            Self::Bars(bar) => bar.id(),
        }
    }
}
// src/user.rs
use extcrate::Bar;

/// Typed parameter of an external crate type. Must not bind a project `id`.
pub fn typed_param(bar: &Bar) -> u32 {
    bar.id()
}

/// Closure parameter over a slice of an external type. Must not bind a project `id`.
pub fn closure_param(bars: &[Bar]) -> Vec<u32> {
    bars.iter().map(|bar| bar.id()).collect()
}
codebase-memory-mcp cli index_repository '{"repo_path":"<repro>"}'
codebase-memory-mcp cli query_graph '{"project":"<p>","query":"MATCH (a)-[r:CALLS]->(b) WHERE b.name = \"id\" RETURN a.name, b.qualified_name, r.strategy, r.confidence"}'
caller sequential parallel (+55 pad files)
typed_param src.series.Series.id, suffix_match, 0.55 same
closure_param src.series.Series.id, suffix_match, 0.55 same

Both edges are fabricated: the callee is extcrate::Bar::id, which has no node in the graph. The match-arm call inside Series::id produced no edge.

Related: #2053 and #2339 (the same mechanism for std receivers), #2923 (no external-crate guard on Rust use paths) and #2892 (C#).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    editor/integrationEditor compatibility and CLI integrationparsing/qualityGraph extraction bugs, false positives, missing edges

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions