rust-lang / rust-lang/rust

fire debug assertion when `expected` and `found` item look the same in diagnostic?

Open
#119,713 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Sometimes rustc outputs silly error hints like

   = note: expected trait `for<'a> <for<'a> fn(&'a u32) -> &'a u32 {function2} as FnOnce<(&'a u32,)>>`
              found trait `for<'a> <for<'a> fn(&'a u32) -> &'a u32 {function2} as FnOnce<(&'a u32,)>>`

where "expected" and "found" look like they are the same which is quite unhelpful.
(example from https://github.com/rust-lang/rust/issues/114883 )

I wonder if we should have a debug assertion in these cases (rustc displaying both types being identical although they shouldn't be) that helps catch these kid of diagnostic mishaps, similar to the "span must not be empty and have no suggestion" and "span must not have overlapping parts" debug assertions.

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 reviewing the diagnostic behavior shown in issue #114883 and tracing where rustc formats the expected and found traits. Determine where an assertion can check for identical displayed items without affecting valid diagnostics. Done means the assertion catches this diagnostic mishap and relevant diagnostic tests still pass.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.