-
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
Improve intra doc errors display #87285
Conversation
Some changes occurred in intra-doc-links. cc @jyn514 |
r? @ollie27 (rust-highfive has picked a reviewer for you, use r? to override) |
r? @jyn514 |
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 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'`') { |
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.
It's not actually required that the backticks match - can you also check that the ending backtick is present?
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'`') { |
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 was wondering originally why it wasn't checking both the beginning and the end. Well, I guess that answers my question. :)
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()`]. | ||
| ^^^^^^^^^^^^ | ||
| ^^^^^^^^^^ |
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.
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 ()
.
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 is an interesting take. Although, not sure it would be an improvement in these cases because they ask to add things, not remove them.
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 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.
8d91e49
to
28f0a97
Compare
@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. |
This comment has been minimized.
This comment has been minimized.
28f0a97
to
7f0cb81
Compare
It happened in that specific case because there happened to be multiple help messages. Almost always there will be only 0 or 1.
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) |
We use backticks literally everywhere:
So this is coherent with all other error outputs. But again, I might misunderstand you...
It's definitely worth adding a new test to ensure the output for an error with just one message then! |
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. |
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. |
I'm for the change to make the span smaller. I would also prefer it if we could use |
Definitely sounds like an improvement. I'm going to give it a try tomorrow! |
3829068
to
d39a544
Compare
With the (great!) help of @estebank, I was able to greatly improve the error output. You can now admire! 😃 |
d39a544
to
9dc0fbb
Compare
help: to link to the macro, add an exclamation mark | ||
| | ||
LL | /// [m!()] | ||
| ^ |
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.
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()
.
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.
Somehow, even after all the other cases have been fixed, this one hasn't 🤔
9dc0fbb
to
bcf057a
Compare
Updated! |
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); | ||
} |
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 that you can just always call multipart_suggestion_verbose
to get the same effect. Otherwise, it's fine to keep this as is.
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.
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.
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())]; |
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 is needed to account for the foo()
-> foo!
change, so the span covers the ()
and gets replaced by !
:
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())]; |
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.
Good point, I'll add a specific check for that.
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.
Actually, it is a valid link to have macro!()
, so I'll keep as is. :)
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.
r=me after addressing the outstanding incorrect suggestion.
Love the results!
bcf057a
to
0f7f85e
Compare
@bors: r=estebank |
📌 Commit 0f7f85e has been approved by |
…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. ;)
…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. ;)
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) |
I answered on the discussion: I added a function with the same name. ;) |
☀️ Test successful - checks-actions |
#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. ;)