Skip to content

Improve error messages for intra-doc links when there are backticks #87169

Closed
@GuillaumeGomez

Description

@GuillaumeGomez
Member

In #87078, we arrived at the following situation:

error: incompatible link kind for `Foo::bar`
  --> $DIR/field-ice.rs:5:6
   |
LL | /// [`Foo::bar()`]
   |      ^^^^^^^^^^^^ help: to link to the field, remove the disambiguator: ``Foo::bar``

I want to underline this part in particular:

``Foo::bar``

Having two backticks is very weird. What I suggest instead is to reduce the "^^^^^" underlining part in order to not include backticks in it so then they can be removed from the error message as well, which would give:

error: incompatible link kind for `Foo::bar`
  --> $DIR/field-ice.rs:5:6
   |
LL | /// [`Foo::bar()`]
   |       ^^^^^^^^^^ help: to link to the field, remove the disambiguator: `Foo::bar`

I'll do it in the next days if no one does until then. :)

cc @jyn514

Activity

added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by name
on Jul 15, 2021
estebank

estebank commented on Jul 16, 2021

@estebank
Contributor

You can fix this by using a span_suggestion_verbose instead of span_suggestion:

diag.span_suggestion(sp, &help, msg, Applicability::MaybeIncorrect);

It'll take more vertical space, but it's ok.


If someone picks this up as their first contribution, you need to --bless the .stderr test files by running ./x.py test src/test/rustdoc-ui --stage 1 --bless from the root of the repo directory.

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
on Jul 16, 2021
b41sh

b41sh commented on Jul 17, 2021

@b41sh

@rustbot claim

GuillaumeGomez

GuillaumeGomez commented on Jul 17, 2021

@GuillaumeGomez
MemberAuthor

@estebank It's a bit different here because we create the spans ourselves because they come from inside a doc comment. So I'm not sure if your suggestion will work out.

Also, in here it's src/test/rustdoc-ui, not src/test/ui (but otherwise it's the same). ;)

estebank

estebank commented on Jul 17, 2021

@estebank
Contributor

@GuillaumeGomez thanks for the correction!

As long as the span was synthesized correctly (including what side of a char the boundary falls on), then just changing the method will work as expected.

GuillaumeGomez

GuillaumeGomez commented on Jul 17, 2021

@GuillaumeGomez
MemberAuthor

I had in mind to simply update the span instead in case the string was starting and ending with backticks.

jyn514

jyn514 commented on Jul 17, 2021

@jyn514
Member

@GuillaumeGomez look at the code that's already there:

let msg = if dox.bytes().nth(link_range.start) == Some(b'`') {
format!("`{}`", suggestion.as_help(path_str))
} else {
suggestion.as_help(path_str)
};

If you think this shouldn't use verbose, remove that instead. But I think it's better to show backticks if the user had them there originally.

GuillaumeGomez

GuillaumeGomez commented on Jul 17, 2021

@GuillaumeGomez
MemberAuthor

We can take advantage of the span to exclude the backticks from the underlining, so then we can avoid displaying the backticks twice in the suggestion. As for the how, I guess it's fine as long as we get the output we want.

removed their assignment
on Jul 29, 2021
added a commit that references this issue on Jul 29, 2021

Rollup merge of rust-lang#87285 - GuillaumeGomez:intra-doc-span, r=es…

f118328
added a commit that references this issue on Jul 29, 2021

Rollup merge of rust-lang#87285 - GuillaumeGomez:intra-doc-span, r=es…

c46c25b
added a commit that references this issue on Jul 29, 2021

Auto merge of rust-lang#87285 - GuillaumeGomez:intra-doc-span, r=este…

GuillaumeGomez

GuillaumeGomez commented on Aug 2, 2021

@GuillaumeGomez
MemberAuthor

Fixed in #87285.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @b41sh@estebank@GuillaumeGomez@jyn514

        Issue actions

          Improve error messages for intra-doc links when there are backticks · Issue #87169 · rust-lang/rust