-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix intra-doc links for Self
on cross-crate items and primitives
#76467
Conversation
This comment has been minimized.
This comment has been minimized.
@bors r+ much nicer, thanks |
📌 Commit c90f2ff207aaa3ae45421add0215690095730ccb has been approved by |
@bors r- Failed documenting libstd:
|
The issue is that the hack I used for |
Hmm ... I'm starting to wonder if we should be doing textual substitution at all for |
Ok yeah my sketch of an idea is that instead of turning this into a string, I turn it into a Actually to make this even more consistent, I could strip |
Another possible hack is to prepend |
This comment has been minimized.
This comment has been minimized.
c90f2ff
to
4296022
Compare
Ok, I have the rustdoc side of this mostly working, but I'm not sure how to pass the partial resolution to @petrochenkov do you know how I would tell resolve ' |
I did find |
This comment has been minimized.
This comment has been minimized.
4296022
to
6d6b311
Compare
Hold on a second ...
So resolving that path segment doesn't need to go through resolve at all! It has all the info it needs available from Petrochenkov, sorry for the ping, I think I figured it out. |
Refactor and fix intra-doc link diagnostics, and fix links to primitives Closes rust-lang#76925, closes rust-lang#76693, closes rust-lang#76692. Originally I only meant to fix rust-lang#76925. But the hack with `has_primitive` was so bad it was easier to fix the primitive issues than to try and work around it. Note that this still has one bug: `std::primitive::i32::MAX` does not resolve. However, this fixes the ICE so I'm fine with fixing the link in a later PR. This is part of a series of refactors to make rust-lang#76467 possible. This is best reviewed commit-by-commit; it has detailed commit messages. r? @euclio
Refactor and fix intra-doc link diagnostics, and fix links to primitives Closes rust-lang#76925, closes rust-lang#76693, closes rust-lang#76692. Originally I only meant to fix rust-lang#76925. But the hack with `has_primitive` was so bad it was easier to fix the primitive issues than to try and work around it. Note that this still has one bug: `std::primitive::i32::MAX` does not resolve. However, this fixes the ICE so I'm fine with fixing the link in a later PR. This is part of a series of refactors to make rust-lang#76467 possible. This is best reviewed commit-by-commit; it has detailed commit messages. r? `@euclio`
This comment has been minimized.
This comment has been minimized.
6d6b311
to
82453c3
Compare
837dc4e
to
b2fe714
Compare
Rather than trying to rewrite all of intra-doc links at once, I changed this to use fully-qualified paths when stringifying DefIds. This is less reliable than using the DefId directly, but should let this land (and unblock #77700) without needing giant refactors. I still need to add a test case for #77875 (comment), I haven't been able to make an MCVE. |
cc @da-x - is there a better way to get the fully-qualified path of a type than the current hack? https://github.com/rust-lang/rust/blob/b2fe71488ffdaf9eadaabd25b5fd24e56512277a/src/librustdoc/passes/collect_intra_doc_links.rs#L852-L859 |
Self
Self
on cross-crate items and primitives
- Remove the difference between `parent_item` and `current_item`; these should never have been different. - Remove `current_item` from `resolve` and `variant_field` so that `Self` is only substituted in one place at the very start. - Resolve the current item as a `DefId`, not a `HirId`. This is what actually fixed the bug. Hacks: - `clean` uses `TypedefItem` when it _really_ should be `AssociatedTypeItem`. I tried fixing this without success and hacked around it instead (see comments) - This stringifies DefIds, then resolves them a second time. This is really silly and rustdoc should just use DefIds throughout. Fixing this is a larger task than I want to take on right now.
b2fe714
to
aa8c9b0
Compare
@Manishearth this is actually ready to go this time 😆 |
@bors r+ |
📌 Commit 2b17f02 has been approved by |
Fix intra-doc links for `Self` on cross-crate items and primitives - Remove the difference between `parent_item` and `current_item`; these should never have been different. - Remove `current_item` from `resolve` and `variant_field` so that `Self` is only substituted in one place at the very start. - Resolve the current item as a `DefId`, not a `HirId`. This is what actually fixed the bug. Hacks: - `clean` uses `TypedefItem` when it _really_ should be `AssociatedTypeItem`. I tried fixing this without success and hacked around it instead (see comments) - This second-guesses the `to_string()` impl since it wants fully-qualified paths. Possibly there's a better way to do this.
☀️ Test successful - checks-actions |
parent_item
andcurrent_item
; theseshould never have been different.
current_item
fromresolve
andvariant_field
so thatSelf
is only substituted in one place at the very start.DefId
, not aHirId
. This is whatactually fixed the bug.
Hacks:
clean
usesTypedefItem
when it really should beAssociatedTypeItem
. I tried fixing this without success and hackedaround it instead (see comments)
to_string()
impl since it wantsfully-qualified paths. Possibly there's a better way to do this.