Update the disambiguation handling in RFC 1946 (intra-rustdoc-links) to match impl concerns#2285
Conversation
|
AFAICT this doesn't need to go through the full RFC process, just a quick discussion and perhaps fcp. |
text/1946-intra-rustdoc-links.md
Outdated
| E.g., given an `struct Foo`, it may be possible to link to it using `[enum Foo]`, | ||
| or, given a `mod bar`, it may be possible to link to that using `[struct bar]`. | ||
|
|
||
| In case a type is in |
There was a problem hiding this comment.
my bad, was initially going to expand there and then decided to take a different path. removed.
|
@Manishearth awesome PR, fewest RFCs get corrected if it is decided that some other path should be taken. |
cb8206a to
5e1ccd4
Compare
| item type: | ||
| - Links to `struct`s can be prefixed with `struct `, | ||
| e.g., `See [struct Foo]`. | ||
| e.g., `See [struct@Foo]`. |
There was a problem hiding this comment.
Can we use the @ in the link target but allow the space when using implied ref links?
There was a problem hiding this comment.
Yes, but I prefer uniformity here. Wonder what others think.
There was a problem hiding this comment.
Actually, I like your idea better. Hm.
There was a problem hiding this comment.
(I actually wrote the implementation with that in mind when i switched it to use @ >_>)
Interestingly escaping the space like In this crate we would like to link to:
* [`ThisType`](struct\ ::ThisType)
* [`ThisEnum`](enum\ ::ThisEnum)
* [`ThisTrait`](trait\ ::ThisTrait)
* [`ThisAlias`](type\ ::ThisAlias)
* [`ThisUnion`](union\ ::ThisUnion)
* [`this_function`](::this_function())
* [`THIS_CONST`](const\ ::THIS_CONST)
* [`THIS_STATIC`](static\ ::THIS_STATIC)<p>In this crate we would like to link to:</p>
<ul>
<li><a href="struct%5C%20::ThisType"><code>ThisType</code></a></li>
<li><a href="enum%5C%20::ThisEnum"><code>ThisEnum</code></a></li>
<li><a href="trait%5C%20::ThisTrait"><code>ThisTrait</code></a></li>
<li><a href="type%5C%20::ThisAlias"><code>ThisAlias</code></a></li>
<li><a href="union%5C%20::ThisUnion"><code>ThisUnion</code></a></li>
<li><a href="::this_function()"><code>this_function</code></a></li>
<li><a href="const%5C%20::THIS_CONST"><code>THIS_CONST</code></a></li>
<li><a href="static%5C%20::THIS_STATIC"><code>THIS_STATIC</code></a></li>
</ul> |
text/1946-intra-rustdoc-links.md
Outdated
| Non-disambiguated paths cannot be used to link to macros. | ||
| - Links to types can be disambiguated by prefixing them with the concrete | ||
| item type: | ||
| - Links to `struct`s can be prefixed with `struct `, |
There was a problem hiding this comment.
Since all these "can be prefixed with" notes include a space in their code span, i would like to see the @ in there as well. So this one would be:
Links to
structs can be prefixed withstruct@,
5e1ccd4 to
0bad27d
Compare
0bad27d to
8f5be35
Compare
|
|
|
The problem is that struct.foo is more like a URL. We eventually want to detect and warn on broken intra links, and to do that you need to be sure that something was a broken intra link and not a URL. For this there should be a clear way of disambiguating, "optionally-backtick-surrounded identifier with possible at symbol or parentheses" doesn't clash with what most URLs will look like. |
|
r? @rust-lang/dev-tools |
|
@Fcpbot fcp merge I'm not quite happy to merge, but I think we should start FCP now and discuss as we go since this is just an amendment to an existing RFC (discussed at dev-tools meeting today). |
|
@rfcbot fcp merge |
|
Team member @nrc has proposed to merge this. The next step is review by the rest of the tagged teams: Concerns:
Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
text/1946-intra-rustdoc-links.md
Outdated
| applies to modules and tuple structs which exist in both namespaces. | ||
| Rustdoc will throw an error if you use a non-disambiguated path in | ||
| the case of there being a value in both the type and value namespace. | ||
| Non-disambiguated paths cannot be used to link to macros. |
There was a problem hiding this comment.
That's what the current impl is, this amendment matches the impl. That can be changed.
|
|
||
| For disambiguation markers using an `@`, in implied shortcut links | ||
| you can use a space instead of the `@`. In other words, `[struct Foo]` | ||
| is fine (and preferred). |
There was a problem hiding this comment.
we should note that you don't need to use the data type names - using type@ and value@ should be OK for all types and values, respectively.
text/1946-intra-rustdoc-links.md
Outdated
| e.g., `See [mod@foo]`. | ||
| - In links to macros, | ||
| the link label must end with a `!`, | ||
| the link label _must_ end with a `!`, |
There was a problem hiding this comment.
I haven't looked this up, but I'm pretty sure I argued strongly against this in the original RFC and I'm surprised to see it here. The ! is the syntax for calling a macro, not naming it (analogous to () to call a function), so I think rustdoc should not include the ! as part of the name (this is more important with macros 2.0 where you import the macro in a use statement without using !). Also, this doesn't make sense for attribute-like macros which are not even used with a !.
So, I would like to see macros named using just the name, and if disambiguation is necessary, to use macro@. I don't mind if you want to allow ! as a shorthand, but I would prefer not to.
| - Links to type aliases can be prefixed with `type@`, | ||
| e.g., `See [type@foo]`. | ||
| - Links to modules can be prefixed with `mod@`, | ||
| e.g., `See [mod@foo]`. |
There was a problem hiding this comment.
I guess unions and traits should be in this list too?
| e.g., `See [type foo]`. | ||
| - Links to modules can be prefixed with `mod `, | ||
| e.g., `See [mod foo]`. | ||
| - In unambiguous cases paths can be written as described earlier, |
There was a problem hiding this comment.
iirc we discussed this in the original RFC and decided against it? I can't remember why though. One possible reason is forwards-compatability - adding a name to a namespace would break any docs that don't use a disambiguator.
There was a problem hiding this comment.
I think we can convert the error into a warning to make it a non-breaking change.
However, you already have this forwardcompat hazard with regular links. [foo](bar) is still a valid link; just won't point anywhere; usually.
You also can already break docs within this proposal by changing your imports in the file.
We provide disambiguation markers for folks who wish to catch this, and I think not mandating the disambiguation markers will make it easy to conveniently write docs. Clashing namespaces is not a common thing to do (aside from the implicit clashes introduced by tuple structs -- we handle this already), and when you do clash them usually it's to create a constructor for the same type so nbd.
|
@rfcbot concern review comments |
|
@nrc - I'm not on dev tools now, so I'm guessing my name should be removed? |
46204f1 to
9eccc58
Compare
|
The current impl e.g. allows you to use |
|
I've made a change (f231d75) allowing ambiguous references to macros. I mostly didn't do this because it was tricky to impl and I wanted something working, but this can be changed. |
|
We discussed at the dev-tools meeting today, we clarified that this should be regarded as a 'bug fix' RFC and that there will be a chance to re-visit and discuss the design during a stabilisation period. Therefore we should tick off and land this quickly. @rfcbot resolved review comments @Manishearth thanks for the updates! |
|
Oh, just a note, I also introduced method@ and variant@ in a fixup pr. I'll add that to the RFC before merging. |
cee1658 to
0b17ddf
Compare
|
Updated. |
|
(Updates on this? Stalled on review) |
|
@rfcbot reviewed (Sorry for delay!) |
|
I'm (still) in favor of this! :) @rfcbot reviewed |
|
@rfcbot reviewed |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period is now complete. |
In rust-lang/rust#47046, we realized that the proposed disambiguation syntax is not valid CommonMark, and changed it to
[struct@Foo], etc.Additionally, we feel that you should be allowed to use un-disambiguated paths to refer to values as long as there isn't a clash.
cc @QuietMisdreavus @killercup