Auto merge of #58824 - euclio:intra-link-ambiguity, r=petrochenkov

overhaul intra-doc-link ambiguity warning

Fixes #52784.

- Makes the warning part of the `intra_doc_link_resolution_failure`
lint.
- Tightens the span to just the ambiguous link.
- Reports ambiguities across all three namespaces.
- Uses structured suggestions for disambiguation.
- Adds a test for the warnings.

r? @QuietMisdreavus
This commit is contained in:
bors 2019-03-18 02:56:35 +00:00
commit 03dafa7da3
4 changed files with 296 additions and 153 deletions

View file

@ -0,0 +1,36 @@
#![deny(intra_doc_link_resolution_failure)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
pub fn ambiguous() {}
pub struct ambiguous {}
#[macro_export]
macro_rules! multi_conflict { () => {} }
#[allow(non_camel_case_types)]
pub struct multi_conflict {}
pub fn multi_conflict() {}
pub mod type_and_value {}
pub const type_and_value: i32 = 0;
pub mod foo {
pub enum bar {}
pub fn bar() {}
}
/// [`ambiguous`] is ambiguous. //~ERROR `ambiguous`
///
/// [ambiguous] is ambiguous. //~ERROR ambiguous
///
/// [`multi_conflict`] is a three-way conflict. //~ERROR `multi_conflict`
///
/// Ambiguous [type_and_value]. //~ERROR type_and_value
///
/// Ambiguous non-implied shortcut link [`foo::bar`]. //~ERROR `foo::bar`
pub struct Docs {}

View file

@ -0,0 +1,82 @@
error: `ambiguous` is both a struct and a function
--> $DIR/intra-links-ambiguity.rs:27:6
|
LL | /// [`ambiguous`] is ambiguous.
| ^^^^^^^^^^^ ambiguous link
|
note: lint level defined here
--> $DIR/intra-links-ambiguity.rs:1:9
|
LL | #![deny(intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the struct, prefix with the item type
|
LL | /// [`struct@ambiguous`] is ambiguous.
| ^^^^^^^^^^^^^^^^^^
help: to link to the function, add parentheses
|
LL | /// [`ambiguous()`] is ambiguous.
| ^^^^^^^^^^^^^
error: `ambiguous` is both a struct and a function
--> $DIR/intra-links-ambiguity.rs:29:6
|
LL | /// [ambiguous] is ambiguous.
| ^^^^^^^^^ ambiguous link
help: to link to the struct, prefix with the item type
|
LL | /// [struct@ambiguous] is ambiguous.
| ^^^^^^^^^^^^^^^^
help: to link to the function, add parentheses
|
LL | /// [ambiguous()] is ambiguous.
| ^^^^^^^^^^^
error: `multi_conflict` is a struct, a function, and a macro
--> $DIR/intra-links-ambiguity.rs:31:6
|
LL | /// [`multi_conflict`] is a three-way conflict.
| ^^^^^^^^^^^^^^^^ ambiguous link
help: to link to the struct, prefix with the item type
|
LL | /// [`struct@multi_conflict`] is a three-way conflict.
| ^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the function, add parentheses
|
LL | /// [`multi_conflict()`] is a three-way conflict.
| ^^^^^^^^^^^^^^^^^^
help: to link to the macro, add an exclamation mark
|
LL | /// [`multi_conflict!`] is a three-way conflict.
| ^^^^^^^^^^^^^^^^^
error: `type_and_value` is both a module and a constant
--> $DIR/intra-links-ambiguity.rs:33:16
|
LL | /// Ambiguous [type_and_value].
| ^^^^^^^^^^^^^^ ambiguous link
help: to link to the module, prefix with the item type
|
LL | /// Ambiguous [module@type_and_value].
| ^^^^^^^^^^^^^^^^^^^^^
help: to link to the constant, prefix with the item type
|
LL | /// Ambiguous [const@type_and_value].
| ^^^^^^^^^^^^^^^^^^^^
error: `foo::bar` is both an enum and a function
--> $DIR/intra-links-ambiguity.rs:35:42
|
LL | /// Ambiguous non-implied shortcut link [`foo::bar`].
| ^^^^^^^^^^ ambiguous link
help: to link to the enum, prefix with the item type
|
LL | /// Ambiguous non-implied shortcut link [`enum@foo::bar`].
| ^^^^^^^^^^^^^^^
help: to link to the function, add parentheses
|
LL | /// Ambiguous non-implied shortcut link [`foo::bar()`].
| ^^^^^^^^^^^^
error: aborting due to 5 previous errors

View file

@ -22,6 +22,7 @@
//! * [`ThisType::this_method`](ThisType::this_method)
//! * [`ThisEnum`](ThisEnum)
//! * [`ThisEnum::ThisVariant`](ThisEnum::ThisVariant)
//! * [`ThisEnum::ThisVariantCtor`](ThisEnum::ThisVariantCtor)
//! * [`ThisTrait`](ThisTrait)
//! * [`ThisTrait::this_associated_method`](ThisTrait::this_associated_method)
//! * [`ThisTrait::ThisAssociatedType`](ThisTrait::ThisAssociatedType)
@ -50,7 +51,7 @@ pub struct ThisType;
impl ThisType {
pub fn this_method() {}
}
pub enum ThisEnum { ThisVariant, }
pub enum ThisEnum { ThisVariant, ThisVariantCtor(u32), }
pub trait ThisTrait {
type ThisAssociatedType;
const THIS_ASSOCIATED_CONST: u8;