rust-lang / rust-lang/rust-analyzer
Misleading diagnostic for E0308 when short name `Error` shadows `std::io::Error` with imported `std::error::Error` trait
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Summary
When an unresolved identifier Error is auto-imported/resolved as std::error::Error (a trait) in a type annotation expecting a concrete struct like std::io::Error, the resulting E0308 type mismatch diagnostic prints identical short names (Error), omitting fully-qualified path disambiguation. This causes a misleading diagnostic suggesting a trait object lifetime/indirection mismatch rather than a concrete type mismatch.
Minimal Reproducible Example (MRE)
use std::error::Error; // Imported trait instead of std::io::Error
use std::fs::{self, DirEntry};
fn main() {
let read_dir = fs::read_dir(".").unwrap();
let file_coll: Vec<_> = read_dir.collect();
// Type annotation using bare trait `Error` instead of `std::io::Error`
let one: &Result<DirEntry, Error> = &file_coll[0];
}
Current Behavior / Diagnostic Output
The error message emitted is:
expected `&Result<DirEntry, dyn Error + 'static>`, found `&Result<DirEntry, Error>` (E0308)
Because both types are stripped to the short name Error, the diagnostic strongly implies that the found type is an instance of the trait itself (missing dynamic dispatch/indirection), rather than making it obvious that:
The expected type is dyn std::error::Error + 'static (bare trait treated as trait object)
The found type is the concrete struct std::io::Error
Expected Behavior
The diagnostic should disambiguate identical or shadowing type names using fully-qualified paths:
expected `&Result<DirEntry, dyn std::error::Error + 'static>`
found `&Result<DirEntry, std::io::Error>`
Environment
rustc version: rustc 1.100.0-nightly (a69a63265 2026-09-03)
cargo version: cargo 1.100.0-nightly (b2e9d5f9d 2026-09-02)
LLVM version: 23.1.1
OS: Fedora 44 (64-bit) / Linux Kernel 7.1.13-200.fc44.x86_64
Host: x86_64-unknown-linux-gnu
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
Reproduce the supplied Rust MRE and compare the E0308 diagnostic's expected and found type displays. Trace the rust-analyzer diagnostic and type-formatting entry points that reduce both types to Error; done means the message disambiguates them with std::error::Error and std::io::Error paths without misleading trait-object wording.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100