about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee <workingjubilee@gmail.com>2024-10-04 19:19:25 -0700
committerGitHub <noreply@github.com>2024-10-04 19:19:25 -0700
commitf66aa600d93059e0a1bd7ee73f311ad8e1946cec (patch)
tree5099e06289201396f209c1d79dac5f3e5b38c576
parentbc2f732870602324ecce17aad19c9fc2a047f917 (diff)
parent3686e59913967072e47d64a6a466a6f5d9386c09 (diff)
downloadrust-f66aa600d93059e0a1bd7ee73f311ad8e1946cec.tar.gz
rust-f66aa600d93059e0a1bd7ee73f311ad8e1946cec.zip
Rollup merge of #131260 - notriddle:notriddle/disambiguator-error, r=GuillaumeGomez
rustdoc: cleaner errors on disambiguator/namespace mismatches

Resolves https://github.com/rust-lang/rust/pull/131224#pullrequestreview-2348407077

r? `@jyn514`
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs21
-rw-r--r--tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr6
-rw-r--r--tests/rustdoc-ui/intra-doc/errors.rs2
-rw-r--r--tests/rustdoc-ui/intra-doc/errors.stderr4
-rw-r--r--tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr4
-rw-r--r--tests/rustdoc-ui/intra-doc/weird-syntax.stderr20
6 files changed, 34 insertions, 23 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 0dba16cbaf3..def9ac3ce4b 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -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 {
diff --git a/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr b/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr
index 66b910eed81..ef7fec77b1e 100644
--- a/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr
+++ b/tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr
@@ -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
    |
@@ -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@`
    |
@@ -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@`
    |
diff --git a/tests/rustdoc-ui/intra-doc/errors.rs b/tests/rustdoc-ui/intra-doc/errors.rs
index f37f49c24cc..e885a3b35f6 100644
--- a/tests/rustdoc-ui/intra-doc/errors.rs
+++ b/tests/rustdoc-ui/intra-doc/errors.rs
@@ -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 {
     () => {};
diff --git a/tests/rustdoc-ui/intra-doc/errors.stderr b/tests/rustdoc-ui/intra-doc/errors.stderr
index a982bba0095..07d328f99a3 100644
--- a/tests/rustdoc-ui/intra-doc/errors.stderr
+++ b/tests/rustdoc-ui/intra-doc/errors.stderr
@@ -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@`
    |
@@ -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
    |
diff --git a/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr b/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr
index 6c834fd0a1b..a347044bfe9 100644
--- a/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr
+++ b/tests/rustdoc-ui/intra-doc/issue-110495-suffix-with-space.stderr
@@ -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
@@ -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@`
    |
diff --git a/tests/rustdoc-ui/intra-doc/weird-syntax.stderr b/tests/rustdoc-ui/intra-doc/weird-syntax.stderr
index f50feb57fcc..17bcbc783fd 100644
--- a/tests/rustdoc-ui/intra-doc/weird-syntax.stderr
+++ b/tests/rustdoc-ui/intra-doc/weird-syntax.stderr
@@ -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@`
    |
@@ -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@`
    |
@@ -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@`
    |
@@ -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@`
    |
@@ -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@`
    |
@@ -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@`
    |
@@ -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@`
    |
@@ -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@`
    |
@@ -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@`
    |
@@ -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