Skip to content
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

Support anchors intra doc links #66675

Merged
merged 4 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 211 additions & 78 deletions src/librustdoc/passes/collect_intra_doc_links.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `[v2]` cannot be resolved, ignoring it...
error: `[v2]` cannot be resolved, ignoring it.
--> $DIR/deny-intra-link-resolution-failure.rs:3:6
|
LL | /// [v2]
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/intra-doc-alias-ice.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `[TypeAlias::hoge]` cannot be resolved, ignoring it...
error: `[TypeAlias::hoge]` cannot be resolved, ignoring it.
--> $DIR/intra-doc-alias-ice.rs:5:30
|
LL | /// [broken cross-reference](TypeAlias::hoge)
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/intra-link-span-ice-55723.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// ## For example:
///
/// (arr[i])
//~^ ERROR `[i]` cannot be resolved, ignoring it...
//~^ ERROR `[i]` cannot be resolved, ignoring it.
pub fn test_ice() {
unimplemented!();
}
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/intra-link-span-ice-55723.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `[i]` cannot be resolved, ignoring it...
error: `[i]` cannot be resolved, ignoring it.
--> $DIR/intra-link-span-ice-55723.rs:9:10
|
LL | /// (arr[i])
Expand Down
45 changes: 45 additions & 0 deletions src/test/rustdoc-ui/intra-links-anchors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#![deny(intra_doc_link_resolution_failure)]

// A few tests on anchors.

/// Hello people.
///
/// You can anchors? Here's one!
///
/// # hola
///
/// Isn't it amazing?
pub struct Foo {
pub f: u8,
}

pub enum Enum {
A,
B,
}

/// Have you heard about stuff?
///
/// Like [Foo#hola].
///
/// Or maybe [Foo::f#hola].
//~^ ERROR `[Foo::f#hola]` has an issue with the link anchor.
pub fn foo() {}

/// Empty.
///
/// Another anchor error: [hello#people#!].
//~^ ERROR `[hello#people#!]` has an issue with the link anchor.
pub fn bar() {}

/// Empty?
///
/// Damn enum's variants: [Enum::A#whatever].
//~^ ERROR `[Enum::A#whatever]` has an issue with the link anchor.
pub fn enum_link() {}

/// Primitives?
///
/// [u32#hello]
//~^ ERROR `[u32#hello]` has an issue with the link anchor.
pub fn x() {}
32 changes: 32 additions & 0 deletions src/test/rustdoc-ui/intra-links-anchors.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error: `[Foo::f#hola]` has an issue with the link anchor.
--> $DIR/intra-links-anchors.rs:25:15
|
LL | /// Or maybe [Foo::f#hola].
| ^^^^^^^^^^^ struct fields cannot be followed by anchors
|
note: lint level defined here
--> $DIR/intra-links-anchors.rs:1:9
|
LL | #![deny(intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `[hello#people#!]` has an issue with the link anchor.
--> $DIR/intra-links-anchors.rs:31:28
|
LL | /// Another anchor error: [hello#people#!].
| ^^^^^^^^^^^^^^ only one `#` is allowed in a link

error: `[Enum::A#whatever]` has an issue with the link anchor.
--> $DIR/intra-links-anchors.rs:37:28
|
LL | /// Damn enum's variants: [Enum::A#whatever].
| ^^^^^^^^^^^^^^^^ variants cannot be followed by anchors

error: `[u32#hello]` has an issue with the link anchor.
--> $DIR/intra-links-anchors.rs:43:6
|
LL | /// [u32#hello]
| ^^^^^^^^^ primitive types cannot be followed by anchors

error: aborting due to 4 previous errors

8 changes: 4 additions & 4 deletions src/test/rustdoc-ui/intra-links-warning-crlf.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: `[error]` cannot be resolved, ignoring it...
warning: `[error]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning-crlf.rs:7:6
|
LL | /// [error]
Expand All @@ -7,23 +7,23 @@ LL | /// [error]
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error1]` cannot be resolved, ignoring it...
warning: `[error1]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning-crlf.rs:12:11
|
LL | /// docs [error1]
| ^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error2]` cannot be resolved, ignoring it...
warning: `[error2]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning-crlf.rs:15:11
|
LL | /// docs [error2]
| ^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error]` cannot be resolved, ignoring it...
warning: `[error]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning-crlf.rs:23:20
|
LL | * It also has an [error].
Expand Down
38 changes: 19 additions & 19 deletions src/test/rustdoc-ui/intra-links-warning.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: `[Foo::baz]` cannot be resolved, ignoring it...
warning: `[Foo::baz]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:3:23
|
LL | //! Test with [Foo::baz], [Bar::foo], ...
Expand All @@ -7,71 +7,71 @@ LL | //! Test with [Foo::baz], [Bar::foo], ...
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[Bar::foo]` cannot be resolved, ignoring it...
warning: `[Bar::foo]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:3:35
|
LL | //! Test with [Foo::baz], [Bar::foo], ...
| ^^^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[Uniooon::X]` cannot be resolved, ignoring it...
warning: `[Uniooon::X]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:6:13
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[Qux::Z]` cannot be resolved, ignoring it...
warning: `[Qux::Z]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:6:30
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[Uniooon::X]` cannot be resolved, ignoring it...
warning: `[Uniooon::X]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:10:14
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[Qux::Z]` cannot be resolved, ignoring it...
warning: `[Qux::Z]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:10:31
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[Qux:Y]` cannot be resolved, ignoring it...
warning: `[Qux:Y]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:14:13
|
LL | /// [Qux:Y]
| ^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error]` cannot be resolved, ignoring it...
warning: `[error]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:58:30
|
LL | * time to introduce a link [error]*/
| ^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error]` cannot be resolved, ignoring it...
warning: `[error]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:64:30
|
LL | * time to introduce a link [error]
| ^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error]` cannot be resolved, ignoring it...
warning: `[error]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:68:1
|
LL | #[doc = "single line [error]"]
Expand All @@ -83,7 +83,7 @@ LL | #[doc = "single line [error]"]
^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error]` cannot be resolved, ignoring it...
warning: `[error]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:71:1
|
LL | #[doc = "single line with \"escaping\" [error]"]
Expand All @@ -95,7 +95,7 @@ LL | #[doc = "single line with \"escaping\" [error]"]
^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error]` cannot be resolved, ignoring it...
warning: `[error]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:74:1
|
LL | / /// Item docs.
Expand All @@ -109,47 +109,47 @@ LL | | /// [error]
^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error1]` cannot be resolved, ignoring it...
warning: `[error1]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:80:11
|
LL | /// docs [error1]
| ^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[error2]` cannot be resolved, ignoring it...
warning: `[error2]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:82:11
|
LL | /// docs [error2]
| ^^^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[BarA]` cannot be resolved, ignoring it...
warning: `[BarA]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:21:10
|
LL | /// bar [BarA] bar
| ^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[BarB]` cannot be resolved, ignoring it...
warning: `[BarB]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:27:9
|
LL | * bar [BarB] bar
| ^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[BarC]` cannot be resolved, ignoring it...
warning: `[BarC]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:34:6
|
LL | bar [BarC] bar
| ^^^^ cannot be resolved, ignoring
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[BarD]` cannot be resolved, ignoring it...
warning: `[BarD]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:45:1
|
LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
Expand All @@ -161,7 +161,7 @@ LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

warning: `[BarF]` cannot be resolved, ignoring it...
warning: `[BarF]` cannot be resolved, ignoring it.
--> $DIR/intra-links-warning.rs:50:9
|
LL | #[doc = $f]
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/lint-group.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(private_doc_tests)]` implied by `#[deny(rustdoc)]`

error: `[error]` cannot be resolved, ignoring it...
error: `[error]` cannot be resolved, ignoring it.
--> $DIR/lint-group.rs:9:29
|
LL | /// what up, let's make an [error]
Expand Down
12 changes: 12 additions & 0 deletions src/test/rustdoc/intra-links-anchors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// I want...
///
/// # Anchor!
pub struct Something;

// @has intra_links_anchors/struct.SomeOtherType.html
// @has - '//a/@href' '../intra_links_anchors/struct.Something.html#Anchor!'

/// I want...
///
/// To link to [Something#Anchor!]
pub struct SomeOtherType;