rust-lang / rust-lang/rust

consistently elide/don't elide types in diagnostics

Open
#118,731 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

right now, the decision of whether to fully elide the type as _ is inconsistent - it never happens for functions, fn pointers, tuples, refs where the pointee types are equal, or adts, but it does happen for primitives and ADTs behind a raw pointer. that is probably not intended? might be worth moving the t1 == t2 comparison up above the big match for consistency. https://github.com/rust-lang/rust/blob/eb53721a34d1d910b900aa753e0a00dc72ef41ac/compiler/rustc_infer/src/infer/error_reporting/mod.rs#L1510-L1512

here is an example of it being inconsistent: https://github.com/rust-lang/rust/blob/cf2dff2b1e3fa55fa5415d524200070d0d7aacfe/tests/ui/issues/issue-17905-2.stderr#L23-L26
isize is elided but str is not.

i originally changed this to almost always elide the type, but @estebank is worried that will be confusing:
image
he suggested instead eliding if the type has either type params or projection types ("looks complicated", basically).

Originally posted by @jyn514 in https://github.com/rust-lang/rust/issues/118730#issuecomment-1846520771

@rustbot label +A-diagnostics +E-medium

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 in compiler/rustc_infer/src/infer/error_reporting/mod.rs around lines 1510-1512, then compare the diagnostic output in tests/ui/issues/issue-17905-2.stderr. Resolve the intended type-elision rule from the issue's competing proposals, implement consistent behavior, and update or add diagnostic coverage showing the expected output for the listed type forms.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.