1
Fork 0

Rollup merge of #77469 - camelid:rustdoc-better-failed-res-error, r=jyn514

Improve rustdoc error for failed intra-doc link resolution

The previous error was confusing since it made it sound like you can't
link to items that are defined outside the current module.

Also suggested importing the item.

r? @jyn514
This commit is contained in:
Yuki Okushi 2020-10-04 11:45:08 +09:00 committed by GitHub
commit 0ed4849a3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 40 deletions

View file

@ -1576,22 +1576,27 @@ fn resolution_failure(
}; };
// See if this was a module: `[path]` or `[std::io::nope]` // See if this was a module: `[path]` or `[std::io::nope]`
if let Some(module) = last_found_module { if let Some(module) = last_found_module {
let module_name = collector.cx.tcx.item_name(module); let note = if partial_res.is_some() {
let note = format!( // Part of the link resolved; e.g. `std::io::nonexistent`
"the module `{}` contains no item named `{}`", let module_name = collector.cx.tcx.item_name(module);
module_name, unresolved format!("no item named `{}` in module `{}`", unresolved, module_name)
); } else {
// None of the link resolved; e.g. `Notimported`
format!("no item named `{}` in scope", unresolved)
};
if let Some(span) = sp { if let Some(span) = sp {
diag.span_label(span, &note); diag.span_label(span, &note);
} else { } else {
diag.note(&note); diag.note(&note);
} }
// If the link has `::` in it, assume it was meant to be an intra-doc link. // If the link has `::` in it, assume it was meant to be an intra-doc link.
// Otherwise, the `[]` might be unrelated. // Otherwise, the `[]` might be unrelated.
// FIXME: don't show this for autolinks (`<>`), `()` style links, or reference links // FIXME: don't show this for autolinks (`<>`), `()` style links, or reference links
if !path_str.contains("::") { if !path_str.contains("::") {
diag.help(r#"to escape `[` and `]` characters, add '\' before them like `\[` or `\]`"#); diag.help(r#"to escape `[` and `]` characters, add '\' before them like `\[` or `\]`"#);
} }
continue; continue;
} }

View file

@ -2,7 +2,7 @@ error: unresolved link to `v2`
--> $DIR/deny-intra-link-resolution-failure.rs:3:6 --> $DIR/deny-intra-link-resolution-failure.rs:3:6
| |
LL | /// [v2] LL | /// [v2]
| ^^ the module `deny_intra_link_resolution_failure` contains no item named `v2` | ^^ no item named `v2` in scope
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/deny-intra-link-resolution-failure.rs:1:9 --> $DIR/deny-intra-link-resolution-failure.rs:1:9

View file

@ -6,23 +6,23 @@
/// [path::to::nonexistent::module] /// [path::to::nonexistent::module]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE `intra_link_errors` contains no item named `path` //~| NOTE no item named `path` in scope
/// [path::to::nonexistent::macro!] /// [path::to::nonexistent::macro!]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE `intra_link_errors` contains no item named `path` //~| NOTE no item named `path` in scope
/// [type@path::to::nonexistent::type] /// [type@path::to::nonexistent::type]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE `intra_link_errors` contains no item named `path` //~| NOTE no item named `path` in scope
/// [std::io::not::here] /// [std::io::not::here]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE `io` contains no item named `not` //~| NOTE no item named `not` in module `io`
/// [type@std::io::not::here] /// [type@std::io::not::here]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE `io` contains no item named `not` //~| NOTE no item named `not` in module `io`
/// [std::io::Error::x] /// [std::io::Error::x]
//~^ ERROR unresolved link //~^ ERROR unresolved link

View file

@ -2,7 +2,7 @@ error: unresolved link to `path::to::nonexistent::module`
--> $DIR/intra-link-errors.rs:7:6 --> $DIR/intra-link-errors.rs:7:6
| |
LL | /// [path::to::nonexistent::module] LL | /// [path::to::nonexistent::module]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in scope
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/intra-link-errors.rs:1:9 --> $DIR/intra-link-errors.rs:1:9
@ -14,25 +14,25 @@ error: unresolved link to `path::to::nonexistent::macro`
--> $DIR/intra-link-errors.rs:11:6 --> $DIR/intra-link-errors.rs:11:6
| |
LL | /// [path::to::nonexistent::macro!] LL | /// [path::to::nonexistent::macro!]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in scope
error: unresolved link to `path::to::nonexistent::type` error: unresolved link to `path::to::nonexistent::type`
--> $DIR/intra-link-errors.rs:15:6 --> $DIR/intra-link-errors.rs:15:6
| |
LL | /// [type@path::to::nonexistent::type] LL | /// [type@path::to::nonexistent::type]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the module `intra_link_errors` contains no item named `path` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `path` in scope
error: unresolved link to `std::io::not::here` error: unresolved link to `std::io::not::here`
--> $DIR/intra-link-errors.rs:19:6 --> $DIR/intra-link-errors.rs:19:6
| |
LL | /// [std::io::not::here] LL | /// [std::io::not::here]
| ^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not` | ^^^^^^^^^^^^^^^^^^ no item named `not` in module `io`
error: unresolved link to `std::io::not::here` error: unresolved link to `std::io::not::here`
--> $DIR/intra-link-errors.rs:23:6 --> $DIR/intra-link-errors.rs:23:6
| |
LL | /// [type@std::io::not::here] LL | /// [type@std::io::not::here]
| ^^^^^^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not` | ^^^^^^^^^^^^^^^^^^^^^^^ no item named `not` in module `io`
error: unresolved link to `std::io::Error::x` error: unresolved link to `std::io::Error::x`
--> $DIR/intra-link-errors.rs:27:6 --> $DIR/intra-link-errors.rs:27:6

View file

@ -2,7 +2,7 @@ error: unresolved link to `i`
--> $DIR/intra-link-span-ice-55723.rs:9:10 --> $DIR/intra-link-span-ice-55723.rs:9:10
| |
LL | /// arr[i] LL | /// arr[i]
| ^ the module `intra_link_span_ice_55723` contains no item named `i` | ^ no item named `i` in scope
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/intra-link-span-ice-55723.rs:1:9 --> $DIR/intra-link-span-ice-55723.rs:1:9

View file

@ -2,7 +2,7 @@ warning: unresolved link to `error`
--> $DIR/intra-links-warning-crlf.rs:7:6 --> $DIR/intra-links-warning-crlf.rs:7:6
| |
LL | /// [error] LL | /// [error]
| ^^^^^ the module `intra_links_warning_crlf` contains no item named `error` | ^^^^^ no item named `error` in scope
| |
= note: `#[warn(broken_intra_doc_links)]` on by default = note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -11,7 +11,7 @@ warning: unresolved link to `error1`
--> $DIR/intra-links-warning-crlf.rs:12:11 --> $DIR/intra-links-warning-crlf.rs:12:11
| |
LL | /// docs [error1] LL | /// docs [error1]
| ^^^^^^ the module `intra_links_warning_crlf` contains no item named `error1` | ^^^^^^ no item named `error1` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -19,7 +19,7 @@ warning: unresolved link to `error2`
--> $DIR/intra-links-warning-crlf.rs:15:11 --> $DIR/intra-links-warning-crlf.rs:15:11
| |
LL | /// docs [error2] LL | /// docs [error2]
| ^^^^^^ the module `intra_links_warning_crlf` contains no item named `error2` | ^^^^^^ no item named `error2` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -27,7 +27,7 @@ warning: unresolved link to `error`
--> $DIR/intra-links-warning-crlf.rs:23:20 --> $DIR/intra-links-warning-crlf.rs:23:20
| |
LL | * It also has an [error]. LL | * It also has an [error].
| ^^^^^ the module `intra_links_warning_crlf` contains no item named `error` | ^^^^^ no item named `error` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

View file

@ -10,37 +10,37 @@ warning: unresolved link to `Bar::foo`
--> $DIR/intra-links-warning.rs:3:35 --> $DIR/intra-links-warning.rs:3:35
| |
LL | //! Test with [Foo::baz], [Bar::foo], ... LL | //! Test with [Foo::baz], [Bar::foo], ...
| ^^^^^^^^ the module `intra_links_warning` contains no item named `Bar` | ^^^^^^^^ no item named `Bar` in scope
warning: unresolved link to `Uniooon::X` warning: unresolved link to `Uniooon::X`
--> $DIR/intra-links-warning.rs:6:13 --> $DIR/intra-links-warning.rs:6:13
| |
LL | //! , [Uniooon::X] and [Qux::Z]. LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^^^^^ the module `intra_links_warning` contains no item named `Uniooon` | ^^^^^^^^^^ no item named `Uniooon` in scope
warning: unresolved link to `Qux::Z` warning: unresolved link to `Qux::Z`
--> $DIR/intra-links-warning.rs:6:30 --> $DIR/intra-links-warning.rs:6:30
| |
LL | //! , [Uniooon::X] and [Qux::Z]. LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^ the module `intra_links_warning` contains no item named `Qux` | ^^^^^^ no item named `Qux` in scope
warning: unresolved link to `Uniooon::X` warning: unresolved link to `Uniooon::X`
--> $DIR/intra-links-warning.rs:10:14 --> $DIR/intra-links-warning.rs:10:14
| |
LL | //! , [Uniooon::X] and [Qux::Z]. LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^^^^^ the module `intra_links_warning` contains no item named `Uniooon` | ^^^^^^^^^^ no item named `Uniooon` in scope
warning: unresolved link to `Qux::Z` warning: unresolved link to `Qux::Z`
--> $DIR/intra-links-warning.rs:10:31 --> $DIR/intra-links-warning.rs:10:31
| |
LL | //! , [Uniooon::X] and [Qux::Z]. LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^ the module `intra_links_warning` contains no item named `Qux` | ^^^^^^ no item named `Qux` in scope
warning: unresolved link to `Qux:Y` warning: unresolved link to `Qux:Y`
--> $DIR/intra-links-warning.rs:14:13 --> $DIR/intra-links-warning.rs:14:13
| |
LL | /// [Qux:Y] LL | /// [Qux:Y]
| ^^^^^ the module `intra_links_warning` contains no item named `Qux:Y` | ^^^^^ no item named `Qux:Y` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -48,7 +48,7 @@ warning: unresolved link to `error`
--> $DIR/intra-links-warning.rs:58:30 --> $DIR/intra-links-warning.rs:58:30
| |
LL | * time to introduce a link [error]*/ LL | * time to introduce a link [error]*/
| ^^^^^ the module `intra_links_warning` contains no item named `error` | ^^^^^ no item named `error` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -56,7 +56,7 @@ warning: unresolved link to `error`
--> $DIR/intra-links-warning.rs:64:30 --> $DIR/intra-links-warning.rs:64:30
| |
LL | * time to introduce a link [error] LL | * time to introduce a link [error]
| ^^^^^ the module `intra_links_warning` contains no item named `error` | ^^^^^ no item named `error` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -70,7 +70,7 @@ LL | #[doc = "single line [error]"]
single line [error] single line [error]
^^^^^ ^^^^^
= note: the module `intra_links_warning` contains no item named `error` = note: no item named `error` in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `error` warning: unresolved link to `error`
@ -83,7 +83,7 @@ LL | #[doc = "single line with \"escaping\" [error]"]
single line with "escaping" [error] single line with "escaping" [error]
^^^^^ ^^^^^
= note: the module `intra_links_warning` contains no item named `error` = note: no item named `error` in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `error` warning: unresolved link to `error`
@ -98,14 +98,14 @@ LL | | /// [error]
[error] [error]
^^^^^ ^^^^^
= note: the module `intra_links_warning` contains no item named `error` = note: no item named `error` in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `error1` warning: unresolved link to `error1`
--> $DIR/intra-links-warning.rs:80:11 --> $DIR/intra-links-warning.rs:80:11
| |
LL | /// docs [error1] LL | /// docs [error1]
| ^^^^^^ the module `intra_links_warning` contains no item named `error1` | ^^^^^^ no item named `error1` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -113,7 +113,7 @@ warning: unresolved link to `error2`
--> $DIR/intra-links-warning.rs:82:11 --> $DIR/intra-links-warning.rs:82:11
| |
LL | /// docs [error2] LL | /// docs [error2]
| ^^^^^^ the module `intra_links_warning` contains no item named `error2` | ^^^^^^ no item named `error2` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -121,7 +121,7 @@ warning: unresolved link to `BarA`
--> $DIR/intra-links-warning.rs:21:10 --> $DIR/intra-links-warning.rs:21:10
| |
LL | /// bar [BarA] bar LL | /// bar [BarA] bar
| ^^^^ the module `intra_links_warning` contains no item named `BarA` | ^^^^ no item named `BarA` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -129,7 +129,7 @@ warning: unresolved link to `BarB`
--> $DIR/intra-links-warning.rs:27:9 --> $DIR/intra-links-warning.rs:27:9
| |
LL | * bar [BarB] bar LL | * bar [BarB] bar
| ^^^^ the module `intra_links_warning` contains no item named `BarB` | ^^^^ no item named `BarB` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -137,7 +137,7 @@ warning: unresolved link to `BarC`
--> $DIR/intra-links-warning.rs:34:6 --> $DIR/intra-links-warning.rs:34:6
| |
LL | bar [BarC] bar LL | bar [BarC] bar
| ^^^^ the module `intra_links_warning` contains no item named `BarC` | ^^^^ no item named `BarC` in scope
| |
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
@ -151,7 +151,7 @@ LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
bar [BarD] bar bar [BarD] bar
^^^^ ^^^^
= note: the module `intra_links_warning` contains no item named `BarD` = note: no item named `BarD` in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `BarF` warning: unresolved link to `BarF`
@ -167,7 +167,7 @@ LL | f!("Foo\nbar [BarF] bar\nbaz");
bar [BarF] bar bar [BarF] bar
^^^^ ^^^^
= note: the module `intra_links_warning` contains no item named `BarF` = note: no item named `BarF` in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -32,7 +32,7 @@ error: unresolved link to `error`
--> $DIR/lint-group.rs:9:29 --> $DIR/lint-group.rs:9:29
| |
LL | /// what up, let's make an [error] LL | /// what up, let's make an [error]
| ^^^^^ the module `lint_group` contains no item named `error` | ^^^^^ no item named `error` in scope
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/lint-group.rs:7:9 --> $DIR/lint-group.rs:7:9