forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#74430 - Manishearth:stabilize-intra-doc, r=…
…Manishearth Stabilize intra-doc links Fixes rust-lang#43466 Thanks to the great work of @jyn514 in getting the [cross-crate reexport issue](rust-lang#65983) in intra-rustdoc links fixed, I think we're now in a position to stabilize this feature. The tracking issue currently has two unresolved issues: - <s>behavior around doc(hidden): This is fixed in rust-lang#73365, which is just waiting for CI and should land tomorrow. It's also a pretty niche bug so while I expect it to land soon I don't think we need to block stabilization on it anyway.</s> - Non-identifier primitive types like slices: This was not a part of the original RFC anyway, and is a pretty niche use case The feature itself, sans rust-lang#65983, has been shipped on nightly for three years now, with people using it on docs.rs. rust-lang#65983 itself is not an overwhelmingly central bit of functionality; the reason we elected to block stabilization on it was that back in 2017 it was not possible to fix the issue without some major refactorings of resolve, and we did not want to stabilize something that had such a potentially unfixable bug. Given that we've fixed it, I see no reason to delay stabilization on this long awaited feature. It's possible that the latest patches have problems, however we _have_ done crater runs of some of the crucial parts. Furthermore, that's what the release trains are for, we will have a solid three months to let it ride the trains before it actually hits the stable compiler. r? @rust-lang/rustdoc
- Loading branch information
Showing
5 changed files
with
107 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Linking to items by name | ||
|
||
Rustdoc is capable of directly linking to other rustdoc pages in Markdown documentation using the path of item as a link. | ||
|
||
For example, in the following code all of the links will link to the rustdoc page for `Bar`: | ||
|
||
```rust | ||
/// This struct is not [Bar] | ||
pub struct Foo1; | ||
|
||
/// This struct is also not [bar](Bar) | ||
pub struct Foo2; | ||
|
||
/// This struct is also not [bar][b] | ||
/// | ||
/// [b]: Bar | ||
pub struct Foo3; | ||
|
||
/// This struct is also not [`Bar`] | ||
pub struct Foo4; | ||
|
||
pub struct Bar; | ||
``` | ||
|
||
You can refer to anything in scope, and use paths, including `Self`, `self`, `super`, and `crate`. You may also use `foo()` and `foo!()` to refer to methods/functions and macros respectively. Backticks around the link will be stripped. | ||
|
||
```rust,edition2018 | ||
use std::sync::mpsc::Receiver; | ||
/// This is an version of [`Receiver`], with support for [`std::future`]. | ||
/// | ||
/// You can obtain a [`std::future::Future`] by calling [`Self::recv()`]. | ||
pub struct AsyncReceiver<T> { | ||
sender: Receiver<T> | ||
} | ||
impl<T> AsyncReceiver<T> { | ||
pub async fn recv() -> T { | ||
unimplemented!() | ||
} | ||
} | ||
``` | ||
|
||
You can also link to sections using URL fragment specifiers: | ||
|
||
```rust | ||
/// This is a special implementation of [positional parameters] | ||
/// | ||
/// [positional parameters]: std::fmt#formatting-parameters | ||
struct MySpecialFormatter; | ||
``` | ||
|
||
Paths in Rust have three namespaces: type, value, and macro. Items from these namespaces are allowed to overlap. In case of ambiguity, rustdoc will warn about the ambiguity and ask you to disambiguate, which can be done by using a prefix like `struct@`, `enum@`, `type@`, `trait@`, `union@`, `const@`, `static@`, `value@`, `function@`, `mod@`, `fn@`, `module@`, `method@`, `prim@`, `primitive@`, `macro@`, or `derive@`: | ||
|
||
```rust | ||
/// See also: [`Foo`](struct@Foo) | ||
struct Bar; | ||
|
||
/// This is different from [`Foo`](fn@Foo) | ||
struct Foo {} | ||
|
||
fn Foo() {} | ||
``` | ||
|
||
Note: Because of how `macro_rules` macros are scoped in Rust, the intra-doc links of a `macro_rules` macro will be resolved relative to the crate root, as opposed to the module it is defined in. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters