The compiler fails to see recursion bug
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Code
use core::fmt::{self, Display, Formatter};
enum E {
A,
B,
}
impl Display for E {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::A => write!(f, "A"),
other => other.fmt(f),
}
}
}
fn main() {
println!("{}", E::A);
println!("{}", E::B);
}
Current output
No warning
Desired output
No response
Rationale and extra context
The compiler fails to see the recursion bug in Display implementation of E, at branch other => other.fmt(f),
When you run it, only E::A is printed out. The program recurses when it tries to print E::B.
Other cases
Rust Version
rustc 1.98.0-nightly (3daae5e42 2026-06-14)
binary: rustc
commit-hash: 3daae5e42ec9ba435212987331af1b7b8634fa90
commit-date: 2026-06-14
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6
Anything else?
No response
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 compiling the Rust reproducer with rustc 1.98.0-nightly and tracing how the compiler handles the recursive other.fmt(f) call in the Display implementation. Determine the intended diagnostic for this recursion and add or update the relevant compiler test once the responsible subsystem is identified.
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
- 48/100