Skip to content

Closure formatting in diagnostics can be a bit verbose #148236

@jieyouxu

Description

@jieyouxu

Consider inputs like

//! Test that closures only implement `Clone` if all captured values implement `Clone`.
, the diagnostics is:

error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`
--> $DIR/closure-clone-requires-captured-clone.rs:17:13
|
LL | let closure = move || {
| ------- within this `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`
...
LL | closure.clone();
| ^^^^^ within `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`, the trait `Clone` is not implemented for `NonClone`

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-prettyArea: Pretty printing (including `-Z unpretty`)D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions