-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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: redirect URLs #35236
rustdoc: redirect URLs #35236
Conversation
@nrc so just to clarify, this emits |
As with the previous PR, methods and struct fields are in the same namespace so we get conflicts. For example |
It is, but without changing the canonical URLs/anchors there doesn't seem to be a great way to disambiguate. However, since these are not canonical URLs, it doesn't really matter - for tool users who link to Rustdoc, there will be a very few URLs that don't work properly, but I expect this to be a pretty small edge case. |
Well, |
There are a few issues with the implementation:
|
@bors: r-, ah, good points! |
⌛ Testing commit 525b77e with merge 8d86593... |
@bors: r- er... maybe a mis-parse? |
💔 Test failed - auto-win-msvc-64-opt-rustbuild |
bors is clearly hungry for this PR, it won't take 'no' for an answer |
re tests, does anyone (@ollie27?) have suggestions for how to test the existence of the redirects? I don't see a way to fit it into the existing framework, but I don't know it very well. |
I think you can at least test for their existence with the rustdoc tests, and maybe html tags inside them as well? |
Check out test/rustdoc/redirect.rs and test/rustdoc/issue-33302.rs for examples which test the same kind of things. For example I'd do something like the following for structs: #![crate_name = "foo"]
// @has 'foo/FooStruct.t.html'
// @has - '//p/a' 'struct.FooStruct.html'
// @has 'foo/struct.FooStruct.html'
pub struct FooStruct {
// @has - '//*[@id="foo.v"]' 'foo'
pub foo: (),
// @has - '//*[@id="dupe.v"]' 'dupe'
pub dupe: (),
}
impl FooStruct {
// @has - '//*[@id="bar.v"]' 'bar'
pub fn bar() {}
// @has - '//*[@id="dupe.v-1"]' 'dupe'
pub fn dupe() {}
} You should be able repeat that for every other item type. |
@ollie27 I tried something like this and it doesn't work. I'm not really clear on the semantics of |
Check out src/etc/htmldocck.py for a better explanation than I could give. |
Thanks for the link, I knew these must be documented somewhere.
This is what was tripping me up. |
Updated with tests, spans instead of anchors, and unique ids. |
⌛ Testing commit 6765f7e with merge 30adf96... |
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
</span><span class='stab {stab}'></span>", | ||
shortty = ItemType::StructField, | ||
write!(w, "<span id='{item_type}.{name}' class='{item_type}'> | ||
<span id='{name}.{name_space}' class='invisible'> |
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.
You'll need to use derive_id
for these as well. The existing ids are also missing a call to derive_id
so you may as well also fix that while you're at it.
@@ -2366,9 +2389,12 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, | |||
if let StructFieldItem(ref ty) = field.inner { | |||
write!(w, "<tr><td \ | |||
id='variant.{v}.field.{f}'>\ | |||
<code>{f}: {t}</code></td><td>", | |||
<span id='{v}.{vns}.{f}.{fns}' class='invisible'>\ |
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.
Same here.
I was hoping you'd add a new test covering every single item type. For example enum variant struct fields and macros are different so need explicit tests. Are you going to document this feature anywhere? What kind of stability guarantees do these new URLs have? Can other people use them? |
I suppose a few more tests couldn't hurt. The main code paths are exercised and the coverage seems as good or better than existing Rustdoc tests.
No. I see no point in encouraging use of these until the long-term URL solution is figured out.
None, use at your own risk.
Sure, but I wouldn't encourage it.
I was assuming there was some logic behind not calling derive_id here (e.g., you can't have duplicate named fields, so I assume there can't be a name clash). |
The test coverage in rustdoc isn't very good right now so we should be aiming for better coverage.
|
pulled out of rust-lang#35020
… ones cc rust-lang#35020 which does this properly
📌 Commit 879637f has been approved by |
rustdoc: redirect URLs cc #35020 which does this properly r? @alexcrichton
cc #35020 which does this properly
r? @alexcrichton