-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Make suggestion include the line number #42904
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
The output could use a bit of spacing, the line numbers aligned with It might also be a good idea to test this with clippy's lints, which have a bunch more suggestions (and there are almost certainly also lints that render multiple suggestions). cc @mcarton (who has just yesterday reacted to some of my clippy suggestions issues, and I didn't want to tag every clippy maintainer) |
Well, r=me on the code anyway, very simple. I think before I chose to exclude the line numbers because it did not correspond to actual source, and I was afraid it might seem confusing, but I guess it's confusing either way, particularly with multiple suggestions. |
I agree that somehow the multiple suggestions above look more crowded. |
e797c31
to
89de943
Compare
@nikomatsakis @killercup would something like the following look better?
|
That does look better to me. |
@nikomatsakis new output |
@estebank looks great! |
@estebank that's pretty awesome |
11 | use mul1::Mul; | ||
11 | use mul2::Mul; | ||
11 | use mul3::Mul; | ||
11 | use mul4::Mul; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks a bit surprising to me -- I wonder if we want to disable line numbers sometimes? or..maybe it's ok. Kind of helps convey that these are distinct alternatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might take a second look to recognize the line number is always the same. I'm not sure what scenario you want to optimize for. Many suggestions will probably look like your screenshot.
What do you think about something like:
help: possible candidates are found in other modules, you can import them into scope
|
1) | use mul1::Mul;
2) | use mul2::Mul;
3) | use mul3::Mul;
4) | use mul4::Mul;
|
Actually, let's think of a more complex example to see where this layout breaks: How does a diagnostic message look that
- has multiple alternative,
- that span multiple lines,
- and each has a highlight/underline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The underline only happens if there's only one suggestion that is on a single line (didn't want to have fancy multiline markings in the suggestions).
A multiline span suggestion looks the following way at the moment:
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> ../../src/test/ui/issue-22644.rs:20:14
|
19 | <
| - not interpreted as comparison
20 | b);
| ^ interpreted as generic argument
|
help: if you want to compare the casted value then write:
|
16 | println!("{}", (a
17 | as
18 | usize)
|
Two other possible ways to present multiple candidates are
error[E0412]: cannot find type `Mul` in this scope
--> $DIR/issue-21221-1.rs:72:16
|
72 | fn getMul() -> Mul {
| ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope
|
11 | use mul1::Mul;
|
11 | use mul2::Mul;
|
11 | use mul3::Mul;
|
11 | use mul4::Mul;
|
and 2 other candidates
and
error[E0412]: cannot find type `Mul` in this scope
--> $DIR/issue-21221-1.rs:72:16
|
72 | fn getMul() -> Mul {
| ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope
|
11 | use mul1::Mul;
| ^^^^^^^^^^^^^^
11 | use mul2::Mul;
| ^^^^^^^^^^^^^^
11 | use mul3::Mul;
| ^^^^^^^^^^^^^^
11 | use mul4::Mul;
| ^^^^^^^^^^^^^^
and 2 other candidates
Multiple suggestions that span multiple lines would look terrible with the current state of this PR:
error[E0412]: cannot find type `Mul` in this scope
--> $DIR/issue-21221-1.rs:72:16
|
72 | fn getMul() -> Mul {
| ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope
|
11 | use
12 | mul1::Mul;
11 | use
12 | mul2::Mul;
11 | use
12 | mul3::Mul;
11 | use
12 | mul4::Mul;
and 2 other candidates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the spaced version, with ^^^
iff it's not spanning the full suggestion.
| use namespaced_enums::Foo::B; | ||
| | ||
12 | use namespaced_enums::Foo::B; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the entire span is the suggestion, I don't think it should put the ^^^
under it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
262daf9
to
4bffe1f
Compare
@nikomatsakis updated. There're some stylistically dubious lines, but the actual output should be sound. |
@bors r+ |
📌 Commit 4bffe1f has been approved by |
🔒 Merge conflict |
When there're more than one suggestions in the same diagnostic, they are displayed in their own block, instead of inline. In order to reduce confusion, those blocks now display the line number.
4bffe1f
to
697c85a
Compare
@bors r=nikomatsakis |
📌 Commit 697c85a has been approved by |
Make suggestion include the line number When there're more than one suggestions in the same diagnostic, they are displayed in their own block, instead of inline. In order to reduce confusion, those blocks now display the line number. New output: ``` error[E0308]: mismatched types --> ../../src/test/ui/block-result/unexpected-return-on-unit.rs:19:5 | 19 | foo() | ^^^^^ expected (), found usize | = note: expected type `()` found type `usize` help: did you mean to add a semicolon here? | 19 | foo(); | ^ help: possibly return type missing here? | 18 | fn bar() -> usize { | ^^^^^^^^ error: aborting due to previous error(s) ``` Fix #39152.
☀️ Test successful - status-appveyor, status-travis |
When there're more than one suggestions in the same diagnostic, they are
displayed in their own block, instead of inline. In order to reduce
confusion, those blocks now display the line number.
New output:
Fix #39152.