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`
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
warning: `[error]` cannot be resolved, ignoring it.
1+
warning: unresolved link to `error`
22
--> $DIR/intra-links-warning-crlf.rs:7:6
33
|
44
LL | /// [error]
5-
| ^^^^^ cannot be resolved, ignoring
5+
| ^^^^^ unresolved link
66
|
77
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
8-
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
8+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
99

10-
warning: `[error1]` cannot be resolved, ignoring it.
10+
warning: unresolved link to `error1`
1111
--> $DIR/intra-links-warning-crlf.rs:12:11
1212
|
1313
LL | /// docs [error1]
14-
| ^^^^^^ cannot be resolved, ignoring
14+
| ^^^^^^ unresolved link
1515
|
16-
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
16+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1717

18-
warning: `[error2]` cannot be resolved, ignoring it.
18+
warning: unresolved link to `error2`
1919
--> $DIR/intra-links-warning-crlf.rs:15:11
2020
|
2121
LL | /// docs [error2]
22-
| ^^^^^^ cannot be resolved, ignoring
22+
| ^^^^^^ unresolved link
2323
|
24-
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
24+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
2525

26-
warning: `[error]` cannot be resolved, ignoring it.
26+
warning: unresolved link to `error`
2727
--> $DIR/intra-links-warning-crlf.rs:23:20
2828
|
2929
LL | * It also has an [error].
30-
| ^^^^^ cannot be resolved, ignoring
30+
| ^^^^^ unresolved link
3131
|
32-
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
32+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
3333

3434
warning: 4 warnings emitted
3535

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
// check-pass
22

33
//! Test with [Foo::baz], [Bar::foo], ...
4-
//~^ WARNING `[Foo::baz]` cannot be resolved
5-
//~| WARNING `[Bar::foo]` cannot be resolved
4+
//~^ WARNING `Foo::baz`
5+
//~| WARNING `Bar::foo`
66
//! , [Uniooon::X] and [Qux::Z].
7-
//~^ WARNING `[Uniooon::X]` cannot be resolved
8-
//~| WARNING `[Qux::Z]` cannot be resolved
7+
//~^ WARNING `Uniooon::X`
8+
//~| WARNING `Qux::Z`
99
//!
1010
//! , [Uniooon::X] and [Qux::Z].
11-
//~^ WARNING `[Uniooon::X]` cannot be resolved
12-
//~| WARNING `[Qux::Z]` cannot be resolved
11+
//~^ WARNING `Uniooon::X`
12+
//~| WARNING `Qux::Z`
1313

1414
/// [Qux:Y]
15-
//~^ WARNING `[Qux:Y]` cannot be resolved
15+
//~^ WARNING `Qux:Y`
1616
pub struct Foo {
1717
pub bar: usize,
1818
}
1919

2020
/// Foo
21-
/// bar [BarA] bar //~ WARNING `[BarA]` cannot be resolved
21+
/// bar [BarA] bar //~ WARNING `BarA`
2222
/// baz
2323
pub fn a() {}
2424

2525
/**
2626
* Foo
27-
* bar [BarB] bar //~ WARNING `[BarB]` cannot be resolved
27+
* bar [BarB] bar //~ WARNING `BarB`
2828
* baz
2929
*/
3030
pub fn b() {}
3131

3232
/** Foo
3333
34-
bar [BarC] bar //~ WARNING `[BarC]` cannot be resolved
34+
bar [BarC] bar //~ WARNING `BarC`
3535
baz
3636
3737
let bar_c_1 = 0;
@@ -42,43 +42,43 @@ baz
4242
*/
4343
pub fn c() {}
4444

45-
#[doc = "Foo\nbar [BarD] bar\nbaz"] //~ WARNING `[BarD]` cannot be resolved
45+
#[doc = "Foo\nbar [BarD] bar\nbaz"] //~ WARNING `BarD`
4646
pub fn d() {}
4747

4848
macro_rules! f {
4949
($f:expr) => {
50-
#[doc = $f] //~ WARNING `[BarF]` cannot be resolved
50+
#[doc = $f] //~ WARNING `BarF`
5151
pub fn f() {}
5252
}
5353
}
5454
f!("Foo\nbar [BarF] bar\nbaz");
5555

5656
/** # for example,
5757
*
58-
* time to introduce a link [error]*/ //~ WARNING `[error]` cannot be resolved
58+
* time to introduce a link [error]*/ //~ WARNING `error`
5959
pub struct A;
6060

6161
/**
6262
* # for example,
6363
*
64-
* time to introduce a link [error] //~ WARNING `[error]` cannot be resolved
64+
* time to introduce a link [error] //~ WARNING `error`
6565
*/
6666
pub struct B;
6767

68-
#[doc = "single line [error]"] //~ WARNING `[error]` cannot be resolved
68+
#[doc = "single line [error]"] //~ WARNING `error`
6969
pub struct C;
7070

71-
#[doc = "single line with \"escaping\" [error]"] //~ WARNING `[error]` cannot be resolved
71+
#[doc = "single line with \"escaping\" [error]"] //~ WARNING `error`
7272
pub struct D;
7373

74-
/// Item docs. //~ WARNING `[error]` cannot be resolved
74+
/// Item docs. //~ WARNING `error`
7575
#[doc="Hello there!"]
7676
/// [error]
7777
pub struct E;
7878

7979
///
80-
/// docs [error1] //~ WARNING `[error1]` cannot be resolved
80+
/// docs [error1] //~ WARNING `error1`
8181
82-
/// docs [error2] //~ WARNING `[error2]` cannot be resolved
82+
/// docs [error2] //~ WARNING `error2`
8383
///
8484
pub struct F;

0 commit comments

Comments
 (0)