rust-lang / rust-lang/rust

Closure formatting in diagnostics can be a bit verbose

Open
#148,236 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-closures A-diagnostics A-pretty D-verbose P-low T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Consider inputs like https://github.com/rust-lang/rust/blob/278a90913daf7707791020a592d722dd7971f196/tests/ui/closures/closure-clone-requires-captured-clone.rs#L1, the diagnostics is:

https://github.com/rust-lang/rust/blob/278a90913daf7707791020a592d722dd7971f196/tests/ui/closures/closure-clone-requires-captured-clone.stderr#L1-L8

The message mentioning the closure uses a format like

 LL |     let closure = move || { 
    |                   ------- within this `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}` 

which feels quite verbose. I guess the span [lo, hi) (in terms of (start, end) line/col) and file path do make it clear which closure is being referred to when there are multiple closures. So not a priority, just tracking this in case there's ways to perhaps make this a bit more concise without losing info -- or assess if that info is actually fully needed).

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 with tests/ui/closures/closure-clone-requires-captured-clone.rs and its corresponding .stderr output to understand the verbose closure location text. Trace where this diagnostic formatting is produced, then determine whether a shorter format can preserve enough location information; done means the intended wording is agreed and the UI output reflects it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.