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

Improve intra doc errors display #87285

Merged
merged 2 commits into from
Jul 30, 2021
Merged

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jul 19, 2021

#87169

@jyn514 This is what I had in mind to avoid having duplicated backticks. I also gave a try to simply updating the span for the suggestion/help messages but I think this current one is better because less "noisy". Anyway, that allows you to see the result. ;)

@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Jul 19, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in intra-doc-links.

cc @jyn514

@rust-highfive
Copy link
Collaborator

r? @ollie27

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 19, 2021
@jyn514
Copy link
Member

jyn514 commented Jul 19, 2021

r? @jyn514

@rust-highfive rust-highfive assigned jyn514 and unassigned ollie27 Jul 19, 2021
@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name and removed A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Jul 19, 2021
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

I still think it would be better to use @estebank's verbose suggestion, the backticks are misleading. Narrowing the span to remove the backticks seems useful, but I don't think it solves the original issue.

let span = super::source_span_for_markdown_range(tcx, dox, link_range, &item.attrs);
let span =
super::source_span_for_markdown_range(tcx, dox, link_range, &item.attrs).map(|sp| {
if dox.bytes().nth(link_range.start) == Some(b'`') {
Copy link
Member

Choose a reason for hiding this comment

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

It's not actually required that the backticks match - can you also check that the ending backtick is present?

Suggested change
if dox.bytes().nth(link_range.start) == Some(b'`') {
if dox.bytes().nth(link_range.start) == Some(b'`') && dox.bytes().nth(link_range.end) == Some(b'`') {

Copy link
Member Author

Choose a reason for hiding this comment

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

I was wondering originally why it wasn't checking both the beginning and the end. Well, I guess that answers my question. :)

Comment on lines 91 to 98
help: to link to the enum, prefix with `enum@`
|
LL | /// Ambiguous non-implied shortcut link [`enum@foo::bar`].
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^
help: to link to the function, add parentheses
|
LL | /// Ambiguous non-implied shortcut link [`foo::bar()`].
| ^^^^^^^^^^^^
| ^^^^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that these are being shown as verbose already (because there's more than one suggestion), it'd be nice to make the span smaller, only covering the enum@ and ().

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an interesting take. Although, not sure it would be an improvement in these cases because they ask to add things, not remove them.

Copy link
Contributor

Choose a reason for hiding this comment

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

This would look like this:

error: `foo::bar` is both an enum and a function
  --> $DIR/ambiguity.rs:35:43
   |
LL | /// Ambiguous non-implied shortcut link [`foo::bar`].
   |                                           ^^^^^^^^ ambiguous link
   |
help: to link to the enum, prefix with `enum@`
   |
LL | /// Ambiguous non-implied shortcut link [`enum@foo::bar`].
   |                                           ^^^^^
help: to link to the function, add parentheses
   |
LL | /// Ambiguous non-implied shortcut link [`foo::bar()`].
   |                                                   ^^

which to my eyes looks easier to understand at a glance.

@GuillaumeGomez
Copy link
Member Author

I still think it would be better to use @estebank's verbose suggestion, the backticks are misleading. Narrowing the span to remove the backticks seems useful, but I don't think it solves the original issue.

@estebank confirmed that it was already using verbose because there are multiple messages, so on this part I think it's already fine?

What is unresolved with the current changes? My complain was that the error message was unclear because of the duplication of the backticks. So instead of including the whole intra-doc element, I only include the part in the backticks. If you have something else in mind, I can do it here as well if you want.

@GuillaumeGomez GuillaumeGomez marked this pull request as ready for review July 20, 2021 11:13
@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member

jyn514 commented Jul 20, 2021

@estebank confirmed that it was already using verbose because there are multiple messages, so on this part I think it's already fine?

It happened in that specific case because there happened to be multiple help messages. Almost always there will be only 0 or 1.

What is unresolved with the current changes? My complain was that the error message was unclear because of the duplication of the backticks. So instead of including the whole intra-doc element, I only include the part in the backticks. If you have something else in mind, I can do it here as well if you want.

My concern is that showing backticks at all is confusing - showing 1 backtick is actually even more confusing because it's not obviously a bug. Take this diagnostic: https://github.com/rust-lang/rust/blob/7f0cb81c8e4743aacc37167a7299ea0a85f005af/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr#L1-L5

That makes it look like you should add backticks when they weren't there before, I've seen people running into this in practice: lightningdevkit/rust-lightning#955 (comment)
Actually after reading that, I wonder if we should change this for any markdown suggestion ...

@GuillaumeGomez
Copy link
Member Author

My concern is that showing backticks at all is confusing - showing 1 backtick is actually even more confusing because it's not obviously a bug. Take this diagnostic:
...
That makes it look like you should add backticks when they weren't there before, I've seen people running into this in practice: lightningdevkit/rust-lightning#955 (comment)
Actually after reading that, I wonder if we should change this for any markdown suggestion ...

We use backticks literally everywhere:

LL | fn mk_int() -> usize { let i: isize = 3; return i; }
   |                -----                            ^ expected `usize`, found `isize`
   |                |
   |                expected `usize` because of return type

So this is coherent with all other error outputs. But again, I might misunderstand you...

It happened in that specific case because there happened to be multiple help messages. Almost always there will be only 0 or 1.

It's definitely worth adding a new test to ensure the output for an error with just one message then!

@jyn514
Copy link
Member

jyn514 commented Jul 20, 2021

We use backticks literally everywhere:

Yes, I understand that. In most parts of the compiler it's not ambiguous, because adding the backtick will cause the code to fail to compile. But in markdown it's valid syntax, and changes the meaning of the code. So we shouldn't suggest it, because it's not easy for the user to tell it's formatting and not part of the suggestion.

@GuillaumeGomez
Copy link
Member Author

I see, it's why I changed the span in order to only underline the parts without backticks so we can use the same logic. But at least I understand your point now.

@estebank
Copy link
Contributor

I'm for the change to make the span smaller. I would also prefer it if we could use span_suggestion_verbose more liberally than we currently are, except for situations where we are suggesting a complete substitution. The reason I haven't mass replaced them is because some people will complain about added verbosity, but at the same time a different subset of people does get confused on small changes (like adding() at the end, but pointing at the whole thing). This later group ends up frustrated thinking "But that's what I have!?". We have an opportunity to avoid that frustration.

@GuillaumeGomez
Copy link
Member Author

Definitely sounds like an improvement. I'm going to give it a try tomorrow!

@GuillaumeGomez GuillaumeGomez force-pushed the intra-doc-span branch 2 times, most recently from 3829068 to d39a544 Compare July 28, 2021 19:18
@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Jul 28, 2021

With the (great!) help of @estebank, I was able to greatly improve the error output. You can now admire! 😃

@GuillaumeGomez GuillaumeGomez changed the title Intra doc error span Improve intra doc errors display Jul 28, 2021
Comment on lines +147 to +150
help: to link to the macro, add an exclamation mark
|
LL | /// [m!()]
| ^
Copy link
Contributor

Choose a reason for hiding this comment

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

For this case the replacement span was pointing at the point immediately after m, but it needs to start there and end at the current sp.hi().

Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow, even after all the other cases have been fixed, this one hasn't 🤔

@GuillaumeGomez
Copy link
Member Author

Updated!

Comment on lines +2154 to +2159
if spans.len() > 1 {
diag.multipart_suggestion(&help, spans, Applicability::MaybeIncorrect);
} else {
suggestion.as_help(path_str)
};

diag.span_suggestion(sp, &help, msg, Applicability::MaybeIncorrect);
let (sp, suggestion_text) = spans.pop().unwrap();
diag.span_suggestion_verbose(sp, &help, suggestion_text, Applicability::MaybeIncorrect);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that you can just always call multipart_suggestion_verbose to get the same effect. Otherwise, it's fine to keep this as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! I added one, but in a PR that hasn't been merged yet. Disregard for now then.

sugg
}
Self::Macro => {
let mut sugg = vec![(inner_sp.shrink_to_hi(), "!".to_string())];
Copy link
Contributor

@estebank estebank Jul 29, 2021

Choose a reason for hiding this comment

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

This is needed to account for the foo() -> foo! change, so the span covers the () and gets replaced by !:

Suggested change
let mut sugg = vec![(inner_sp.shrink_to_hi(), "!".to_string())];
let mut sugg = vec![(inner_sp.shrink_to_hi().with_hi(sp.hi()), "!".to_string())];

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll add a specific check for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, it is a valid link to have macro!(), so I'll keep as is. :)

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

r=me after addressing the outstanding incorrect suggestion.

Love the results!

@jyn514 jyn514 assigned estebank and unassigned jyn514 Jul 29, 2021
@GuillaumeGomez
Copy link
Member Author

@bors: r=estebank

@bors
Copy link
Contributor

bors commented Jul 29, 2021

📌 Commit 0f7f85e has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 29, 2021
…tebank

Improve intra doc errors display

rust-lang#87169

`@jyn514` This is what I had in mind to avoid having duplicated backticks. I also gave a try to simply updating the span for the suggestion/help messages but I think this current one is better because less "noisy". Anyway, that allows you to see the result. ;)
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this pull request Jul 29, 2021
…tebank

Improve intra doc errors display

rust-lang#87169

``@jyn514`` This is what I had in mind to avoid having duplicated backticks. I also gave a try to simply updating the span for the suggestion/help messages but I think this current one is better because less "noisy". Anyway, that allows you to see the result. ;)
@jyn514
Copy link
Member

jyn514 commented Jul 29, 2021

I see that this has already been put in a rollup, but I'd really prefer to see a test for multiple overlaps in a namespace: #87285 (comment)

@GuillaumeGomez
Copy link
Member Author

I answered on the discussion: I added a function with the same name. ;)

@bors
Copy link
Contributor

bors commented Jul 29, 2021

⌛ Testing commit 0f7f85e with merge e66a8c2...

@bors
Copy link
Contributor

bors commented Jul 30, 2021

☀️ Test successful - checks-actions
Approved by: estebank
Pushing e66a8c2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 30, 2021
@bors bors merged commit e66a8c2 into rust-lang:master Jul 30, 2021
@rustbot rustbot added this to the 1.56.0 milestone Jul 30, 2021
@GuillaumeGomez GuillaumeGomez deleted the intra-doc-span branch July 30, 2021 07:55
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-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants