Skip to content

Commit d67eb1f

Browse files
committed
Don't suggest \[ \] if there's a :: in the path
1 parent f2826d9 commit d67eb1f

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
592592
/// (such as having invalid URL fragments or being in the wrong namespace).
593593
fn check_full_res(
594594
&self,
595-
// TODO: is this parameter actually needed, since we return results for the wrong namespace?
596595
ns: Namespace,
597596
path_str: &str,
598597
base_node: Option<DefId>,
@@ -1511,7 +1510,13 @@ fn resolution_failure(
15111510
continue;
15121511
}
15131512
diag.note(&format!("no item named `{}` is in scope", base));
1514-
diag.help(r#"to escape `[` and `]` characters, add '\' before them like `\[` or `\]`"#);
1513+
// If the link has `::` in the path, assume it's meant to be an intra-doc link
1514+
if !path_str.contains("::") {
1515+
// Otherwise, the `[]` might be unrelated.
1516+
// FIXME(https://github.com/raphlinus/pulldown-cmark/issues/373):
1517+
// don't show this for autolinks (`<>`), `()` style links, or reference links
1518+
diag.help(r#"to escape `[` and `]` characters, add '\' before them like `\[` or `\]`"#);
1519+
}
15151520
}
15161521
ResolutionFailure::Dummy => continue,
15171522
ResolutionFailure::WrongNamespace(res, expected_ns) => {

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

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/// [path::to::nonexistent::module]
88
//~^ ERROR unresolved link
99
//~| NOTE no item named `path` is in scope
10-
//~| HELP to escape
1110

1211
/// [std::io::not::here]
1312
//~^ ERROR unresolved link
@@ -67,7 +66,6 @@ impl S {
6766
/// [T::h!]
6867
//~^ ERROR unresolved link
6968
//~| NOTE no item named `T::h`
70-
//~| HELP to escape
7169
pub trait T {
7270
fn g() {}
7371
}

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

+13-15
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,73 @@ note: the lint level is defined here
1010
LL | #![deny(broken_intra_doc_links)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^
1212
= note: no item named `path` is in scope
13-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1413

1514
error: unresolved link to `std::io::not::here`
16-
--> $DIR/intra-link-errors.rs:13:6
15+
--> $DIR/intra-link-errors.rs:12:6
1716
|
1817
LL | /// [std::io::not::here]
1918
| ^^^^^^^^^^^^^^^^^^
2019
|
2120
= note: the module `io` has no inner item named `not`
2221

2322
error: unresolved link to `std::io::Error::x`
24-
--> $DIR/intra-link-errors.rs:17:6
23+
--> $DIR/intra-link-errors.rs:16:6
2524
|
2625
LL | /// [std::io::Error::x]
2726
| ^^^^^^^^^^^^^^^^^
2827
|
2928
= note: the struct `Error` has no field or associated item named `x`
3029

3130
error: unresolved link to `std::io::ErrorKind::x`
32-
--> $DIR/intra-link-errors.rs:21:6
31+
--> $DIR/intra-link-errors.rs:20:6
3332
|
3433
LL | /// [std::io::ErrorKind::x]
3534
| ^^^^^^^^^^^^^^^^^^^^^
3635
|
3736
= note: the enum `ErrorKind` has no variant or associated item named `x`
3837

3938
error: unresolved link to `f::A`
40-
--> $DIR/intra-link-errors.rs:25:6
39+
--> $DIR/intra-link-errors.rs:24:6
4140
|
4241
LL | /// [f::A]
4342
| ^^^^
4443
|
4544
= note: `f` is a function, not a module or type, and cannot have associated items
4645

4746
error: unresolved link to `S::A`
48-
--> $DIR/intra-link-errors.rs:29:6
47+
--> $DIR/intra-link-errors.rs:28:6
4948
|
5049
LL | /// [S::A]
5150
| ^^^^
5251
|
5352
= note: the struct `S` has no field or associated item named `A`
5453

5554
error: unresolved link to `S::fmt`
56-
--> $DIR/intra-link-errors.rs:33:6
55+
--> $DIR/intra-link-errors.rs:32:6
5756
|
5857
LL | /// [S::fmt]
5958
| ^^^^^^
6059
|
6160
= note: the struct `S` has no field or associated item named `fmt`
6261

6362
error: unresolved link to `E::D`
64-
--> $DIR/intra-link-errors.rs:37:6
63+
--> $DIR/intra-link-errors.rs:36:6
6564
|
6665
LL | /// [E::D]
6766
| ^^^^
6867
|
6968
= note: the enum `E` has no variant or associated item named `D`
7069

7170
error: unresolved link to `u8::not_found`
72-
--> $DIR/intra-link-errors.rs:41:6
71+
--> $DIR/intra-link-errors.rs:40:6
7372
|
7473
LL | /// [u8::not_found]
7574
| ^^^^^^^^^^^^^
7675
|
7776
= note: the builtin type `u8` does not have an associated item named `not_found`
7877

7978
error: unresolved link to `S`
80-
--> $DIR/intra-link-errors.rs:45:6
79+
--> $DIR/intra-link-errors.rs:44:6
8180
|
8281
LL | /// [S!]
8382
| ^^
@@ -89,32 +88,31 @@ LL | /// [struct@S]
8988
| ^^^^^^^^
9089

9190
error: unresolved link to `T::g`
92-
--> $DIR/intra-link-errors.rs:63:6
91+
--> $DIR/intra-link-errors.rs:62:6
9392
|
9493
LL | /// [type@T::g]
9594
| ^^^^^^^^^ help: to link to the associated function, add parentheses: `T::g()`
9695
|
9796
= note: this link resolves to the associated function `g`, which is not in the type namespace
9897

9998
error: unresolved link to `T::h`
100-
--> $DIR/intra-link-errors.rs:68:6
99+
--> $DIR/intra-link-errors.rs:67:6
101100
|
102101
LL | /// [T::h!]
103102
| ^^^^^
104103
|
105104
= note: no item named `T::h` is in scope
106-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
107105

108106
error: unresolved link to `S::h`
109-
--> $DIR/intra-link-errors.rs:55:6
107+
--> $DIR/intra-link-errors.rs:54:6
110108
|
111109
LL | /// [type@S::h]
112110
| ^^^^^^^^^ help: to link to the associated function, add parentheses: `S::h()`
113111
|
114112
= note: this link resolves to the associated function `h`, which is not in the type namespace
115113

116114
error: unresolved link to `m`
117-
--> $DIR/intra-link-errors.rs:76:6
115+
--> $DIR/intra-link-errors.rs:74:6
118116
|
119117
LL | /// [m()]
120118
| ^^^ help: to link to the macro, add an exclamation mark: `m!`

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

-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ LL | //! Test with [Foo::baz], [Bar::foo], ...
1414
| ^^^^^^^^
1515
|
1616
= note: no item named `Bar` is in scope
17-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1817

1918
warning: unresolved link to `Uniooon::X`
2019
--> $DIR/intra-links-warning.rs:6:13
@@ -23,7 +22,6 @@ LL | //! , [Uniooon::X] and [Qux::Z].
2322
| ^^^^^^^^^^
2423
|
2524
= note: no item named `Uniooon` is in scope
26-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
2725

2826
warning: unresolved link to `Qux::Z`
2927
--> $DIR/intra-links-warning.rs:6:30
@@ -32,7 +30,6 @@ LL | //! , [Uniooon::X] and [Qux::Z].
3230
| ^^^^^^
3331
|
3432
= note: no item named `Qux` is in scope
35-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
3633

3734
warning: unresolved link to `Uniooon::X`
3835
--> $DIR/intra-links-warning.rs:10:14
@@ -41,7 +38,6 @@ LL | //! , [Uniooon::X] and [Qux::Z].
4138
| ^^^^^^^^^^
4239
|
4340
= note: no item named `Uniooon` is in scope
44-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
4541

4642
warning: unresolved link to `Qux::Z`
4743
--> $DIR/intra-links-warning.rs:10:31
@@ -50,7 +46,6 @@ LL | //! , [Uniooon::X] and [Qux::Z].
5046
| ^^^^^^
5147
|
5248
= note: no item named `Qux` is in scope
53-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
5449

5550
warning: unresolved link to `Qux:Y`
5651
--> $DIR/intra-links-warning.rs:14:13

0 commit comments

Comments
 (0)