Skip to content

Commit aa9b718

Browse files
committed
Improve error messages
1 parent 21fb9df commit aa9b718

8 files changed

+39
-40
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1577,13 +1577,12 @@ fn resolution_failure(
15771577
// See if this was a module: `[path]` or `[std::io::nope]`
15781578
if let Some(module) = last_found_module {
15791579
let note = if partial_res.is_some() {
1580+
// Part of the link resolved; e.g. `std::io::nonexistent`
15801581
let module_name = collector.cx.tcx.item_name(module);
1581-
format!(
1582-
"the module `{}` contains no item named `{}`",
1583-
module_name, unresolved
1584-
)
1582+
format!("no item named `{}` in module `{}`", unresolved, module_name)
15851583
} else {
1586-
format!("there is no item named `{}` in scope", unresolved)
1584+
// None of the link resolved; e.g. `Notimported`
1585+
format!("no item named `{}` in scope", unresolved)
15871586
};
15881587
if let Some(span) = sp {
15891588
diag.span_label(span, &note);

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

+1-1
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-
| ^^ there is no item named `v2` in scope
5+
| ^^ no item named `v2` in scope
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

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
77
/// [path::to::nonexistent::module]
88
//~^ ERROR unresolved link
9-
//~| NOTE there is no item named `path` in scope
9+
//~| NOTE no item named `path` in scope
1010

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

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

1919
/// [std::io::not::here]
2020
//~^ ERROR unresolved link
21-
//~| NOTE `io` contains no item named `not`
21+
//~| NOTE no item named `not` in module `io`
2222

2323
/// [type@std::io::not::here]
2424
//~^ ERROR unresolved link
25-
//~| NOTE `io` contains no item named `not`
25+
//~| NOTE no item named `not` in module `io`
2626

2727
/// [std::io::Error::x]
2828
//~^ ERROR unresolved link

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

+5-5
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-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ there is no item named `path` in scope
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in scope
66
|
77
note: the lint level is defined here
88
--> $DIR/intra-link-errors.rs:1:9
@@ -14,25 +14,25 @@ error: unresolved link to `path::to::nonexistent::macro`
1414
--> $DIR/intra-link-errors.rs:11:6
1515
|
1616
LL | /// [path::to::nonexistent::macro!]
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ there is no item named `path` in scope
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in scope
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-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ there is no item named `path` in scope
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in scope
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` contains no item named `not`
29+
| ^^^^^^^^^^^^^^^^^^ no item named `not` in module `io`
3030

3131
error: unresolved link to `std::io::not::here`
3232
--> $DIR/intra-link-errors.rs:23:6
3333
|
3434
LL | /// [type@std::io::not::here]
35-
| ^^^^^^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not`
35+
| ^^^^^^^^^^^^^^^^^^^^^^^ no item named `not` in module `io`
3636

3737
error: unresolved link to `std::io::Error::x`
3838
--> $DIR/intra-link-errors.rs:27:6

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

+1-1
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-
| ^ there is no item named `i` in scope
5+
| ^ no item named `i` in scope
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

+4-4
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-
| ^^^^^ there is no item named `error` in scope
5+
| ^^^^^ no item named `error` in scope
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-
| ^^^^^^ there is no item named `error1` in scope
14+
| ^^^^^^ no item named `error1` in scope
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-
| ^^^^^^ there is no item named `error2` in scope
22+
| ^^^^^^ no item named `error2` in scope
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-
| ^^^^^ there is no item named `error` in scope
30+
| ^^^^^ no item named `error` in scope
3131
|
3232
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
3333

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

+18-18
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-
| ^^^^^^^^ there is no item named `Bar` in scope
13+
| ^^^^^^^^ no item named `Bar` in scope
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-
| ^^^^^^^^^^ there is no item named `Uniooon` in scope
19+
| ^^^^^^^^^^ no item named `Uniooon` in scope
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-
| ^^^^^^ there is no item named `Qux` in scope
25+
| ^^^^^^ no item named `Qux` in scope
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-
| ^^^^^^^^^^ there is no item named `Uniooon` in scope
31+
| ^^^^^^^^^^ no item named `Uniooon` in scope
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-
| ^^^^^^ there is no item named `Qux` in scope
37+
| ^^^^^^ no item named `Qux` in scope
3838

3939
warning: unresolved link to `Qux:Y`
4040
--> $DIR/intra-links-warning.rs:14:13
4141
|
4242
LL | /// [Qux:Y]
43-
| ^^^^^ there is no item named `Qux:Y` in scope
43+
| ^^^^^ no item named `Qux:Y` in scope
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-
| ^^^^^ there is no item named `error` in scope
51+
| ^^^^^ no item named `error` in scope
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-
| ^^^^^ there is no item named `error` in scope
59+
| ^^^^^ no item named `error` in scope
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: there is no item named `error` in scope
73+
= note: no item named `error` in scope
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: there is no item named `error` in scope
86+
= note: no item named `error` in scope
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: there is no item named `error` in scope
101+
= note: no item named `error` in scope
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-
| ^^^^^^ there is no item named `error1` in scope
108+
| ^^^^^^ no item named `error1` in scope
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-
| ^^^^^^ there is no item named `error2` in scope
116+
| ^^^^^^ no item named `error2` in scope
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-
| ^^^^ there is no item named `BarA` in scope
124+
| ^^^^ no item named `BarA` in scope
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-
| ^^^^ there is no item named `BarB` in scope
132+
| ^^^^ no item named `BarB` in scope
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-
| ^^^^ there is no item named `BarC` in scope
140+
| ^^^^ no item named `BarC` in scope
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: there is no item named `BarD` in scope
154+
= note: no item named `BarD` in scope
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: there is no item named `BarF` in scope
170+
= note: no item named `BarF` in scope
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

+1-1
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-
| ^^^^^ there is no item named `error` in scope
35+
| ^^^^^ no item named `error` in scope
3636
|
3737
note: the lint level is defined here
3838
--> $DIR/lint-group.rs:7:9

0 commit comments

Comments
 (0)