about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-08-20 23:14:41 -0400
committerJoshua Nelson <jyn514@gmail.com>2020-09-05 13:48:19 -0400
commitf4e6ebd11aaea9fc412d78371fd3060468625056 (patch)
tree097b0555ea3ae6fd8860b4e8dfb945feb0cafb4d
parent42bed035001b9a0bd6282326a243a926ea3d0424 (diff)
downloadrust-f4e6ebd11aaea9fc412d78371fd3060468625056.tar.gz
rust-f4e6ebd11aaea9fc412d78371fd3060468625056.zip
Fix tests and improve error message if `::` isn't found
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs13
-rw-r--r--src/test/rustdoc-ui/intra-doc-alias-ice.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-link-errors.rs16
-rw-r--r--src/test/rustdoc-ui/intra-link-errors.stderr54
-rw-r--r--src/test/rustdoc-ui/intra-links-warning.stderr2
5 files changed, 33 insertions, 54 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 287f5fcf805..ea3ec1b6685 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -324,9 +324,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
                 })
                 // If there's no `::`, it's not an associated item.
                 // So we can be sure that `rustc_resolve` was accurate when it said it wasn't resolved.
-                .ok_or(ErrorKind::Resolve(ResolutionFailure::NotInScope(
-                    item_name.to_string().into(),
-                )))?;
+                .ok_or_else(|| {
+                    debug!("found no `::`, assumming {} was correctly not in scope", item_name);
+                    ErrorKind::Resolve(ResolutionFailure::NotInScope(item_name.to_string().into()))
+                })?;
 
             if let Some((path, prim)) = is_primitive(&path_root, ns) {
                 let impls = primitive_impl(cx, &path).ok_or_else(|| {
@@ -361,6 +362,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
 
             let (_, ty_res) = cx
                 .enter_resolver(|resolver| {
+                    // only types can have associated items
                     resolver.resolve_str_path_error(DUMMY_SP, &path_root, TypeNS, module_id)
                 })
                 .map_err(|_| {
@@ -1450,10 +1452,7 @@ fn resolution_failure(
                         // FIXME: when are items neither a primitive nor a Def?
                         if let Res::Def(_, def_id) = res {
                             let name = cx.tcx.item_name(def_id);
-                            let note = format!(
-                                "`{}` has no field, variant, or associated item named `{}`",
-                                name, assoc_item
-                            );
+                            let note = format!("no `{}` in `{}`", assoc_item, name,);
                             diag.note(&note);
                         }
                     }
diff --git a/src/test/rustdoc-ui/intra-doc-alias-ice.stderr b/src/test/rustdoc-ui/intra-doc-alias-ice.stderr
index cc1343eb7b9..58abe4406a8 100644
--- a/src/test/rustdoc-ui/intra-doc-alias-ice.stderr
+++ b/src/test/rustdoc-ui/intra-doc-alias-ice.stderr
@@ -10,7 +10,7 @@ note: the lint level is defined here
 LL | #![deny(broken_intra_doc_links)]
    |         ^^^^^^^^^^^^^^^^^^^^^^
    = note: this link partially resolves to the type alias `TypeAlias`
-   = note: `TypeAlias` has no field, variant, or associated item named `hoge`
+   = note: no `hoge` in `TypeAlias`
 
 error: aborting due to previous error
 
diff --git a/src/test/rustdoc-ui/intra-link-errors.rs b/src/test/rustdoc-ui/intra-link-errors.rs
index 8c42a38ff4e..79ce57c2267 100644
--- a/src/test/rustdoc-ui/intra-link-errors.rs
+++ b/src/test/rustdoc-ui/intra-link-errors.rs
@@ -1,9 +1,6 @@
 #![deny(broken_intra_doc_links)]
 //~^ NOTE lint level is defined
 
-//! [std::io::oops]
-//! [std::io::oops::not::here]
-
 // FIXME: this should say that it was skipped (maybe an allowed by default lint?)
 /// [<invalid syntax>]
 
@@ -22,17 +19,17 @@
 /// [S::A]
 //~^ ERROR unresolved link
 //~| NOTE this link partially resolves
-//~| NOTE `S` has no field
+//~| NOTE no `A` in `S`
 
 /// [S::fmt]
 //~^ ERROR unresolved link
 //~| NOTE this link partially resolves
-//~| NOTE `S` has no field
+//~| NOTE no `fmt` in `S`
 
 /// [E::D]
 //~^ ERROR unresolved link
 //~| NOTE this link partially resolves
-//~| NOTE `E` has no field
+//~| NOTE no `D` in `E`
 
 /// [u8::not_found]
 //~^ ERROR unresolved link
@@ -40,8 +37,8 @@
 
 /// [S!]
 //~^ ERROR unresolved link
-//~| HELP to link to the unit struct, use its disambiguator
-//~| NOTE this link resolves to the unit struct `S`
+//~| HELP to link to the struct, use its disambiguator
+//~| NOTE this link resolves to the struct `S`
 pub fn f() {}
 #[derive(Debug)]
 pub struct S;
@@ -62,6 +59,9 @@ impl S {
 //~| NOTE not in the type namespace
 
 /// [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 bb9db68e0d5..4044c7fde66 100644
--- a/src/test/rustdoc-ui/intra-link-errors.stderr
+++ b/src/test/rustdoc-ui/intra-link-errors.stderr
@@ -1,39 +1,19 @@
-error: unresolved link to `std::io::oops`
-  --> $DIR/intra-link-errors.rs:4:6
+error: unresolved link to `path::to::nonexistent::module`
+  --> $DIR/intra-link-errors.rs:8:6
    |
-LL | //! [std::io::oops]
-   |      ^^^^^^^^^^^^^
+LL | /// [path::to::nonexistent::module]
+   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
 note: the lint level is defined here
   --> $DIR/intra-link-errors.rs:1:9
    |
 LL | #![deny(broken_intra_doc_links)]
    |         ^^^^^^^^^^^^^^^^^^^^^^
-   = note: this link resolves to the crate `std`, which is not an enum
-   = note: if this were an enum, it might have a variant which resolved
-   = note: this link partially resolves to the module `io`
-   = note: `io` has no field, variant, or associated item named `oops`
-
-error: unresolved link to `std::io::oops::not::here`
-  --> $DIR/intra-link-errors.rs:5:6
-   |
-LL | //! [std::io::oops::not::here]
-   |      ^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: no item named `std::io::oops::not` is in scope
-   = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
-
-error: unresolved link to `path::to::nonexistent::module`
-  --> $DIR/intra-link-errors.rs:11:6
-   |
-LL | /// [path::to::nonexistent::module]
-   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
    = note: no item named `path::to::nonexistent` is in scope
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
 
 error: unresolved link to `f::A`
-  --> $DIR/intra-link-errors.rs:17:6
+  --> $DIR/intra-link-errors.rs:14:6
    |
 LL | /// [f::A]
    |      ^^^^
@@ -42,34 +22,34 @@ LL | /// [f::A]
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
 
 error: unresolved link to `S::A`
-  --> $DIR/intra-link-errors.rs:22:6
+  --> $DIR/intra-link-errors.rs:19:6
    |
 LL | /// [S::A]
    |      ^^^^
    |
    = note: this link partially resolves to the struct `S`
-   = note: `S` has no field, variant, or associated item named `A`
+   = note: no `A` in `S`
 
 error: unresolved link to `S::fmt`
-  --> $DIR/intra-link-errors.rs:27:6
+  --> $DIR/intra-link-errors.rs:24:6
    |
 LL | /// [S::fmt]
    |      ^^^^^^
    |
    = note: this link partially resolves to the struct `S`
-   = note: `S` has no field, variant, or associated item named `fmt`
+   = note: no `fmt` in `S`
 
 error: unresolved link to `E::D`
-  --> $DIR/intra-link-errors.rs:32:6
+  --> $DIR/intra-link-errors.rs:29:6
    |
 LL | /// [E::D]
    |      ^^^^
    |
    = note: this link partially resolves to the enum `E`
-   = note: `E` has no field, variant, or associated item named `D`
+   = note: no `D` in `E`
 
 error: unresolved link to `u8::not_found`
-  --> $DIR/intra-link-errors.rs:37:6
+  --> $DIR/intra-link-errors.rs:34:6
    |
 LL | /// [u8::not_found]
    |      ^^^^^^^^^^^^^
@@ -77,7 +57,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:41:6
+  --> $DIR/intra-link-errors.rs:38:6
    |
 LL | /// [S!]
    |      ^^ help: to link to the struct, use its disambiguator: `struct@S`
@@ -85,7 +65,7 @@ LL | /// [S!]
    = note: this link resolves to the struct `S`, which is not in the macro namespace
 
 error: unresolved link to `T::g`
-  --> $DIR/intra-link-errors.rs:59:6
+  --> $DIR/intra-link-errors.rs:56:6
    |
 LL | /// [type@T::g]
    |      ^^^^^^^^^ help: to link to the associated function, use its disambiguator: `T::g()`
@@ -93,7 +73,7 @@ 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:64:6
+  --> $DIR/intra-link-errors.rs:61:6
    |
 LL | /// [T::h!]
    |      ^^^^^
@@ -102,12 +82,12 @@ LL | /// [T::h!]
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
 
 error: unresolved link to `S::h`
-  --> $DIR/intra-link-errors.rs:51:6
+  --> $DIR/intra-link-errors.rs:48:6
    |
 LL | /// [type@S::h]
    |      ^^^^^^^^^ help: to link to the associated function, use its disambiguator: `S::h()`
    |
    = note: this link resolves to the associated function `h`, which is not in the type namespace
 
-error: aborting due to 12 previous errors
+error: aborting due to 10 previous errors
 
diff --git a/src/test/rustdoc-ui/intra-links-warning.stderr b/src/test/rustdoc-ui/intra-links-warning.stderr
index 3737cad1cb1..b51c8e89600 100644
--- a/src/test/rustdoc-ui/intra-links-warning.stderr
+++ b/src/test/rustdoc-ui/intra-links-warning.stderr
@@ -6,7 +6,7 @@ LL |        //! Test with [Foo::baz], [Bar::foo], ...
    |
    = note: `#[warn(broken_intra_doc_links)]` on by default
    = note: this link partially resolves to the struct `Foo`
-   = note: `Foo` has no field, variant, or associated item named `baz`
+   = note: no `baz` in `Foo`
 
 warning: unresolved link to `Bar::foo`
   --> $DIR/intra-links-warning.rs:3:35