Skip to content

Can't identify method related to Self in trait #21033

@lvyuemeng

Description

@lvyuemeng

rust-analyzer version: rust-analyzer version: 0.3.2675-standalone [/home/nostal/.vscode-server/extensions/rust-lang.rust-analyzer-0.3.2675-linux-x64/server/rust-analyzer]

rustc version: rustc 1.93.0-nightly (bd3ac0330 2025-11-01)

editor or extension: VScode with rust-analyzer

relevant settings:

The only important setting is "rust-analyzer.diagnostics.experimental.enable": true,, which will give error complain on below minimal code.

    "rust-analyzer.diagnostics.experimental.enable": true,

code snippet to reproduce:

Below code works fine.

struct PBox<T, A>(T, A);

impl<T, A> PBox<T, A> {
    fn token_with(self) -> usize {
        0
    }
}

trait MoveMessage {
    fn token<A>(self, alloc: A) -> usize
    where
        Self: Sized,
    {
        let b = PBox::<Self, A>(self, alloc);
        let t = b.token_with(); // RA complains: no method `token_with`
        t
    }
}

#[test]
fn works() {
    struct Msg(u32);
    impl MoveMessage for Msg {}

    let msg = Msg(1);
    let token = msg.token("alloc");
    println!("token: {}",token)
}

Metadata

Metadata

Labels

A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions