Fix jump-to-def links broken by turbofish syntax#156727
Conversation
|
rustbot has assigned @GuillaumeGomez. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
|
||
| pub fn foo() { | ||
| // `PhantomData::<usize>` — `PhantomData` must be linked despite the turbofish. | ||
| //@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'PhantomData' |
There was a problem hiding this comment.
The type appears 3 times, so the test is not really checking much. Use a type alias instead for the specific one that you need to be tested. For example:
type TheOne = PhantomData;
let _: TheOne::<usize> = PhantomData;The idea is to make TheOne appears only once. Then you can check like you did with //@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'TheOne'.
There was a problem hiding this comment.
An alternative would be to use count but I think it'd be less robust (and readable).
There was a problem hiding this comment.
Switched to checking the local reference link since a type alias links to its own
definition rather than to struct.PhantomData.html.
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
Handle turbofish syntax correctly in rustdoc jump-to-def links and add regression tests covering type aliases.
| // `PhantomData::<usize>` — `PhantomData` must be linked despite the turbofish. | ||
| type TheOne = PhantomData<()>; | ||
|
|
||
| //@ has - '//a[@href="#13"]' 'TheOne' |
There was a problem hiding this comment.
That doesn't fix anything. ^^'
There was a problem hiding this comment.
Is using an import alias fine
use std::marker::PhantomData as TheOne;
pub fn foo() {
//@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'TheOne'
let _: TheOne::<usize>;
}cuz the idea you mentioned
use std::marker::PhantomData;
type TheOne = PhantomData<()>;
pub fn foo() {
//@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'TheOne'
let _: TheOne::<usize> = PhantomData;
}it ends up genenrating this html
<a href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html">std::marker::PhantomData</a>
'<a href="../../foo/fn.foo.html">foo</a>'
'<a href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html">PhantomData</a>'
'<a href="#13">TheOne</a>'
'<a href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>'
'<a href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html">PhantomData</a>'`There was a problem hiding this comment.
Ah yes, much better. An aliased import is much better!
|
Thanks! @bors r+ rollup |
Fixes #156706