rust-lang / rust-lang/rust

Incorrect suggestion diff highlight for nonexistent variant

Open
#146,586 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
enum A {
    B(),
}

fn foo(_: A) {}

fn main() {
    foo(A::C);
}
Current output

As shown in the screenshot attached, the diff marked with plus in the suggestion highlights the opening parenthesis in green.

Image
Desired output
  1. The plus diff should highlight the replacement B, not the parenthesis.
  2. In the absence of a use A::B; statement, A::B should be suggested as the replacement instead of B.
Rationale and extra context

This bug affects latest stable 1.89.0 (29483883e 2025-08-04) and beta 1.90.0-beta.10 (67cb8e039 2025-09-11). In latest nightly 1.92.0-nightly (52618eb33 2025-09-14), this triggers a ICE as describe in issue #146261. This bug was discovered during the investigation of that ICE bug, might be the root cause of it.

Rust Version
rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.7

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 issue with the provided Rust snippet on the stable, beta, and nightly versions listed. Trace the compiler's suggestion diff handling for the nonexistent variant and compare it with the ICE investigation in issue #146261; done means the diff highlights B and suggests A::B when no use statement exists, without triggering the ICE.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.