refactor and reword intra-doc link errors

This commit refactors intra-doc link error reporting to deduplicate code
and decouple error construction from the type of error. This greatly
improves flexibility at each error construction site, while reducing the
complexity of the diagnostic creation.

This commit also rewords the diagnostics for clarity and style:

- Diagnostics should not end in periods.
- It's unnecessary to say "ignoring it". Since this is a warning by
  default, it's already clear that the link is ignored.
This commit is contained in:
Andy Russell 2020-07-19 13:03:35 -04:00
parent 48036804d2
commit 7f3e2c0d37
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
17 changed files with 290 additions and 298 deletions

View file

@ -1,15 +1,15 @@
error: `[v2]` cannot be resolved, ignoring it.
error: unresolved link to `v2`
--> $DIR/deny-intra-link-resolution-failure.rs:3:6
|
LL | /// [v2]
| ^^ cannot be resolved, ignoring
| ^^ unresolved link
|
note: the lint level is defined here
--> $DIR/deny-intra-link-resolution-failure.rs:1:9
|
LL | #![deny(intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: aborting due to previous error

View file

@ -1,15 +1,15 @@
error: `[TypeAlias::hoge]` cannot be resolved, ignoring it.
error: unresolved link to `TypeAlias::hoge`
--> $DIR/intra-doc-alias-ice.rs:5:30
|
LL | /// [broken cross-reference](TypeAlias::hoge)
| ^^^^^^^^^^^^^^^ cannot be resolved, ignoring
| ^^^^^^^^^^^^^^^ unresolved link
|
note: the lint level is defined here
--> $DIR/intra-doc-alias-ice.rs:1:9
|
LL | #![deny(intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: aborting due to previous error

View file

@ -7,7 +7,7 @@
/// ## For example:
///
/// arr[i]
//~^ ERROR `[i]` cannot be resolved, ignoring it.
//~^ ERROR `i`
pub fn test_ice() {
unimplemented!();
}

View file

@ -1,15 +1,15 @@
error: `[i]` cannot be resolved, ignoring it.
error: unresolved link to `i`
--> $DIR/intra-link-span-ice-55723.rs:9:10
|
LL | /// arr[i]
| ^ cannot be resolved, ignoring
| ^ unresolved link
|
note: the lint level is defined here
--> $DIR/intra-link-span-ice-55723.rs:1:9
|
LL | #![deny(intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: aborting due to previous error

View file

@ -23,23 +23,23 @@ pub enum Enum {
/// Like [Foo#hola].
///
/// Or maybe [Foo::f#hola].
//~^ ERROR `[Foo::f#hola]` has an issue with the link anchor.
//~^ ERROR `Foo::f#hola` contains an anchor
pub fn foo() {}
/// Empty.
///
/// Another anchor error: [hello#people#!].
//~^ ERROR `[hello#people#!]` has an issue with the link anchor.
//~^ ERROR `hello#people#!` contains multiple anchors
pub fn bar() {}
/// Empty?
///
/// Damn enum's variants: [Enum::A#whatever].
//~^ ERROR `[Enum::A#whatever]` has an issue with the link anchor.
//~^ ERROR `Enum::A#whatever` contains an anchor
pub fn enum_link() {}
/// Primitives?
///
/// [u32#hello]
//~^ ERROR `[u32#hello]` has an issue with the link anchor.
//~^ ERROR `u32#hello` contains an anchor
pub fn x() {}

View file

@ -1,8 +1,8 @@
error: `[Foo::f#hola]` has an issue with the link anchor.
error: `Foo::f#hola` contains an anchor, but links to struct fields are already anchored
--> $DIR/intra-links-anchors.rs:25:15
|
LL | /// Or maybe [Foo::f#hola].
| ^^^^^^^^^^^ struct fields cannot be followed by anchors
| ^^^^^^^^^^^ contains invalid anchor
|
note: the lint level is defined here
--> $DIR/intra-links-anchors.rs:1:9
@ -10,23 +10,23 @@ note: the lint level is defined here
LL | #![deny(intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `[hello#people#!]` has an issue with the link anchor.
error: `hello#people#!` contains multiple anchors
--> $DIR/intra-links-anchors.rs:31:28
|
LL | /// Another anchor error: [hello#people#!].
| ^^^^^^^^^^^^^^ only one `#` is allowed in a link
| ^^^^^^^^^^^^^^ contains invalid anchor
error: `[Enum::A#whatever]` has an issue with the link anchor.
error: `Enum::A#whatever` contains an anchor, but links to enum variants are already anchored
--> $DIR/intra-links-anchors.rs:37:28
|
LL | /// Damn enum's variants: [Enum::A#whatever].
| ^^^^^^^^^^^^^^^^ variants cannot be followed by anchors
| ^^^^^^^^^^^^^^^^ contains invalid anchor
error: `[u32#hello]` has an issue with the link anchor.
error: `u32#hello` contains an anchor, but links to primitive types are already anchored
--> $DIR/intra-links-anchors.rs:43:6
|
LL | /// [u32#hello]
| ^^^^^^^^^ primitive types cannot be followed by anchors
| ^^^^^^^^^ contains invalid anchor
error: aborting due to 4 previous errors

View file

@ -1,4 +1,4 @@
warning: `[DontDocMe]` public documentation for `DocMe` links to a private item
warning: public documentation for `DocMe` links to private item `DontDocMe`
--> $DIR/intra-links-private.rs:6:11
|
LL | /// docs [DontDocMe]

View file

@ -4,7 +4,7 @@
#![cfg_attr(private, deny(intra_doc_link_resolution_failure))]
/// docs [DontDocMe]
//[public]~^ WARNING `[DontDocMe]` public documentation for `DocMe` links to a private item
//[public]~^ WARNING public documentation for `DocMe` links to private item `DontDocMe`
// FIXME: for [private] we should also make sure the link was actually generated
pub struct DocMe;
struct DontDocMe;

View file

@ -6,16 +6,16 @@
/// [error]
pub struct A;
//~^^ WARNING `[error]` cannot be resolved
//~^^ WARNING `error`
///
/// docs [error1]
//~^ WARNING `[error1]` cannot be resolved
//~^ WARNING `error1`
/// docs [error2]
///
pub struct B;
//~^^^ WARNING `[error2]` cannot be resolved
//~^^^ WARNING `error2`
/**
* This is a multi-line comment.
@ -23,4 +23,4 @@ pub struct B;
* It also has an [error].
*/
pub struct C;
//~^^^ WARNING `[error]` cannot be resolved
//~^^^ WARNING `error`

View file

@ -1,35 +1,35 @@
warning: `[error]` cannot be resolved, ignoring it.
warning: unresolved link to `error`
--> $DIR/intra-links-warning-crlf.rs:7:6
|
LL | /// [error]
| ^^^^^ cannot be resolved, ignoring
| ^^^^^ unresolved link
|
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error1]` cannot be resolved, ignoring it.
warning: unresolved link to `error1`
--> $DIR/intra-links-warning-crlf.rs:12:11
|
LL | /// docs [error1]
| ^^^^^^ cannot be resolved, ignoring
| ^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error2]` cannot be resolved, ignoring it.
warning: unresolved link to `error2`
--> $DIR/intra-links-warning-crlf.rs:15:11
|
LL | /// docs [error2]
| ^^^^^^ cannot be resolved, ignoring
| ^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error]` cannot be resolved, ignoring it.
warning: unresolved link to `error`
--> $DIR/intra-links-warning-crlf.rs:23:20
|
LL | * It also has an [error].
| ^^^^^ cannot be resolved, ignoring
| ^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 4 warnings emitted

View file

@ -1,37 +1,37 @@
// check-pass
//! Test with [Foo::baz], [Bar::foo], ...
//~^ WARNING `[Foo::baz]` cannot be resolved
//~| WARNING `[Bar::foo]` cannot be resolved
//~^ WARNING `Foo::baz`
//~| WARNING `Bar::foo`
//! , [Uniooon::X] and [Qux::Z].
//~^ WARNING `[Uniooon::X]` cannot be resolved
//~| WARNING `[Qux::Z]` cannot be resolved
//~^ WARNING `Uniooon::X`
//~| WARNING `Qux::Z`
//!
//! , [Uniooon::X] and [Qux::Z].
//~^ WARNING `[Uniooon::X]` cannot be resolved
//~| WARNING `[Qux::Z]` cannot be resolved
//~^ WARNING `Uniooon::X`
//~| WARNING `Qux::Z`
/// [Qux:Y]
//~^ WARNING `[Qux:Y]` cannot be resolved
//~^ WARNING `Qux:Y`
pub struct Foo {
pub bar: usize,
}
/// Foo
/// bar [BarA] bar //~ WARNING `[BarA]` cannot be resolved
/// bar [BarA] bar //~ WARNING `BarA`
/// baz
pub fn a() {}
/**
* Foo
* bar [BarB] bar //~ WARNING `[BarB]` cannot be resolved
* bar [BarB] bar //~ WARNING `BarB`
* baz
*/
pub fn b() {}
/** Foo
bar [BarC] bar //~ WARNING `[BarC]` cannot be resolved
bar [BarC] bar //~ WARNING `BarC`
baz
let bar_c_1 = 0;
@ -42,12 +42,12 @@ baz
*/
pub fn c() {}
#[doc = "Foo\nbar [BarD] bar\nbaz"] //~ WARNING `[BarD]` cannot be resolved
#[doc = "Foo\nbar [BarD] bar\nbaz"] //~ WARNING `BarD`
pub fn d() {}
macro_rules! f {
($f:expr) => {
#[doc = $f] //~ WARNING `[BarF]` cannot be resolved
#[doc = $f] //~ WARNING `BarF`
pub fn f() {}
}
}
@ -55,30 +55,30 @@ f!("Foo\nbar [BarF] bar\nbaz");
/** # for example,
*
* time to introduce a link [error]*/ //~ WARNING `[error]` cannot be resolved
* time to introduce a link [error]*/ //~ WARNING `error`
pub struct A;
/**
* # for example,
*
* time to introduce a link [error] //~ WARNING `[error]` cannot be resolved
* time to introduce a link [error] //~ WARNING `error`
*/
pub struct B;
#[doc = "single line [error]"] //~ WARNING `[error]` cannot be resolved
#[doc = "single line [error]"] //~ WARNING `error`
pub struct C;
#[doc = "single line with \"escaping\" [error]"] //~ WARNING `[error]` cannot be resolved
#[doc = "single line with \"escaping\" [error]"] //~ WARNING `error`
pub struct D;
/// Item docs. //~ WARNING `[error]` cannot be resolved
/// Item docs. //~ WARNING `error`
#[doc="Hello there!"]
/// [error]
pub struct E;
///
/// docs [error1] //~ WARNING `[error1]` cannot be resolved
/// docs [error1] //~ WARNING `error1`
/// docs [error2] //~ WARNING `[error2]` cannot be resolved
/// docs [error2] //~ WARNING `error2`
///
pub struct F;

View file

@ -1,77 +1,77 @@
warning: `[Foo::baz]` cannot be resolved, ignoring it.
warning: unresolved link to `Foo::baz`
--> $DIR/intra-links-warning.rs:3:23
|
LL | //! Test with [Foo::baz], [Bar::foo], ...
| ^^^^^^^^ cannot be resolved, ignoring
| ^^^^^^^^ unresolved link
|
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[Bar::foo]` cannot be resolved, ignoring it.
warning: unresolved link to `Bar::foo`
--> $DIR/intra-links-warning.rs:3:35
|
LL | //! Test with [Foo::baz], [Bar::foo], ...
| ^^^^^^^^ cannot be resolved, ignoring
| ^^^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[Uniooon::X]` cannot be resolved, ignoring it.
warning: unresolved link to `Uniooon::X`
--> $DIR/intra-links-warning.rs:6:13
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^^^^^ cannot be resolved, ignoring
| ^^^^^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[Qux::Z]` cannot be resolved, ignoring it.
warning: unresolved link to `Qux::Z`
--> $DIR/intra-links-warning.rs:6:30
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^ cannot be resolved, ignoring
| ^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[Uniooon::X]` cannot be resolved, ignoring it.
warning: unresolved link to `Uniooon::X`
--> $DIR/intra-links-warning.rs:10:14
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^^^^^ cannot be resolved, ignoring
| ^^^^^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[Qux::Z]` cannot be resolved, ignoring it.
warning: unresolved link to `Qux::Z`
--> $DIR/intra-links-warning.rs:10:31
|
LL | //! , [Uniooon::X] and [Qux::Z].
| ^^^^^^ cannot be resolved, ignoring
| ^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[Qux:Y]` cannot be resolved, ignoring it.
warning: unresolved link to `Qux:Y`
--> $DIR/intra-links-warning.rs:14:13
|
LL | /// [Qux:Y]
| ^^^^^ cannot be resolved, ignoring
| ^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error]` cannot be resolved, ignoring it.
warning: unresolved link to `error`
--> $DIR/intra-links-warning.rs:58:30
|
LL | * time to introduce a link [error]*/
| ^^^^^ cannot be resolved, ignoring
| ^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error]` cannot be resolved, ignoring it.
warning: unresolved link to `error`
--> $DIR/intra-links-warning.rs:64:30
|
LL | * time to introduce a link [error]
| ^^^^^ cannot be resolved, ignoring
| ^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error]` cannot be resolved, ignoring it.
warning: unresolved link to `error`
--> $DIR/intra-links-warning.rs:68:1
|
LL | #[doc = "single line [error]"]
@ -81,9 +81,9 @@ LL | #[doc = "single line [error]"]
single line [error]
^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error]` cannot be resolved, ignoring it.
warning: unresolved link to `error`
--> $DIR/intra-links-warning.rs:71:1
|
LL | #[doc = "single line with \"escaping\" [error]"]
@ -93,9 +93,9 @@ LL | #[doc = "single line with \"escaping\" [error]"]
single line with "escaping" [error]
^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error]` cannot be resolved, ignoring it.
warning: unresolved link to `error`
--> $DIR/intra-links-warning.rs:74:1
|
LL | / /// Item docs.
@ -107,49 +107,49 @@ LL | | /// [error]
[error]
^^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error1]` cannot be resolved, ignoring it.
warning: unresolved link to `error1`
--> $DIR/intra-links-warning.rs:80:11
|
LL | /// docs [error1]
| ^^^^^^ cannot be resolved, ignoring
| ^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[error2]` cannot be resolved, ignoring it.
warning: unresolved link to `error2`
--> $DIR/intra-links-warning.rs:82:11
|
LL | /// docs [error2]
| ^^^^^^ cannot be resolved, ignoring
| ^^^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[BarA]` cannot be resolved, ignoring it.
warning: unresolved link to `BarA`
--> $DIR/intra-links-warning.rs:21:10
|
LL | /// bar [BarA] bar
| ^^^^ cannot be resolved, ignoring
| ^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[BarB]` cannot be resolved, ignoring it.
warning: unresolved link to `BarB`
--> $DIR/intra-links-warning.rs:27:9
|
LL | * bar [BarB] bar
| ^^^^ cannot be resolved, ignoring
| ^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[BarC]` cannot be resolved, ignoring it.
warning: unresolved link to `BarC`
--> $DIR/intra-links-warning.rs:34:6
|
LL | bar [BarC] bar
| ^^^^ cannot be resolved, ignoring
| ^^^^ unresolved link
|
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[BarD]` cannot be resolved, ignoring it.
warning: unresolved link to `BarD`
--> $DIR/intra-links-warning.rs:45:1
|
LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
@ -159,9 +159,9 @@ LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
bar [BarD] bar
^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: `[BarF]` cannot be resolved, ignoring it.
warning: unresolved link to `BarF`
--> $DIR/intra-links-warning.rs:50:9
|
LL | #[doc = $f]
@ -174,7 +174,7 @@ LL | f!("Foo\nbar [BarF] bar\nbaz");
bar [BarF] bar
^^^^
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 19 warnings emitted

View file

@ -1,4 +1,4 @@
warning: `[PrivateType]` public documentation for `public_item` links to a private item
warning: public documentation for `public_item` links to private item `PrivateType`
--> $DIR/issue-74134.rs:19:10
|
LL | /// [`PrivateType`]

View file

@ -17,7 +17,7 @@ pub struct PublicType;
pub struct Public {
/// [`PublicType`]
/// [`PrivateType`]
//[public]~^ WARNING public documentation for `public_item` links to a private
//[public]~^ WARNING public documentation for `public_item` links to private item `PrivateType`
pub public_item: u32,
/// [`PublicType`]

View file

@ -11,7 +11,7 @@
/// ```
/// println!("sup");
/// ```
pub fn link_error() {} //~^^^^^ ERROR cannot be resolved, ignoring it
pub fn link_error() {} //~^^^^^ ERROR unresolved link to `error`
/// wait, this doesn't have a doctest?
pub fn no_doctest() {} //~^ ERROR missing code example in this documentation

View file

@ -15,11 +15,11 @@ LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(private_doc_tests)]` implied by `#[deny(rustdoc)]`
error: `[error]` cannot be resolved, ignoring it.
error: unresolved link to `error`
--> $DIR/lint-group.rs:9:29
|
LL | /// what up, let's make an [error]
| ^^^^^ cannot be resolved, ignoring
| ^^^^^ unresolved link
|
note: the lint level is defined here
--> $DIR/lint-group.rs:7:9
@ -27,7 +27,7 @@ note: the lint level is defined here
LL | #![deny(rustdoc)]
| ^^^^^^^
= note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]`
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: missing code example in this documentation
--> $DIR/lint-group.rs:16:1