rust-lang / rust-lang/rust-analyzer
Reports false type errors on macro, but actually compiles without errors
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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