Skip to content

Commit f4079ce

Browse files
authored
Rollup merge of #74528 - euclio:intra-link-errors, r=jyn514
refactor and reword intra-doc link errors This commit refactors intra-doc link error reporting to deduplicate code and decouple error construction from the type of error. This greatly improves flexibility at each error construction site, while reducing the complexity of the diagnostic creation. This commit also rewords the diagnostics for clarity and style: - Diagnostics should not end in periods. - It's unnecessary to say "ignoring it". Since this is a warning by default, it's already clear that the link is ignored.
2 parents e811e29 + 7f3e2c0 commit f4079ce

17 files changed

+290
-298
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 173 additions & 181 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error: `[v2]` cannot be resolved, ignoring it.
1+
error: unresolved link to `v2`
22
--> $DIR/deny-intra-link-resolution-failure.rs:3:6
33
|
44
LL | /// [v2]
5-
| ^^ cannot be resolved, ignoring
5+
| ^^ unresolved link
66
|
77
note: the lint level is defined here
88
--> $DIR/deny-intra-link-resolution-failure.rs:1:9
99
|
1010
LL | #![deny(intra_doc_link_resolution_failure)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
12+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1313

1414
error: aborting due to previous error
1515

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error: `[TypeAlias::hoge]` cannot be resolved, ignoring it.
1+
error: unresolved link to `TypeAlias::hoge`
22
--> $DIR/intra-doc-alias-ice.rs:5:30
33
|
44
LL | /// [broken cross-reference](TypeAlias::hoge)
5-
| ^^^^^^^^^^^^^^^ cannot be resolved, ignoring
5+
| ^^^^^^^^^^^^^^^ unresolved link
66
|
77
note: the lint level is defined here
88
--> $DIR/intra-doc-alias-ice.rs:1:9
99
|
1010
LL | #![deny(intra_doc_link_resolution_failure)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
12+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1313

1414
error: aborting due to previous error
1515

src/test/rustdoc-ui/intra-link-span-ice-55723.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// ## For example:
88
///
99
/// (arr[i])
10-
//~^ ERROR `[i]` cannot be resolved, ignoring it.
10+
//~^ ERROR `i`
1111
pub fn test_ice() {
1212
unimplemented!();
1313
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error: `[i]` cannot be resolved, ignoring it.
1+
error: unresolved link to `i`
22
--> $DIR/intra-link-span-ice-55723.rs:9:10
33
|
44
LL | /// (arr[i])
5-
| ^ cannot be resolved, ignoring
5+
| ^ unresolved link
66
|
77
note: the lint level is defined here
88
--> $DIR/intra-link-span-ice-55723.rs:1:9
99
|
1010
LL | #![deny(intra_doc_link_resolution_failure)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
12+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1313

1414
error: aborting due to previous error
1515

src/test/rustdoc-ui/intra-links-anchors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ pub enum Enum {
2323
/// Like [Foo#hola].
2424
///
2525
/// Or maybe [Foo::f#hola].
26-
//~^ ERROR `[Foo::f#hola]` has an issue with the link anchor.
26+
//~^ ERROR `Foo::f#hola` contains an anchor
2727
pub fn foo() {}
2828

2929
/// Empty.
3030
///
3131
/// Another anchor error: [hello#people#!].
32-
//~^ ERROR `[hello#people#!]` has an issue with the link anchor.
32+
//~^ ERROR `hello#people#!` contains multiple anchors
3333
pub fn bar() {}
3434

3535
/// Empty?
3636
///
3737
/// Damn enum's variants: [Enum::A#whatever].
38-
//~^ ERROR `[Enum::A#whatever]` has an issue with the link anchor.
38+
//~^ ERROR `Enum::A#whatever` contains an anchor
3939
pub fn enum_link() {}
4040

4141
/// Primitives?
4242
///
4343
/// [u32#hello]
44-
//~^ ERROR `[u32#hello]` has an issue with the link anchor.
44+
//~^ ERROR `u32#hello` contains an anchor
4545
pub fn x() {}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
error: `[Foo::f#hola]` has an issue with the link anchor.
1+
error: `Foo::f#hola` contains an anchor, but links to struct fields are already anchored
22
--> $DIR/intra-links-anchors.rs:25:15
33
|
44
LL | /// Or maybe [Foo::f#hola].
5-
| ^^^^^^^^^^^ struct fields cannot be followed by anchors
5+
| ^^^^^^^^^^^ contains invalid anchor
66
|
77
note: the lint level is defined here
88
--> $DIR/intra-links-anchors.rs:1:9
99
|
1010
LL | #![deny(intra_doc_link_resolution_failure)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: `[hello#people#!]` has an issue with the link anchor.
13+
error: `hello#people#!` contains multiple anchors
1414
--> $DIR/intra-links-anchors.rs:31:28
1515
|
1616
LL | /// Another anchor error: [hello#people#!].
17-
| ^^^^^^^^^^^^^^ only one `#` is allowed in a link
17+
| ^^^^^^^^^^^^^^ contains invalid anchor
1818

19-
error: `[Enum::A#whatever]` has an issue with the link anchor.
19+
error: `Enum::A#whatever` contains an anchor, but links to enum variants are already anchored
2020
--> $DIR/intra-links-anchors.rs:37:28
2121
|
2222
LL | /// Damn enum's variants: [Enum::A#whatever].
23-
| ^^^^^^^^^^^^^^^^ variants cannot be followed by anchors
23+
| ^^^^^^^^^^^^^^^^ contains invalid anchor
2424

25-
error: `[u32#hello]` has an issue with the link anchor.
25+
error: `u32#hello` contains an anchor, but links to primitive types are already anchored
2626
--> $DIR/intra-links-anchors.rs:43:6
2727
|
2828
LL | /// [u32#hello]
29-
| ^^^^^^^^^ primitive types cannot be followed by anchors
29+
| ^^^^^^^^^ contains invalid anchor
3030

3131
error: aborting due to 4 previous errors
3232

src/test/rustdoc-ui/intra-links-private.public.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: `[DontDocMe]` public documentation for `DocMe` links to a private item
1+
warning: public documentation for `DocMe` links to private item `DontDocMe`
22
--> $DIR/intra-links-private.rs:6:11
33
|
44
LL | /// docs [DontDocMe]

src/test/rustdoc-ui/intra-links-private.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![cfg_attr(private, deny(intra_doc_link_resolution_failure))]
55

66
/// docs [DontDocMe]
7-
//[public]~^ WARNING `[DontDocMe]` public documentation for `DocMe` links to a private item
7+
//[public]~^ WARNING public documentation for `DocMe` links to private item `DontDocMe`
88
// FIXME: for [private] we should also make sure the link was actually generated
99
pub struct DocMe;
1010
struct DontDocMe;

src/test/rustdoc-ui/intra-links-warning-crlf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
/// [error]
88
pub struct A;
9-
//~^^ WARNING `[error]` cannot be resolved
9+
//~^^ WARNING `error`
1010

1111
///
1212
/// docs [error1]
13-
//~^ WARNING `[error1]` cannot be resolved
13+
//~^ WARNING `error1`
1414

1515
/// docs [error2]
1616
///
1717
pub struct B;
18-
//~^^^ WARNING `[error2]` cannot be resolved
18+
//~^^^ WARNING `error2`
1919

2020
/**
2121
* This is a multi-line comment.
2222
*
2323
* It also has an [error].
2424
*/
2525
pub struct C;
26-
//~^^^ WARNING `[error]` cannot be resolved
26+
//~^^^ WARNING `error`

0 commit comments

Comments
 (0)