Skip to content

Failure to analyze valid code #21034

@Demiu

Description

@Demiu

rust-analyzer version: rust-analyzer version: 0.3.2675-standalone (21f8445 2025-11-09)

rustc version: rustc 1.90.0 (1159e78c4 2025-09-14)

editor or extension: VS Code

relevant settings: nothing out of ordinary

code snippet to reproduce:

use std::ops::Deref;

struct Base;

impl Base {
    fn func(&self) -> i32 { 111 }
}

trait BaseLayerOne: Deref<Target = Base>{}

trait BaseLayerTwo: BaseLayerOne {}

impl<T> BaseLayerOne for T
where
    T: BaseLayerTwo + 'static,
{
}

struct BaseLayerThree(Box<dyn BaseLayerTwo>);

impl Deref for BaseLayerThree {
    type Target = dyn BaseLayerTwo;

    fn deref(&self) -> &Self::Target {
        self.0.deref()
    }
}

struct NonBase(Base);

impl Deref for NonBase {
    type Target = Base;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl BaseLayerTwo for NonBase {}

fn main() {
    let t = BaseLayerThree(Box::new(NonBase(Base)));
    let r = t.func();
    println!("{r}");
}

cargo/rustc has no problem with this, rust-analyzer gives up at recognizing the t.func() call "Go to Definition" doesn't work and r's type is {unknown} on hover. This is a based on real code (from fyrox).

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