Skip to content

Commit 21fb9df

Browse files
committed
Use old error when there's partial resolution
The new error was confusing when there was partial resolution (something like `std::io::nonexistent`); the old one is better for those cases.
1 parent 0193a88 commit 21fb9df

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1575,11 +1575,16 @@ fn resolution_failure(
15751575
_ => None,
15761576
};
15771577
// See if this was a module: `[path]` or `[std::io::nope]`
1578-
if let Some(_module) = last_found_module {
1579-
let note = format!(
1580-
"there is no item named `{}` in scope",
1581-
unresolved
1582-
);
1578+
if let Some(module) = last_found_module {
1579+
let note = if partial_res.is_some() {
1580+
let module_name = collector.cx.tcx.item_name(module);
1581+
format!(
1582+
"the module `{}` contains no item named `{}`",
1583+
module_name, unresolved
1584+
)
1585+
} else {
1586+
format!("there is no item named `{}` in scope", unresolved)
1587+
};
15831588
if let Some(span) = sp {
15841589
diag.span_label(span, &note);
15851590
} else {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

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

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

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ error: unresolved link to `std::io::not::here`
2626
--> $DIR/intra-link-errors.rs:19:6
2727
|
2828
LL | /// [std::io::not::here]
29-
| ^^^^^^^^^^^^^^^^^^ there is no item named `not` in scope
29+
| ^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not`
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-
| ^^^^^^^^^^^^^^^^^^^^^^^ there is no item named `not` in scope
35+
| ^^^^^^^^^^^^^^^^^^^^^^^ the module `io` contains no item named `not`
3636

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

0 commit comments

Comments
 (0)