Skip to content

Commit dd7b8c8

Browse files
committed
Perform most diagnostic lookups in resolution_failure
Previously, these were spread throughout the codebase. This had two drawbacks: 1. It caused the fast path to be slower: even if a link resolved, rustdoc would still perform various lookups for the error diagnostic. 2. It was inconsistent and didn't always give all diagnostics (rust-lang#76925) Now, diagnostics only perform expensive lookups in the error case. Additionally, the error handling is much more consistent, both in wording and behavior. - Remove `CannotHaveAssociatedItems`, `NotInScope`, `NoAssocItem`, and `NotAVariant` in favor of the more general `NotResolved` `resolution_failure` will now look up which of the four above categories is relevant, instead of requiring the rest of the code to be consistent and accurate in which it picked. - Remove unnecessary lookups throughout the intra-doc link pass. These are now done by `resolution_failure`. + Remove unnecessary `extra_fragment` argument to `variant_field()`; it was only used to do lookups on failure. + Remove various lookups related to associated items + Remove distinction between 'not in scope' and 'no associated item' - Don't perform unnecessary copies - Remove unused variables and code - Update tests - Note why looking at other namespaces is still necessary - 'has no inner item' -> 'contains no item' bless tests
1 parent cbc5e4d commit dd7b8c8

9 files changed

+263
-253
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 191 additions & 206 deletions
Large diffs are not rendered by default.

src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unresolved link to `v2`
22
--> $DIR/deny-intra-link-resolution-failure.rs:3:6
33
|
44
LL | /// [v2]
5-
| ^^ no item named `v2` in `deny_intra_link_resolution_failure`
5+
| ^^ the module `deny_intra_link_resolution_failure` contains no item named `v2`
66
|
77
note: the lint level is defined here
88
--> $DIR/deny-intra-link-resolution-failure.rs:1:9

src/test/rustdoc-ui/intra-link-errors.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
77
/// [path::to::nonexistent::module]
88
//~^ ERROR unresolved link
9-
//~| NOTE no item named `path` in `intra_link_errors`
9+
//~| NOTE `intra_link_errors` contains no item named `path`
1010

1111
/// [path::to::nonexistent::macro!]
1212
//~^ ERROR unresolved link
13-
//~| NOTE no item named `path` in `intra_link_errors`
13+
//~| NOTE `intra_link_errors` contains no item named `path`
1414

1515
/// [type@path::to::nonexistent::type]
1616
//~^ ERROR unresolved link
17-
//~| NOTE no item named `path` in `intra_link_errors`
17+
//~| NOTE `intra_link_errors` contains no item named `path`
1818

1919
/// [std::io::not::here]
2020
//~^ ERROR unresolved link
21-
//~| NOTE the module `io` has no inner item
21+
//~| NOTE `io` contains no item named `not`
22+
23+
/// [type@std::io::not::here]
24+
//~^ ERROR unresolved link
25+
//~| NOTE `io` contains no item named `not`
2226

2327
/// [std::io::Error::x]
2428
//~^ ERROR unresolved link
@@ -32,6 +36,10 @@
3236
//~^ ERROR unresolved link
3337
//~| NOTE `f` is a function, not a module
3438

39+
/// [f::A!]
40+
//~^ ERROR unresolved link
41+
//~| NOTE `f` is a function, not a module
42+
3543
/// [S::A]
3644
//~^ ERROR unresolved link
3745
//~| NOTE struct `S` has no field or associated item

src/test/rustdoc-ui/intra-link-errors.stderr

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unresolved link to `path::to::nonexistent::module`
22
--> $DIR/intra-link-errors.rs:7:6
33
|
44
LL | /// [path::to::nonexistent::module]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in `intra_link_errors`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path`
66
|
77
note: the lint level is defined here
88
--> $DIR/intra-link-errors.rs:1:9
@@ -14,64 +14,79 @@ error: unresolved link to `path::to::nonexistent::macro`
1414
--> $DIR/intra-link-errors.rs:11:6
1515
|
1616
LL | /// [path::to::nonexistent::macro!]
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in `intra_link_errors`
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path`
1818

1919
error: unresolved link to `path::to::nonexistent::type`
2020
--> $DIR/intra-link-errors.rs:15:6
2121
|
2222
LL | /// [type@path::to::nonexistent::type]
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in `intra_link_errors`
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path`
2424

2525
error: unresolved link to `std::io::not::here`
2626
--> $DIR/intra-link-errors.rs:19:6
2727
|
2828
LL | /// [std::io::not::here]
29-
| ^^^^^^^^^^^^^^^^^^ the module `io` has no inner item named `not`
29+
| ^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not`
3030

31-
error: unresolved link to `std::io::Error::x`
31+
error: unresolved link to `std::io::not::here`
3232
--> $DIR/intra-link-errors.rs:23:6
3333
|
34+
LL | /// [type@std::io::not::here]
35+
| ^^^^^^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not`
36+
37+
error: unresolved link to `std::io::Error::x`
38+
--> $DIR/intra-link-errors.rs:27:6
39+
|
3440
LL | /// [std::io::Error::x]
3541
| ^^^^^^^^^^^^^^^^^ the struct `Error` has no field or associated item named `x`
3642

3743
error: unresolved link to `std::io::ErrorKind::x`
38-
--> $DIR/intra-link-errors.rs:27:6
44+
--> $DIR/intra-link-errors.rs:31:6
3945
|
4046
LL | /// [std::io::ErrorKind::x]
4147
| ^^^^^^^^^^^^^^^^^^^^^ the enum `ErrorKind` has no variant or associated item named `x`
4248

4349
error: unresolved link to `f::A`
44-
--> $DIR/intra-link-errors.rs:31:6
50+
--> $DIR/intra-link-errors.rs:35:6
4551
|
4652
LL | /// [f::A]
4753
| ^^^^ `f` is a function, not a module or type, and cannot have associated items
4854

55+
error: unresolved link to `f::A`
56+
--> $DIR/intra-link-errors.rs:39:6
57+
|
58+
LL | /// [f::A!]
59+
| ^^^^^ `f` is a function, not a module or type, and cannot have associated items
60+
4961
error: unresolved link to `S::A`
50-
--> $DIR/intra-link-errors.rs:35:6
62+
--> $DIR/intra-link-errors.rs:43:6
5163
|
5264
LL | /// [S::A]
5365
| ^^^^ the struct `S` has no field or associated item named `A`
5466

5567
error: unresolved link to `S::fmt`
56-
--> $DIR/intra-link-errors.rs:39:6
68+
--> $DIR/intra-link-errors.rs:47:6
5769
|
5870
LL | /// [S::fmt]
5971
| ^^^^^^ the struct `S` has no field or associated item named `fmt`
6072

6173
error: unresolved link to `E::D`
62-
--> $DIR/intra-link-errors.rs:43:6
74+
--> $DIR/intra-link-errors.rs:51:6
6375
|
6476
LL | /// [E::D]
6577
| ^^^^ the enum `E` has no variant or associated item named `D`
6678

6779
error: unresolved link to `u8::not_found`
68-
--> $DIR/intra-link-errors.rs:47:6
80+
--> $DIR/intra-link-errors.rs:55:6
6981
|
7082
LL | /// [u8::not_found]
71-
| ^^^^^^^^^^^^^ the builtin type `u8` does not have an associated item named `not_found`
83+
| ^^^^^^^^^^^^^
84+
| |
85+
| the builtin type `u8` does not have an associated item named `not_found`
86+
| the builtin type `u8` has no builtin type named `not_found`
7287

7388
error: unresolved link to `S`
74-
--> $DIR/intra-link-errors.rs:51:6
89+
--> $DIR/intra-link-errors.rs:59:6
7590
|
7691
LL | /// [S!]
7792
| ^^
@@ -80,7 +95,7 @@ LL | /// [S!]
8095
| help: to link to the struct, prefix with `struct@`: `struct@S`
8196

8297
error: unresolved link to `T::g`
83-
--> $DIR/intra-link-errors.rs:69:6
98+
--> $DIR/intra-link-errors.rs:77:6
8499
|
85100
LL | /// [type@T::g]
86101
| ^^^^^^^^^
@@ -89,13 +104,13 @@ LL | /// [type@T::g]
89104
| help: to link to the associated function, add parentheses: `T::g()`
90105

91106
error: unresolved link to `T::h`
92-
--> $DIR/intra-link-errors.rs:74:6
107+
--> $DIR/intra-link-errors.rs:82:6
93108
|
94109
LL | /// [T::h!]
95110
| ^^^^^ the trait `T` has no macro named `h`
96111

97112
error: unresolved link to `S::h`
98-
--> $DIR/intra-link-errors.rs:61:6
113+
--> $DIR/intra-link-errors.rs:69:6
99114
|
100115
LL | /// [type@S::h]
101116
| ^^^^^^^^^
@@ -104,13 +119,13 @@ LL | /// [type@S::h]
104119
| help: to link to the associated function, add parentheses: `S::h()`
105120

106121
error: unresolved link to `m`
107-
--> $DIR/intra-link-errors.rs:81:6
122+
--> $DIR/intra-link-errors.rs:89:6
108123
|
109124
LL | /// [m()]
110125
| ^^^
111126
| |
112127
| this link resolves to the macro `m`, which is not in the value namespace
113128
| help: to link to the macro, add an exclamation mark: `m!`
114129

115-
error: aborting due to 16 previous errors
130+
error: aborting due to 18 previous errors
116131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unresolved link to `i`
22
--> $DIR/intra-link-span-ice-55723.rs:9:10
33
|
44
LL | /// (arr[i])
5-
| ^ no item named `i` in `intra_link_span_ice_55723`
5+
| ^ the module `intra_link_span_ice_55723` contains no item named `i`
66
|
77
note: the lint level is defined here
88
--> $DIR/intra-link-span-ice-55723.rs:1:9

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: unresolved link to `error`
22
--> $DIR/intra-links-warning-crlf.rs:7:6
33
|
44
LL | /// [error]
5-
| ^^^^^ no item named `error` in `intra_links_warning_crlf`
5+
| ^^^^^ the module `intra_links_warning_crlf` contains no item named `error`
66
|
77
= note: `#[warn(broken_intra_doc_links)]` on by default
88
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@@ -11,23 +11,23 @@ warning: unresolved link to `error1`
1111
--> $DIR/intra-links-warning-crlf.rs:12:11
1212
|
1313
LL | /// docs [error1]
14-
| ^^^^^^ no item named `error1` in `intra_links_warning_crlf`
14+
| ^^^^^^ the module `intra_links_warning_crlf` contains no item named `error1`
1515
|
1616
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1717

1818
warning: unresolved link to `error2`
1919
--> $DIR/intra-links-warning-crlf.rs:15:11
2020
|
2121
LL | /// docs [error2]
22-
| ^^^^^^ no item named `error2` in `intra_links_warning_crlf`
22+
| ^^^^^^ the module `intra_links_warning_crlf` contains no item named `error2`
2323
|
2424
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
2525

2626
warning: unresolved link to `error`
2727
--> $DIR/intra-links-warning-crlf.rs:23:20
2828
|
2929
LL | * It also has an [error].
30-
| ^^^^^ no item named `error` in `intra_links_warning_crlf`
30+
| ^^^^^ the module `intra_links_warning_crlf` contains no item named `error`
3131
|
3232
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
3333

src/test/rustdoc-ui/intra-links-warning.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,53 @@ warning: unresolved link to `Bar::foo`
1010
--> $DIR/intra-links-warning.rs:3:35
1111
|
1212
LL | //! Test with [Foo::baz], [Bar::foo], ...
13-
| ^^^^^^^^ no item named `Bar` in `intra_links_warning`
13+
| ^^^^^^^^ the module `intra_links_warning` contains no item named `Bar`
1414

1515
warning: unresolved link to `Uniooon::X`
1616
--> $DIR/intra-links-warning.rs:6:13
1717
|
1818
LL | //! , [Uniooon::X] and [Qux::Z].
19-
| ^^^^^^^^^^ no item named `Uniooon` in `intra_links_warning`
19+
| ^^^^^^^^^^ the module `intra_links_warning` contains no item named `Uniooon`
2020

2121
warning: unresolved link to `Qux::Z`
2222
--> $DIR/intra-links-warning.rs:6:30
2323
|
2424
LL | //! , [Uniooon::X] and [Qux::Z].
25-
| ^^^^^^ no item named `Qux` in `intra_links_warning`
25+
| ^^^^^^ the module `intra_links_warning` contains no item named `Qux`
2626

2727
warning: unresolved link to `Uniooon::X`
2828
--> $DIR/intra-links-warning.rs:10:14
2929
|
3030
LL | //! , [Uniooon::X] and [Qux::Z].
31-
| ^^^^^^^^^^ no item named `Uniooon` in `intra_links_warning`
31+
| ^^^^^^^^^^ the module `intra_links_warning` contains no item named `Uniooon`
3232

3333
warning: unresolved link to `Qux::Z`
3434
--> $DIR/intra-links-warning.rs:10:31
3535
|
3636
LL | //! , [Uniooon::X] and [Qux::Z].
37-
| ^^^^^^ no item named `Qux` in `intra_links_warning`
37+
| ^^^^^^ the module `intra_links_warning` contains no item named `Qux`
3838

3939
warning: unresolved link to `Qux:Y`
4040
--> $DIR/intra-links-warning.rs:14:13
4141
|
4242
LL | /// [Qux:Y]
43-
| ^^^^^ no item named `Qux:Y` in `intra_links_warning`
43+
| ^^^^^ the module `intra_links_warning` contains no item named `Qux:Y`
4444
|
4545
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
4646

4747
warning: unresolved link to `error`
4848
--> $DIR/intra-links-warning.rs:58:30
4949
|
5050
LL | * time to introduce a link [error]*/
51-
| ^^^^^ no item named `error` in `intra_links_warning`
51+
| ^^^^^ the module `intra_links_warning` contains no item named `error`
5252
|
5353
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
5454

5555
warning: unresolved link to `error`
5656
--> $DIR/intra-links-warning.rs:64:30
5757
|
5858
LL | * time to introduce a link [error]
59-
| ^^^^^ no item named `error` in `intra_links_warning`
59+
| ^^^^^ the module `intra_links_warning` contains no item named `error`
6060
|
6161
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
6262

@@ -70,7 +70,7 @@ LL | #[doc = "single line [error]"]
7070

7171
single line [error]
7272
^^^^^
73-
= note: no item named `error` in `intra_links_warning`
73+
= note: the module `intra_links_warning` contains no item named `error`
7474
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
7575

7676
warning: unresolved link to `error`
@@ -83,7 +83,7 @@ LL | #[doc = "single line with \"escaping\" [error]"]
8383

8484
single line with "escaping" [error]
8585
^^^^^
86-
= note: no item named `error` in `intra_links_warning`
86+
= note: the module `intra_links_warning` contains no item named `error`
8787
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
8888

8989
warning: unresolved link to `error`
@@ -98,46 +98,46 @@ LL | | /// [error]
9898

9999
[error]
100100
^^^^^
101-
= note: no item named `error` in `intra_links_warning`
101+
= note: the module `intra_links_warning` contains no item named `error`
102102
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
103103

104104
warning: unresolved link to `error1`
105105
--> $DIR/intra-links-warning.rs:80:11
106106
|
107107
LL | /// docs [error1]
108-
| ^^^^^^ no item named `error1` in `intra_links_warning`
108+
| ^^^^^^ the module `intra_links_warning` contains no item named `error1`
109109
|
110110
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
111111

112112
warning: unresolved link to `error2`
113113
--> $DIR/intra-links-warning.rs:82:11
114114
|
115115
LL | /// docs [error2]
116-
| ^^^^^^ no item named `error2` in `intra_links_warning`
116+
| ^^^^^^ the module `intra_links_warning` contains no item named `error2`
117117
|
118118
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
119119

120120
warning: unresolved link to `BarA`
121121
--> $DIR/intra-links-warning.rs:21:10
122122
|
123123
LL | /// bar [BarA] bar
124-
| ^^^^ no item named `BarA` in `intra_links_warning`
124+
| ^^^^ the module `intra_links_warning` contains no item named `BarA`
125125
|
126126
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
127127

128128
warning: unresolved link to `BarB`
129129
--> $DIR/intra-links-warning.rs:27:9
130130
|
131131
LL | * bar [BarB] bar
132-
| ^^^^ no item named `BarB` in `intra_links_warning`
132+
| ^^^^ the module `intra_links_warning` contains no item named `BarB`
133133
|
134134
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
135135

136136
warning: unresolved link to `BarC`
137137
--> $DIR/intra-links-warning.rs:34:6
138138
|
139139
LL | bar [BarC] bar
140-
| ^^^^ no item named `BarC` in `intra_links_warning`
140+
| ^^^^ the module `intra_links_warning` contains no item named `BarC`
141141
|
142142
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
143143

@@ -151,7 +151,7 @@ LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
151151

152152
bar [BarD] bar
153153
^^^^
154-
= note: no item named `BarD` in `intra_links_warning`
154+
= note: the module `intra_links_warning` contains no item named `BarD`
155155
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
156156

157157
warning: unresolved link to `BarF`
@@ -167,7 +167,7 @@ LL | f!("Foo\nbar [BarF] bar\nbaz");
167167

168168
bar [BarF] bar
169169
^^^^
170-
= note: no item named `BarF` in `intra_links_warning`
170+
= note: the module `intra_links_warning` contains no item named `BarF`
171171
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
172172
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
173173

src/test/rustdoc-ui/lint-group.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ error: unresolved link to `error`
3232
--> $DIR/lint-group.rs:9:29
3333
|
3434
LL | /// what up, let's make an [error]
35-
| ^^^^^ no item named `error` in `lint_group`
35+
| ^^^^^ the module `lint_group` contains no item named `error`
3636
|
3737
note: the lint level is defined here
3838
--> $DIR/lint-group.rs:7:9

0 commit comments

Comments
 (0)