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

Rustdoc treats primitive disambiguators incorrectly #80559

Closed
jyn514 opened this issue Dec 31, 2020 · 8 comments · Fixed by #80660
Closed

Rustdoc treats primitive disambiguators incorrectly #80559

jyn514 opened this issue Dec 31, 2020 · 8 comments · Fixed by #80660
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Dec 31, 2020

I tried this code:

//! [str::trim()]

I expected to see this happen: Rustdoc links to https://doc.rust-lang.org/nightly/std/primitive.str.html#method.trim.

Instead, this happened: Rustdoc gets confused that () means a function and thinks that the link is a primitive.

error: incompatible link kind for `str::trim`
   |
   |
57 | /// Using the [`str::trim()`] method ensures that no whitespace remains before parsing.
   |                ^^^^^^^^^^^^^ help: to link to the builtin type, prefix with `prim@`: ``prim@str::trim``
   |
   = note: `-D broken-intra-doc-links` implied by `-D warnings`
   = note: this link resolved to a builtin type, which is not a function

Meta

rustdoc --version:

rustdoc 1.50.0-beta.1 (05b602367 2020-12-29)

Relevant code:

report_mismatch(other, Disambiguator::Primitive);

I think the fix is just to add if self.kind_side_channel.is_none() as a match guard.

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Dec 31, 2020
@jyn514
Copy link
Member Author

jyn514 commented Dec 31, 2020

This is blocking #75807 and made #77875 (comment) unnecessarily difficult.

@max-heller
Copy link
Contributor

@rustbot claim

@max-heller
Copy link
Contributor

@jyn514 which arm do you mean to add the match guard to?

@jyn514
Copy link
Member Author

jyn514 commented Dec 31, 2020

@max-heller the one for telling if the resolved item is a primitive:

Res::Primitive(_) => match disambiguator {

@max-heller
Copy link
Contributor

@jyn514 It looks like self.kind_side_channel is in fact None for str::trim()

@jyn514
Copy link
Member Author

jyn514 commented Dec 31, 2020

Oh hmm - the issue is that for primitives, rustdoc generates the anchor manually:

Res::Primitive(prim_ty),
Some(format!("{}#{}.{}", prim_ty.as_str(), out, item_str)),
. I would try storing the def_id of the associated item in kind_side_channel instead, so you know later whether the anchor is a manual link (str#method.trim) or whether it was generated by rustdoc.

@max-heller
Copy link
Contributor

Adding self.kind_side_channel.set(Some((item.kind.as_def_kind(), item.def_id))); in here

.map(|item| match item.kind {
ty::AssocKind::Fn => "method",
ty::AssocKind::Const => "associatedconstant",
ty::AssocKind::Type => "associatedtype",
})

and adding the match guard seems to fix things, but also feels like a hack.

@jyn514
Copy link
Member Author

jyn514 commented Dec 31, 2020

I mean, all of kind_side_channel is a hack because other parts of rustdoc break when you store the associated item instead: 0c99d80. If you can figure out a way to get rid of it, I'd love to do that, but it will require some pretty major refactors I think.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 7, 2021
Properly handle primitive disambiguators in rustdoc

Fixes rust-lang#80559

r? `@jyn514`

Is there a way to test that the generated intra-doc link is what I expect?
@bors bors closed this as completed in 2e9788b Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants