Skip to content

Commit 71bdb84

Browse files
committed
Auto merge of rust-lang#76955 - jyn514:refactor-diagnostics, r=euclio
Refactor and fix intra-doc link diagnostics, and fix links to primitives Closes rust-lang#76925, closes rust-lang#76693, closes rust-lang#76692. Originally I only meant to fix rust-lang#76925. But the hack with `has_primitive` was so bad it was easier to fix the primitive issues than to try and work around it. Note that this still has one bug: `std::primitive::i32::MAX` does not resolve. However, this fixes the ICE so I'm fine with fixing the link in a later PR. This is part of a series of refactors to make rust-lang#76467 possible. This is best reviewed commit-by-commit; it has detailed commit messages. r? `@euclio`
2 parents c9e5e6a + 049d29b commit 71bdb84

11 files changed

+329
-279
lines changed

compiler/rustc_hir/src/hir.rs

+24
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,30 @@ pub enum PrimTy {
20042004
Char,
20052005
}
20062006

2007+
impl PrimTy {
2008+
pub fn name_str(self) -> &'static str {
2009+
match self {
2010+
PrimTy::Int(i) => i.name_str(),
2011+
PrimTy::Uint(u) => u.name_str(),
2012+
PrimTy::Float(f) => f.name_str(),
2013+
PrimTy::Str => "str",
2014+
PrimTy::Bool => "bool",
2015+
PrimTy::Char => "char",
2016+
}
2017+
}
2018+
2019+
pub fn name(self) -> Symbol {
2020+
match self {
2021+
PrimTy::Int(i) => i.name(),
2022+
PrimTy::Uint(u) => u.name(),
2023+
PrimTy::Float(f) => f.name(),
2024+
PrimTy::Str => sym::str,
2025+
PrimTy::Bool => sym::bool,
2026+
PrimTy::Char => sym::char,
2027+
}
2028+
}
2029+
}
2030+
20072031
#[derive(Debug, HashStable_Generic)]
20082032
pub struct BareFnTy<'hir> {
20092033
pub unsafety: Unsafety,

src/librustdoc/passes/collect_intra_doc_links.rs

+204-231
Large diffs are not rendered by default.

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-
| ^^ 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

+22-5
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
@@ -46,7 +54,16 @@
4654

4755
/// [u8::not_found]
4856
//~^ ERROR unresolved link
49-
//~| NOTE the builtin type `u8` does not have an associated item named `not_found`
57+
//~| NOTE the builtin type `u8` has no associated item named `not_found`
58+
59+
/// [std::primitive::u8::not_found]
60+
//~^ ERROR unresolved link
61+
//~| NOTE the builtin type `u8` has no associated item named `not_found`
62+
63+
/// [type@Vec::into_iter]
64+
//~^ ERROR unresolved link
65+
//~| HELP to link to the associated function, add parentheses
66+
//~| NOTE this link resolves to the associated function `into_iter`
5067

5168
/// [S!]
5269
//~^ ERROR unresolved link

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

+45-18
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,91 @@ 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+
| ^^^^^^^^^^^^^ the builtin type `u8` has no associated item named `not_found`
84+
85+
error: unresolved link to `std::primitive::u8::not_found`
86+
--> $DIR/intra-link-errors.rs:59:6
87+
|
88+
LL | /// [std::primitive::u8::not_found]
89+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the builtin type `u8` has no associated item named `not_found`
90+
91+
error: unresolved link to `Vec::into_iter`
92+
--> $DIR/intra-link-errors.rs:63:6
93+
|
94+
LL | /// [type@Vec::into_iter]
95+
| ^^^^^^^^^^^^^^^^^^^
96+
| |
97+
| this link resolves to the associated function `into_iter`, which is not in the type namespace
98+
| help: to link to the associated function, add parentheses: `Vec::into_iter()`
7299

73100
error: unresolved link to `S`
74-
--> $DIR/intra-link-errors.rs:51:6
101+
--> $DIR/intra-link-errors.rs:68:6
75102
|
76103
LL | /// [S!]
77104
| ^^
@@ -80,7 +107,7 @@ LL | /// [S!]
80107
| help: to link to the struct, prefix with `struct@`: `struct@S`
81108

82109
error: unresolved link to `T::g`
83-
--> $DIR/intra-link-errors.rs:69:6
110+
--> $DIR/intra-link-errors.rs:86:6
84111
|
85112
LL | /// [type@T::g]
86113
| ^^^^^^^^^
@@ -89,13 +116,13 @@ LL | /// [type@T::g]
89116
| help: to link to the associated function, add parentheses: `T::g()`
90117

91118
error: unresolved link to `T::h`
92-
--> $DIR/intra-link-errors.rs:74:6
119+
--> $DIR/intra-link-errors.rs:91:6
93120
|
94121
LL | /// [T::h!]
95122
| ^^^^^ the trait `T` has no macro named `h`
96123

97124
error: unresolved link to `S::h`
98-
--> $DIR/intra-link-errors.rs:61:6
125+
--> $DIR/intra-link-errors.rs:78:6
99126
|
100127
LL | /// [type@S::h]
101128
| ^^^^^^^^^
@@ -104,13 +131,13 @@ LL | /// [type@S::h]
104131
| help: to link to the associated function, add parentheses: `S::h()`
105132

106133
error: unresolved link to `m`
107-
--> $DIR/intra-link-errors.rs:81:6
134+
--> $DIR/intra-link-errors.rs:98:6
108135
|
109136
LL | /// [m()]
110137
| ^^^
111138
| |
112139
| this link resolves to the macro `m`, which is not in the value namespace
113140
| help: to link to the macro, add an exclamation mark: `m!`
114141

115-
error: aborting due to 16 previous errors
142+
error: aborting due to 20 previous errors
116143

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-
| ^ 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

+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-
| ^^^^^ 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

0 commit comments

Comments
 (0)