rust-lang / rust-lang/rust

The compiler fails to see recursion bug

Open
#159,828 1 comment 0 reactions 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.