Skip to content

Tracking Issue for improving suggestion rendering in diagnostics #141973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks
estebank opened this issue Jun 3, 2025 · 1 comment
Open
3 tasks

Tracking Issue for improving suggestion rendering in diagnostics #141973

estebank opened this issue Jun 3, 2025 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@estebank
Copy link
Contributor

estebank commented Jun 3, 2025

This is a tracking issue for the prioritizing "verbose" or "hidden" suggestions over "inline" (the default given by span_suggestion suggestions.

Inline suggestions have several issues that make them less readable than verbose ones:

  • I've seen people get confused by them
  • Small differences caused by typos are much better seen on the verbose output, where the highlighting now points at the exact character, instead of having to visually notice the different text in non-aligned places
  • The inline output was the original implementation, but since we've introduced the diff output which is clearer on what we expect the user to write
  • For additions, things like "add a type parameter: " are even more unclear
  • Relying on the inline suggestions have lead us to use worse spans on purpose because otherwise the rendering would be bad (like skipping whitespace in some cases) and has a tendency to make suggestion mistakes harder to notice (broken suggestions making it in because we couldn't tell during review)
  • When a single suggestion is in the diagnostic, the default renders inline, but if there are two, then both get rendered as verbose, which makes the output sometimes sensitive to what was emitted and can cause two similar errors to look very different.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Steps

  • Audit all cases of span_suggestion uses.
  • Adjust individual cases to be either span_suggestion_verbose, span_suggestion_hidden or span_suggestion_tool_only
  • Change span_suggestion to span_suggestion_inline and span_suggestion_verbose to span_suggestion

Implementation history

https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/Why.20are.20we.20making.20suggestions.20verbose.3F

@estebank estebank added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Jun 3, 2025
@compiler-errors
Copy link
Member

This work is also enabled by:

which improve the presentation of verbose suggestions when they're "purely additive", which should help reduce the impact of this work.

@fmease fmease added the WG-diagnostics Working group: Diagnostics label Jun 3, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 5, 2025
…-suggestion, r=compiler-errors

Make E0621 missing lifetime suggestion verbose

```
error[E0621]: explicit lifetime required in the type of `x`
  --> $DIR/42701_one_named_and_one_anonymous.rs:10:9
   |
LL |         &*x
   |         ^^^ lifetime `'a` required
   |
help: add explicit lifetime `'a` to the type of `x`
   |
LL | fn foo2<'a>(a: &'a Foo, x: &'a i32) -> &'a i32 {
   |                             ++
```

Part of rust-lang#141973.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 6, 2025
…ywiser

Verbose suggestion to make param `const`

```
error[E0747]: type provided when a constant was expected
  --> $DIR/invalid-const-arguments.rs:10:19
   |
LL | impl<N> Foo for B<N> {}
   |                   ^
   |
help: consider changing this type parameter to a const parameter
   |
LL - impl<N> Foo for B<N> {}
LL + impl<const N: u8> Foo for B<N> {}
   |
```

Part of rust-lang#141973.
rust-timer added a commit that referenced this issue Jun 7, 2025
Rollup merge of #142043 - estebank:const-suggestion, r=wesleywiser

Verbose suggestion to make param `const`

```
error[E0747]: type provided when a constant was expected
  --> $DIR/invalid-const-arguments.rs:10:19
   |
LL | impl<N> Foo for B<N> {}
   |                   ^
   |
help: consider changing this type parameter to a const parameter
   |
LL - impl<N> Foo for B<N> {}
LL + impl<const N: u8> Foo for B<N> {}
   |
```

Part of #141973.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants