1
Fork 0

Fix tests and improve error message if :: isn't found

This commit is contained in:
Joshua Nelson 2020-08-20 23:14:41 -04:00
parent 42bed03500
commit f4e6ebd11a
5 changed files with 33 additions and 54 deletions

View file

@ -324,9 +324,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
}) })
// If there's no `::`, it's not an associated item. // 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. // So we can be sure that `rustc_resolve` was accurate when it said it wasn't resolved.
.ok_or(ErrorKind::Resolve(ResolutionFailure::NotInScope( .ok_or_else(|| {
item_name.to_string().into(), 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) { if let Some((path, prim)) = is_primitive(&path_root, ns) {
let impls = primitive_impl(cx, &path).ok_or_else(|| { let impls = primitive_impl(cx, &path).ok_or_else(|| {
@ -361,6 +362,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
let (_, ty_res) = cx let (_, ty_res) = cx
.enter_resolver(|resolver| { .enter_resolver(|resolver| {
// only types can have associated items
resolver.resolve_str_path_error(DUMMY_SP, &path_root, TypeNS, module_id) resolver.resolve_str_path_error(DUMMY_SP, &path_root, TypeNS, module_id)
}) })
.map_err(|_| { .map_err(|_| {
@ -1450,10 +1452,7 @@ fn resolution_failure(
// FIXME: when are items neither a primitive nor a Def? // FIXME: when are items neither a primitive nor a Def?
if let Res::Def(_, def_id) = res { if let Res::Def(_, def_id) = res {
let name = cx.tcx.item_name(def_id); let name = cx.tcx.item_name(def_id);
let note = format!( let note = format!("no `{}` in `{}`", assoc_item, name,);
"`{}` has no field, variant, or associated item named `{}`",
name, assoc_item
);
diag.note(&note); diag.note(&note);
} }
} }

View file

@ -10,7 +10,7 @@ note: the lint level is defined here
LL | #![deny(broken_intra_doc_links)] LL | #![deny(broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
= note: this link partially resolves to the type alias `TypeAlias` = 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 error: aborting due to previous error

View file

@ -1,9 +1,6 @@
#![deny(broken_intra_doc_links)] #![deny(broken_intra_doc_links)]
//~^ NOTE lint level is defined //~^ 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?) // FIXME: this should say that it was skipped (maybe an allowed by default lint?)
/// [<invalid syntax>] /// [<invalid syntax>]
@ -22,17 +19,17 @@
/// [S::A] /// [S::A]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE this link partially resolves //~| NOTE this link partially resolves
//~| NOTE `S` has no field //~| NOTE no `A` in `S`
/// [S::fmt] /// [S::fmt]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE this link partially resolves //~| NOTE this link partially resolves
//~| NOTE `S` has no field //~| NOTE no `fmt` in `S`
/// [E::D] /// [E::D]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| NOTE this link partially resolves //~| NOTE this link partially resolves
//~| NOTE `E` has no field //~| NOTE no `D` in `E`
/// [u8::not_found] /// [u8::not_found]
//~^ ERROR unresolved link //~^ ERROR unresolved link
@ -40,8 +37,8 @@
/// [S!] /// [S!]
//~^ ERROR unresolved link //~^ ERROR unresolved link
//~| HELP to link to the unit struct, use its disambiguator //~| HELP to link to the struct, use its disambiguator
//~| NOTE this link resolves to the unit struct `S` //~| NOTE this link resolves to the struct `S`
pub fn f() {} pub fn f() {}
#[derive(Debug)] #[derive(Debug)]
pub struct S; pub struct S;
@ -62,6 +59,9 @@ impl S {
//~| NOTE not in the type namespace //~| NOTE not in the type namespace
/// [T::h!] /// [T::h!]
//~^ ERROR unresolved link
//~| NOTE no item named `T::h`
//~| HELP to escape
pub trait T { pub trait T {
fn g() {} fn g() {}
} }

View file

@ -1,39 +1,19 @@
error: unresolved link to `std::io::oops` error: unresolved link to `path::to::nonexistent::module`
--> $DIR/intra-link-errors.rs:4:6 --> $DIR/intra-link-errors.rs:8:6
| |
LL | //! [std::io::oops] LL | /// [path::to::nonexistent::module]
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
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
| |
LL | #![deny(broken_intra_doc_links)] 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 = note: no item named `path::to::nonexistent` is in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: unresolved link to `f::A` error: unresolved link to `f::A`
--> $DIR/intra-link-errors.rs:17:6 --> $DIR/intra-link-errors.rs:14:6
| |
LL | /// [f::A] LL | /// [f::A]
| ^^^^ | ^^^^
@ -42,34 +22,34 @@ LL | /// [f::A]
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: unresolved link to `S::A` error: unresolved link to `S::A`
--> $DIR/intra-link-errors.rs:22:6 --> $DIR/intra-link-errors.rs:19:6
| |
LL | /// [S::A] LL | /// [S::A]
| ^^^^ | ^^^^
| |
= note: this link partially resolves to the struct `S` = 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` error: unresolved link to `S::fmt`
--> $DIR/intra-link-errors.rs:27:6 --> $DIR/intra-link-errors.rs:24:6
| |
LL | /// [S::fmt] LL | /// [S::fmt]
| ^^^^^^ | ^^^^^^
| |
= note: this link partially resolves to the struct `S` = 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` error: unresolved link to `E::D`
--> $DIR/intra-link-errors.rs:32:6 --> $DIR/intra-link-errors.rs:29:6
| |
LL | /// [E::D] LL | /// [E::D]
| ^^^^ | ^^^^
| |
= note: this link partially resolves to the enum `E` = 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` 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] 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` = note: the builtin type `u8` does not have an associated item named `not_found`
error: unresolved link to `S` error: unresolved link to `S`
--> $DIR/intra-link-errors.rs:41:6 --> $DIR/intra-link-errors.rs:38:6
| |
LL | /// [S!] LL | /// [S!]
| ^^ help: to link to the struct, use its disambiguator: `struct@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 = note: this link resolves to the struct `S`, which is not in the macro namespace
error: unresolved link to `T::g` error: unresolved link to `T::g`
--> $DIR/intra-link-errors.rs:59:6 --> $DIR/intra-link-errors.rs:56:6
| |
LL | /// [type@T::g] LL | /// [type@T::g]
| ^^^^^^^^^ help: to link to the associated function, use its disambiguator: `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 = note: this link resolves to the associated function `g`, which is not in the type namespace
error: unresolved link to `T::h` error: unresolved link to `T::h`
--> $DIR/intra-link-errors.rs:64:6 --> $DIR/intra-link-errors.rs:61:6
| |
LL | /// [T::h!] LL | /// [T::h!]
| ^^^^^ | ^^^^^
@ -102,12 +82,12 @@ LL | /// [T::h!]
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: unresolved link to `S::h` error: unresolved link to `S::h`
--> $DIR/intra-link-errors.rs:51:6 --> $DIR/intra-link-errors.rs:48:6
| |
LL | /// [type@S::h] LL | /// [type@S::h]
| ^^^^^^^^^ help: to link to the associated function, use its disambiguator: `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 = 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

View file

@ -6,7 +6,7 @@ LL | //! Test with [Foo::baz], [Bar::foo], ...
| |
= note: `#[warn(broken_intra_doc_links)]` on by default = note: `#[warn(broken_intra_doc_links)]` on by default
= note: this link partially resolves to the struct `Foo` = 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` warning: unresolved link to `Bar::foo`
--> $DIR/intra-links-warning.rs:3:35 --> $DIR/intra-links-warning.rs:3:35