-
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
Issues with intra-doc links to core/std derive macros #110111
Comments
So there are actually two issues from what I can understand: some |
@GuillaumeGomez I've already taken a look at this a few days ago. Basically, the derive macro The compiler has an internal hard-coded mapping from macro name to macro kind (bang, attribute, derive). Now, the intra-doc link resolves the macro |
Yes but they are marked as such in the |
Okay, so in your fix do you change the prefix found in the URL of the page of the built-in macro from |
I only fixed the part where a proc-macro is not correctly recognized for now. I'll make the intra-doc link fix after. You can see my fix here. I need to add a test for it, I'll do so after lunch. |
Since I didn't know which of those two directions I should pursue, I held off from writing a fix. Personally I prefer changing the URL (and maybe also the page layout in the future) of those built-in derive macros to reflect that they are derive-macros even if not marked as such but that would be a breaking change. Special-casing built-in macros in the intra-doc resolution code to use |
Agreed. The fix should prevent that. However, the second part still needs to be done (ie, emitting a warning if a macro - bang, derive, etc - has the same name as another matching item). I improved things recently in this area so I think it shouldn't be too complicated to achieve. |
…ve, r=notriddle rustdoc: Correctly handle built-in compiler proc-macros as proc-macro and not macro Part of rust-lang#110111. There were actually one issue split in two parts: * Compiler built-in proc-macro were incorrectly considered as macros and not proc-macros. * Re-exports of compiler built-in proc-macros were considering them as macros. Both issues can be fixed by looking at the `MacroKind` variant instead of just relying on information extracted later on. r? `@fmease`
…ve, r=notriddle rustdoc: Correctly handle built-in compiler proc-macros as proc-macro and not macro Part of rust-lang#110111. There were actually one issue split in two parts: * Compiler built-in proc-macro were incorrectly considered as macros and not proc-macros. * Re-exports of compiler built-in proc-macros were considering them as macros. Both issues can be fixed by looking at the `MacroKind` variant instead of just relying on information extracted later on. r? ``@fmease``
…-proc-trait, r=notriddle [rustdoc] Add explanations for auto-disambiguation when an intra doc link is resolved to a proc-macro and a trait at the same time Part of rust-lang#110111. r? `@notriddle`
So only the sliced error message is now remaining. Small summary: /// For bug report: [`struct@Clone`]
Result:
Any idea @estebank maybe? |
I'm taking a look. I've already found the source of the bug. Now I just need to find a good fix. |
Just as an update, since I couldn't quite find a most general proper fix yet. Here are some more examples where it goes wrong:
There are several issues at play here: When creating a
|
…d-syntax, r=GuillaumeGomez,fmease rustdoc: get unnormalized link destination for suggestions Fixes rust-lang#110111 This bug, and the workaround in this PR, is closely linked to [pulldown-cmark/pulldown-cmark#441], getting offsets of link components. In particular, pulldown-cmark doesn't provide the offsets of the contents of a link. To work around this, rustdoc parser parts of a link definition itself. [pulldown-cmark/pulldown-cmark#441]: pulldown-cmark/pulldown-cmark#441
Fixes rust-lang#110111 This bug, and the workaround in this commit, is closely linked to [pulldown-cmark/pulldown-cmark#441], getting offsets of link components. In particular, pulldown-cmark doesn't provide the offsets of the contents of a link. To work around this, rustdoc parser parts of a link definition itself. [pulldown-cmark/pulldown-cmark#441]: pulldown-cmark/pulldown-cmark#441
I tried to refer to the core
Clone
derive macro (rather than the coreClone
trait) in a rustdoc intra-doc link, but was not able to find a way that works. Along the way I found broken generated links and a broken error message.Environment
I am using a
rust-toolchain.toml
withtoolchain.channel
set to"nightly-2023-04-07"
. Rustdoc identifies itself as:I happen to be working on a
no_std
crate, so all of my generated links will point to thecore
variants of these items.Correct behavior
First, what works:
/// [`Clone`]
Generated link: https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html
This links to the
Clone
trait and does not issue an ambiguity warning, apparently due to an intentional disambiguation rule that serves the common case: #82478 (comment). Great! I have benefited from this tens if not hundreds of times. But I'm on the unusual path and want to link to the derive macro.Incomplete documentation
I did a search and found the Namespaces and Disambiguators section of the rustdoc book. It says, "Paths in Rust have three namespaces: type, value, and macro." This implies to me that
type@
,value@
, andmacro@
would be the only valid disambiguators. But then the only examples usestruct@
andfn@
.I also found RFC 1946, which provides a more exhaustive (though potentially outdated) list of disambiguators.
The book says there's a macro namespace and the RFC mentions the
macro@
disambiguator, so I tried that one. I also found that aderive@
disambiguator is accepted and has the same effect, though neither doc mentions it. It would be nice if there was an exhaustive list of these disambiguators and their behaviors.Broken links
I tried using the
macro@
andderive@
disambiguators in my doc links:Generated links:
Those are 404s! And rustdoc does not issue any warnings or errors. Navigating the official docs, this is the link I want:
https://doc.rust-lang.org/nightly/core/clone/macro.Clone.html
So the official docs and and rustdoc disagree on how to refer to this item.
Third-party derive macros work
Does this happen with user-defined derive macros? I was surprised to see I was unable to link to the
derive_more::Add
orclap::Parser
derive macros (no idea why and#[doc(hidden)]
, respectively). But here'sserde
1.0.151 with thederive
feature enabled:Generated links:
Those links all work!
So I'm led to believe the std/core docs are doing something unusual with the naming of their derive macro pages.
Sliced error message
For fun, I tried specifying an incorrect disambiguator:
/// For bug report: [`struct@Clone`]
The suggestion replaced
struct
withtrait
, which is reasonable, but it removed theC
fromClone
in the process.The error message seems to do the right thing if I omit the backticks:
The text was updated successfully, but these errors were encountered: