Skip to content

Commit

Permalink
rustdoc: cleaner errors on disambiguator/namespace mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Oct 4, 2024
1 parent 267cf8d commit 3686e59
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
21 changes: 16 additions & 5 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1996,11 +1996,22 @@ fn resolution_failure(
&diag_info,
);

format!(
"this link resolves to {}, which is not in the {} namespace",
item(res),
expected_ns.descr()
)
if let Some(disambiguator) = disambiguator
&& !matches!(disambiguator, Disambiguator::Namespace(..))
{
format!(
"this link resolves to {}, which is not {} {}",
item(res),
disambiguator.article(),
disambiguator.descr()
)
} else {
format!(
"this link resolves to {}, which is not in the {} namespace",
item(res),
expected_ns.descr()
)
}
}
};
if let Some(span) = sp {
Expand Down
6 changes: 3 additions & 3 deletions tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ error: unresolved link to `m`
--> $DIR/disambiguator-mismatch.rs:52:14
|
LL | /// Link to [m()]
| ^^^ this link resolves to the macro `m`, which is not in the value namespace
| ^^^ this link resolves to the macro `m`, which is not a function
|
help: to link to the macro, add an exclamation mark
|
Expand Down Expand Up @@ -142,7 +142,7 @@ error: unresolved link to `std`
--> $DIR/disambiguator-mismatch.rs:83:14
|
LL | /// Link to [fn@std]
| ^^^^^^ this link resolves to the crate `std`, which is not in the value namespace
| ^^^^^^ this link resolves to the crate `std`, which is not a function
|
help: to link to the crate, prefix with `mod@`
|
Expand All @@ -164,7 +164,7 @@ error: unresolved link to `S::A`
--> $DIR/disambiguator-mismatch.rs:93:14
|
LL | /// Link to [field@S::A]
| ^^^^^^^^^^ this link resolves to the variant `A`, which is not in the value namespace
| ^^^^^^^^^^ this link resolves to the variant `A`, which is not a field
|
help: to link to the variant, prefix with `variant@`
|
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/intra-doc/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub trait T {
/// [m()]
//~^ ERROR unresolved link
//~| HELP to link to the macro
//~| NOTE not in the value namespace
//~| NOTE not a function
#[macro_export]
macro_rules! m {
() => {};
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc-ui/intra-doc/errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ error: unresolved link to `S`
--> $DIR/errors.rs:68:6
|
LL | /// [S!]
| ^^ this link resolves to the struct `S`, which is not in the macro namespace
| ^^ this link resolves to the struct `S`, which is not a macro
|
help: to link to the struct, prefix with `struct@`
|
Expand Down Expand Up @@ -158,7 +158,7 @@ error: unresolved link to `m`
--> $DIR/errors.rs:98:6
|
LL | /// [m()]
| ^^^ this link resolves to the macro `m`, which is not in the value namespace
| ^^^ this link resolves to the macro `m`, which is not a function
|
help: to link to the macro, add an exclamation mark
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: unresolved link to `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:3:6
|
LL | //! [Clone ()].
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
note: the lint level is defined here
--> $DIR/issue-110495-suffix-with-space.rs:2:9
Expand Down Expand Up @@ -31,7 +31,7 @@ error: unresolved link to `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:5:7
|
LL | //! [`Clone ()`].
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand Down
20 changes: 10 additions & 10 deletions tests/rustdoc-ui/intra-doc/weird-syntax.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:27:9
|
LL | /// [ `Clone ()` ]
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand All @@ -52,7 +52,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:30:7
|
LL | /// [`Clone ()` ]
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand All @@ -64,7 +64,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:33:9
|
LL | /// [ `Clone ()`]
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand All @@ -76,7 +76,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:36:9
|
LL | /// [```Clone ()```]
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand All @@ -88,7 +88,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:42:13
|
LL | /// [ ``` Clone () ``` ]
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand Down Expand Up @@ -122,7 +122,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:74:9
|
LL | /// [x][Clone()]
| ^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand All @@ -134,7 +134,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:77:9
|
LL | /// [x][Clone ()]
| ^^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand Down Expand Up @@ -176,7 +176,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:97:9
|
LL | /// [w](Clone\(\))
| ^^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand All @@ -188,7 +188,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:103:9
|
LL | /// [w](Clone())
| ^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^^^ this link resolves to the trait `Clone`, which is not a function
|
help: to link to the trait, prefix with `trait@`
|
Expand Down Expand Up @@ -256,7 +256,7 @@ error: unresolved link to `Clone`
--> $DIR/weird-syntax.rs:132:9
|
LL | /// The [cln][] link here will produce a plain text suggestion
| ^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
| ^^^^^ this link resolves to the trait `Clone`, which is not a function
|
= help: to link to the trait, prefix with `trait@`: trait@Clone

Expand Down

0 comments on commit 3686e59

Please sign in to comment.