Skip to content
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

Merged
merged 3 commits into from
Jul 7, 2017

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jun 25, 2017

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.

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member

eddyb commented Jun 25, 2017

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Jun 25, 2017
@killercup
Copy link
Member

The output could use a bit of spacing, the line numbers aligned with help: seems weird to me. I don't have a good layout suggestions right now, though.

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)

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2017
@nikomatsakis
Copy link
Contributor

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.

@nikomatsakis
Copy link
Contributor

I agree that somehow the multiple suggestions above look more crowded.

@estebank estebank force-pushed the number-suggestions branch 2 times, most recently from e797c31 to 89de943 Compare June 26, 2017 18:09
@estebank
Copy link
Contributor Author

@nikomatsakis @killercup would something like the following look better?

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)

@nikomatsakis
Copy link
Contributor

That does look better to me.

@arielb1 arielb1 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 27, 2017
@estebank
Copy link
Contributor Author

@nikomatsakis new output
screen shot 2017-06-27 at 23 16 49

@killercup
Copy link
Member

@estebank looks great!

@nikomatsakis
Copy link
Contributor

@estebank that's pretty awesome

11 | use mul1::Mul;
11 | use mul2::Mul;
11 | use mul3::Mul;
11 | use mul4::Mul;
Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor

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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@estebank estebank force-pushed the number-suggestions branch 3 times, most recently from 262daf9 to 4bffe1f Compare July 6, 2017 01:25
@estebank
Copy link
Contributor Author

estebank commented Jul 6, 2017

@nikomatsakis updated. There're some stylistically dubious lines, but the actual output should be sound.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 6, 2017

📌 Commit 4bffe1f has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jul 6, 2017

🔒 Merge conflict

estebank added 2 commits July 6, 2017 14:36
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.
@estebank estebank force-pushed the number-suggestions branch from 4bffe1f to 697c85a Compare July 6, 2017 21:36
@estebank
Copy link
Contributor Author

estebank commented Jul 6, 2017

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jul 6, 2017

📌 Commit 697c85a has been approved by nikomatsakis

bors added a commit that referenced this pull request Jul 6, 2017
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.
@bors
Copy link
Contributor

bors commented Jul 6, 2017

⌛ Testing commit 697c85a with merge d2ebb12...

@bors
Copy link
Contributor

bors commented Jul 7, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing d2ebb12 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants