Skip to content

Commit 12ec6ac

Browse files
authored
Merge pull request #2975 from jyn514/intra-doc-links
Update the intra-doc link RFC to match the implementation
2 parents 88fe454 + 2ccc5db commit 12ec6ac

File tree

1 file changed

+55
-13
lines changed

1 file changed

+55
-13
lines changed

text/1946-intra-rustdoc-links.md

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,34 @@ fn foo2() {
260260
}
261261
```
262262

263+
### Cross-crate re-exports
264+
265+
If an item is re-exported from an inner crate to an outer crate,
266+
its documentation will be resolved the same in both crates, as if it were in
267+
the original scope. For example, this function will link to `f` in both crates,
268+
even though `f` is not in scope in the outer crate:
269+
270+
```rust
271+
// inner-crate
272+
273+
pub fn f() {}
274+
/// This links to [f].
275+
pub fn g() {}
276+
```
277+
278+
```rust
279+
// outer-crate
280+
pub use inner_crate::g;
281+
```
282+
283+
### Links to private items
284+
285+
If a public item links to a private one, and `--document-private-items` is not passed,
286+
rustdoc should give a warning. If a private item links to another private
287+
item, no warning should be emitted. If a public item links to another private
288+
item and `--document-private-items` is passed, rustdoc should emit the link,
289+
but it is up to the implementation whether to give a warning.
290+
263291
## Path Ambiguities
264292
[path-ambiguities]: #path-ambiguities
265293

@@ -287,7 +315,7 @@ Our proposal is this:
287315
- In unambiguous cases paths can be written as described earlier,
288316
with no pre- or suffix, e.g., `Look at the [FOO] trait`. This also
289317
applies to modules and tuple structs which exist in both namespaces.
290-
Rustdoc will throw an error if you use a non-disambiguated path in
318+
Rustdoc will throw a warning if you use a non-disambiguated path in
291319
the case of there being a value in both the type and value namespace.
292320
- Links to types can be disambiguated by prefixing them with the concrete
293321
item type:
@@ -326,18 +354,9 @@ Our proposal is this:
326354
- It is possible that disambiguators for one kind of type-namespace object
327355
will work for the other (i.e. you can use `static@` to refer to a const),
328356

329-
For disambiguation markers using an `@`, in implied shortcut links
330-
you can use a space instead of the `@`. In other words, `[struct Foo]`
331-
is fine (and preferred).
332-
333-
It should be noted that in the RFC discussion it was determined
334-
that exact knowledge of the item type
335-
should not be necessary; only knowing the namespace should suffice.
336-
It is acceptable that the tool resolving the links
337-
allows (and successfully resolves) a link
338-
with the wrong prefix that is in the same namespace.
339-
E.g., given an `struct Foo`, it may be possible to link to it using `[enum Foo]`,
340-
or, given a `mod bar`, it may be possible to link to that using `[struct bar]`.
357+
If a disambiguator for a type does not match, rustdoc should issue a warning.
358+
For example, given `struct@Foo`, attempting to link to it using `[enum@Foo]`
359+
should not be allowed.
341360

342361
## Errors
343362
[errors]: #errors
@@ -452,6 +471,29 @@ like `See the [<Foo as Bar>::bar()] method`.
452471
We have yet to analyze in which cases this is necessary,
453472
and what syntax should be used.
454473

474+
### Traits in scope
475+
476+
If linking to an associated item that comes from a trait,
477+
the link should only be resolved in the trait is in scope.
478+
This prevents ambiguities if multiple traits are available with the associated item.
479+
For example, this should issue a warning:
480+
481+
```rust
482+
#[derive(Debug)]
483+
/// Link to [S::fmt]
484+
struct S;`
485+
```
486+
487+
but this should link to the implementation of `Debug::fmt` for `S`:
488+
489+
```rust
490+
use std::fmt::Debug;
491+
492+
#[derive(Debug)]
493+
/// Link to [S::fmt]
494+
struct S;`
495+
```
496+
455497
[ref-ufcs]: https://github.com/rust-lang-nursery/reference/blob/96e976d32a0a6927dd26c2ee805aaf44ef3bef2d/src/expressions.md#disambiguating-function-calls
456498

457499
## Linking to External Documentation

0 commit comments

Comments
 (0)