-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Use name.namespace.html
as the canonical URL, not kind.name.html
#55160
Comments
For me it's a positive thing. I'd argue that you'd better not use direct URLs and just search or rustdoc links. The current URLs are clear and represent what they should. |
@GuillaumeGomez I disagree with that, I think that direct links to documentation are useful, their use should be encouraged, and we should avoid breaking them if possible. Having the extra information of |
I'm not sure we understood each other. To be clear: the current state of rustdoc URLs seems good and should be kept unless something way better is proposed. |
I agree with the OP that encoding the "kind" of type in the URL seems suboptimal. Rust has three namespaces (macro-level, fn/variable-level, type-level), so that needs to be encoded, but I see no good reason to encode more. As another argument for why the current URLs are bad: this is one of the few cases where doing a semver-compatible change (changing a |
Changing a struct to an enum isn't backwards-compatible (one can match against |
We have a bunch of redirects that only focus on the namespace an item belongs to. For example the URL https://doc.rust-lang.org/stable/std/mem/ManuallyDrop.t.html with "t" for type, will redirect to the correct place and I assume this URL was there before the struct/union switch happened. Only problem is that it's not the canonical URL. (And, it would be more ideal if we didn't have lots of extra redirect files, there are enough small files already in a rustdoc site). |
@bluss wow, I had no idea these files even existed! For use in rustc/libstd, if they should be useful we need a tidy pass that tells people to link to the "t" file instead of the "struct"/"enum"/"union" file. |
It was for RLS iirc. Not sure if removing it is fine but I'd like to remove it. |
I have the same comment as in #71912 (comment): direct links should use intra-doc links, the links rustdoc generates are not stable. |
@jyn514 so say I am writing a blog post and mentioning some Rust types whose docs I want to reference. Obviously my site generator does not support intra-doc links. What do you propose I do? This is something people already do -- anything that has a URL has people link to it. It's what makes the web so amazing. Please don't break that. |
URLs are stable, the DOM content isn't. However, since you always use a specific version of a crate, you can just link to the element of this specific version of the crate on docs.rs. |
URLs are not stable when a |
Then that's on the crate owner, not on rustdoc. We the URLs are defined as |
The entire point of this issue is that there is no good reason to include struct vs union in the URL. The "item type" of all structs, unions and enums should be just It's predictable, sure, but that does not make it sensible. |
So you would want to include a breaking change for something stable even before 1.0? You'd need very strong reasons for it to be done and I'm really not convinced... |
No we don't need a breaking change -- as @bluss wrote above, reasonably stable URLs already exist: https://doc.rust-lang.org/stable/std/mem/ManuallyDrop.t.html |
Well, we kinda want to remove this URL format since a while. It's still there because it's being used by RLS iirc. Also, this would be a regression in my point of view considering you lose information. And since it's not the default URL format, it's definitely a breaking change. |
The point of discussion IMO is whether or not it is stable. Currently, it's stable with respect to rustdoc versions, but not with respect to the code being documented. Either a) The file names should be predictable across versions being documented, in which case we should recommend The current middle ground is sort of the worst of both worlds because it looks like it's stable, but can break for changes that do not break semver. |
The information you lose is not semver-stable and irrelevant for API consumers. It's like having the line number in the URL -- sure that would be more inforamtion, but it's not good information to have in the URL. That's what this issue is all about -- please consult the arguments given above. Also, how is this a breaking change if it doesn't break anything? All existing URLs keep working. |
IMO the question is quite simple at a fundamental level -- what does it take to uniquely identify an item in Rust (assuming you already know the crate it is in)? You need its name, its full module path, and its "kind" -- which can be value, type, or macro. And that's it. So this information should be sufficient to construct a URL, and no other information should be contained in the URL. After all, a "Uniform Resource Locator" is all about being able to locate resources, such as the documentation about items in Rust, in a uniform and consistent way. |
@RalfJung what do you propose we do about all the existing URLs that point to |
If my understanding is correct, currently we generate two pages for every type:
What I am proposing is to swap the role of these two files, so every existing link keeps working:
This cannot break any link that currently works. It means changing e.g. union to enum still breaks people that use the "wrong" (deprecated) |
I'm happy with that. It doesn't fix the existing links to |
(I am not sure what |
I was actually thinking of |
|
name.namespace.html
as the canonical URL, not kind.name.html
The namespace based redirects were removed in #70563. |
It looks like that was mostly to fix wonky hash handling? The only comment about namespaces I see is #70563 (comment):
Is there any reason not to add the namespace redirects back? |
Why would we want it? It's a duplication of the current system. We removed it to stop having to maintain it and therefore reduce the amount of code. |
The entire issue is giving reasons why we would want it. #55160 (comment) has a good summary. |
Please read this issue. |
@nox turns out you're right, I'm glad I double-checked it. I think this is a mistake in the language design and should be deprecated. It's very impractical and I was unknowingly relying on it not being the case. The comment I originally intended to write, still relevant if the incompatibility gets fixed: Somewhat less related but IMO if the type has no public fields people shouldn't even know what "kind" the type is. Whether it's a tuple struct or ordinary struct or an enum with private variants, if Rust ever gets those, should be completely irrelevant to the consumer because it has no observable effects. This information shouldn't be present in URL or docs or anywhere outside the source code. It's exactly like the analogy with having line numbers in the docs. |
I just wanted to look at the
ManuallyDrop
docs again, and my browser helpfully remembered that it's at https://doc.rust-lang.org/std/mem/union.ManuallyDrop.html. But, despite the type being stable, that page no longer exists; it's now https://doc.rust-lang.org/std/mem/struct.ManuallyDrop.html.Is the specific item kind actually important to have in the path? The namespace (type vs value vs ...) certainly is, but especially for things without public fields, making the struct-vs-union distinction so front-and-centre seems overall unhelpful.
The text was updated successfully, but these errors were encountered: