rust-lang / rust-lang/rust-analyzer

Reports false type errors on macro, but actually compiles without errors

Open
#21,837 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macro A-nameres C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: 0.3.2828-standalone

rustc version: rustc 1.90.0 (1159e78c4 2025-09-14) ~ rustc 1.94.0 (4a4ef493e 2026-03-02)

editor or extension: VSCode 1.109.5

code snippet to reproduce:

use ambassador::{Delegate, delegatable_trait};

#[delegatable_trait]
pub trait Shout {
    fn shout(&self, input: &str) -> String;
}

pub struct Cat;

impl Shout for Cat {
    fn shout(&self, input: &str) -> String {
        format!("{} - meow!", input)
    }
}

pub struct Dog;

impl Shout for Dog {
    fn shout(&self, input: &str) -> String {
        format!("{} - wuff!", input)
    }
}

#[derive(Delegate)]
#[delegate(Shout)]
pub enum Animal {
    Cat(Cat),
    Dog(Dog),
}

pub fn main() {
    let foo_animal = Animal::Cat(Cat);
    println!("{}", foo_animal.shout("BAR"));
}

Simply run the example code from the ambassador crate documentation: https://crates.io/crates/ambassador

rust-analyzer reports errors:

---> #[derive(Delegate)]
expected &{unknown}, found Dog rust-analyzer(E0308)
expected &{unknown}, found Cat rust-analyzer(E0308)

However, there are actually no errors, and the macro-expanded code compiles successfully.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ambassador example from the issue and compare rust-analyzer's E0308 diagnostics with the successfully compiled macro-expanded code. The issue is done when the false errors on #[derive(Delegate)] no longer appear while genuine type errors remain detectable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.