From d67eb1f1487c04cdd2564741828cba0784ed8501 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 28 Aug 2020 00:23:24 -0400 Subject: [PATCH] Don't suggest \[ \] if there's a :: in the path --- .../passes/collect_intra_doc_links.rs | 9 ++++-- src/test/rustdoc-ui/intra-link-errors.rs | 2 -- src/test/rustdoc-ui/intra-link-errors.stderr | 28 +++++++++---------- .../rustdoc-ui/intra-links-warning.stderr | 5 ---- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 098ac13ffe2..0ae322ee11a 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -592,7 +592,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { /// (such as having invalid URL fragments or being in the wrong namespace). fn check_full_res( &self, - // TODO: is this parameter actually needed, since we return results for the wrong namespace? ns: Namespace, path_str: &str, base_node: Option, @@ -1511,7 +1510,13 @@ fn resolution_failure( continue; } diag.note(&format!("no item named `{}` is in scope", base)); - diag.help(r#"to escape `[` and `]` characters, add '\' before them like `\[` or `\]`"#); + // If the link has `::` in the path, assume it's meant to be an intra-doc link + if !path_str.contains("::") { + // Otherwise, the `[]` might be unrelated. + // FIXME(https://github.com/raphlinus/pulldown-cmark/issues/373): + // don't show this for autolinks (`<>`), `()` style links, or reference links + diag.help(r#"to escape `[` and `]` characters, add '\' before them like `\[` or `\]`"#); + } } ResolutionFailure::Dummy => continue, ResolutionFailure::WrongNamespace(res, expected_ns) => { diff --git a/src/test/rustdoc-ui/intra-link-errors.rs b/src/test/rustdoc-ui/intra-link-errors.rs index d8d4ebeb60b..f66bb8a4533 100644 --- a/src/test/rustdoc-ui/intra-link-errors.rs +++ b/src/test/rustdoc-ui/intra-link-errors.rs @@ -7,7 +7,6 @@ /// [path::to::nonexistent::module] //~^ ERROR unresolved link //~| NOTE no item named `path` is in scope -//~| HELP to escape /// [std::io::not::here] //~^ ERROR unresolved link @@ -67,7 +66,6 @@ impl S { /// [T::h!] //~^ ERROR unresolved link //~| NOTE no item named `T::h` -//~| HELP to escape pub trait T { fn g() {} } diff --git a/src/test/rustdoc-ui/intra-link-errors.stderr b/src/test/rustdoc-ui/intra-link-errors.stderr index 0275fd692fe..4dac892b820 100644 --- a/src/test/rustdoc-ui/intra-link-errors.stderr +++ b/src/test/rustdoc-ui/intra-link-errors.stderr @@ -10,10 +10,9 @@ note: the lint level is defined here LL | #![deny(broken_intra_doc_links)] | ^^^^^^^^^^^^^^^^^^^^^^ = note: no item named `path` is in scope - = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unresolved link to `std::io::not::here` - --> $DIR/intra-link-errors.rs:13:6 + --> $DIR/intra-link-errors.rs:12:6 | LL | /// [std::io::not::here] | ^^^^^^^^^^^^^^^^^^ @@ -21,7 +20,7 @@ LL | /// [std::io::not::here] = note: the module `io` has no inner item named `not` error: unresolved link to `std::io::Error::x` - --> $DIR/intra-link-errors.rs:17:6 + --> $DIR/intra-link-errors.rs:16:6 | LL | /// [std::io::Error::x] | ^^^^^^^^^^^^^^^^^ @@ -29,7 +28,7 @@ LL | /// [std::io::Error::x] = note: the struct `Error` has no field or associated item named `x` error: unresolved link to `std::io::ErrorKind::x` - --> $DIR/intra-link-errors.rs:21:6 + --> $DIR/intra-link-errors.rs:20:6 | LL | /// [std::io::ErrorKind::x] | ^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +36,7 @@ LL | /// [std::io::ErrorKind::x] = note: the enum `ErrorKind` has no variant or associated item named `x` error: unresolved link to `f::A` - --> $DIR/intra-link-errors.rs:25:6 + --> $DIR/intra-link-errors.rs:24:6 | LL | /// [f::A] | ^^^^ @@ -45,7 +44,7 @@ LL | /// [f::A] = note: `f` is a function, not a module or type, and cannot have associated items error: unresolved link to `S::A` - --> $DIR/intra-link-errors.rs:29:6 + --> $DIR/intra-link-errors.rs:28:6 | LL | /// [S::A] | ^^^^ @@ -53,7 +52,7 @@ LL | /// [S::A] = note: the struct `S` has no field or associated item named `A` error: unresolved link to `S::fmt` - --> $DIR/intra-link-errors.rs:33:6 + --> $DIR/intra-link-errors.rs:32:6 | LL | /// [S::fmt] | ^^^^^^ @@ -61,7 +60,7 @@ LL | /// [S::fmt] = note: the struct `S` has no field or associated item named `fmt` error: unresolved link to `E::D` - --> $DIR/intra-link-errors.rs:37:6 + --> $DIR/intra-link-errors.rs:36:6 | LL | /// [E::D] | ^^^^ @@ -69,7 +68,7 @@ LL | /// [E::D] = note: the enum `E` has no variant or associated item named `D` error: unresolved link to `u8::not_found` - --> $DIR/intra-link-errors.rs:41:6 + --> $DIR/intra-link-errors.rs:40:6 | LL | /// [u8::not_found] | ^^^^^^^^^^^^^ @@ -77,7 +76,7 @@ LL | /// [u8::not_found] = note: the builtin type `u8` does not have an associated item named `not_found` error: unresolved link to `S` - --> $DIR/intra-link-errors.rs:45:6 + --> $DIR/intra-link-errors.rs:44:6 | LL | /// [S!] | ^^ @@ -89,7 +88,7 @@ LL | /// [struct@S] | ^^^^^^^^ error: unresolved link to `T::g` - --> $DIR/intra-link-errors.rs:63:6 + --> $DIR/intra-link-errors.rs:62:6 | LL | /// [type@T::g] | ^^^^^^^^^ help: to link to the associated function, add parentheses: `T::g()` @@ -97,16 +96,15 @@ LL | /// [type@T::g] = note: this link resolves to the associated function `g`, which is not in the type namespace error: unresolved link to `T::h` - --> $DIR/intra-link-errors.rs:68:6 + --> $DIR/intra-link-errors.rs:67:6 | LL | /// [T::h!] | ^^^^^ | = note: no item named `T::h` is in scope - = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unresolved link to `S::h` - --> $DIR/intra-link-errors.rs:55:6 + --> $DIR/intra-link-errors.rs:54:6 | LL | /// [type@S::h] | ^^^^^^^^^ help: to link to the associated function, add parentheses: `S::h()` @@ -114,7 +112,7 @@ LL | /// [type@S::h] = note: this link resolves to the associated function `h`, which is not in the type namespace error: unresolved link to `m` - --> $DIR/intra-link-errors.rs:76:6 + --> $DIR/intra-link-errors.rs:74:6 | LL | /// [m()] | ^^^ help: to link to the macro, add an exclamation mark: `m!` diff --git a/src/test/rustdoc-ui/intra-links-warning.stderr b/src/test/rustdoc-ui/intra-links-warning.stderr index 988a65c7a59..25c6975d3a5 100644 --- a/src/test/rustdoc-ui/intra-links-warning.stderr +++ b/src/test/rustdoc-ui/intra-links-warning.stderr @@ -14,7 +14,6 @@ LL | //! Test with [Foo::baz], [Bar::foo], ... | ^^^^^^^^ | = note: no item named `Bar` is in scope - = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `Uniooon::X` --> $DIR/intra-links-warning.rs:6:13 @@ -23,7 +22,6 @@ LL | //! , [Uniooon::X] and [Qux::Z]. | ^^^^^^^^^^ | = note: no item named `Uniooon` is in scope - = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `Qux::Z` --> $DIR/intra-links-warning.rs:6:30 @@ -32,7 +30,6 @@ LL | //! , [Uniooon::X] and [Qux::Z]. | ^^^^^^ | = note: no item named `Qux` is in scope - = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `Uniooon::X` --> $DIR/intra-links-warning.rs:10:14 @@ -41,7 +38,6 @@ LL | //! , [Uniooon::X] and [Qux::Z]. | ^^^^^^^^^^ | = note: no item named `Uniooon` is in scope - = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `Qux::Z` --> $DIR/intra-links-warning.rs:10:31 @@ -50,7 +46,6 @@ LL | //! , [Uniooon::X] and [Qux::Z]. | ^^^^^^ | = note: no item named `Qux` is in scope - = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `Qux:Y` --> $DIR/intra-links-warning.rs:14:13