Skip to content

Trait functions from foreign crates are not suggested #21413

@sshcrack

Description

@sshcrack

rust-analyzer version: rust-analyzer version: 0.3.2743-standalone (6a1246b 2026-01-04)

rustc version: rustc 1.91.1 (ed61e7d7e 2025-11-07)

editor or extension: VSCode v0.3.2743

relevant settings: No relevant settings

repository link (if public, optional): https://github.com/sshcrack/rust-analyzer-repro

code snippet to reproduce:

// This is crate test-implementation
//--
use test_trait::TestTrait;
pub struct TestStruct(pub usize);

impl TestTrait for TestStruct {
    fn test_function(&self) -> String {
        format!("TestStruct contains: {}", self.0)
    }
}
// ---
// Crate test-trait
pub trait TestTrait {
    fn test_function(&self) -> String;
}
// --
// Any other crate
use test_implementation::TestStruct;

fn main() {
    let test = TestStruct(42);
    // The test_function should be suggested by rust-analyzer but is not.
    test.test_function();

    println!("Hello, world!");
}

TLDR: If trait TestTrait is in crate A, struct TestStruct implements TestTrait in crate b, rust-analyzer will not pick up the autocomplete for any function in crate c, which has crate a and b as dependency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions