Skip to content

Commit

Permalink
Rollup merge of #109104 - GuillaumeGomez:fix-invalid-suggestion-ambig…
Browse files Browse the repository at this point in the history
…uous-intra-doc2, r=oli-obk,notriddle

rustdoc: Fix invalid suggestions on ambiguous intra doc links v2

Fixes #108653.

This is another approach to fixing the same issue. This time, we keep the computed information around instead of re-computing it.

Strangely enough, the order for ambiguities seem to have been changed. Not an issue but it creates a lot of diff...

So which version do you prefer?

r? `@notriddle`
  • Loading branch information
GuillaumeGomez authored Mar 31, 2023
2 parents 480068c + 415a3ca commit 8fe5b56
Show file tree
Hide file tree
Showing 26 changed files with 702 additions and 189 deletions.
384 changes: 242 additions & 142 deletions src/librustdoc/passes/collect_intra_doc_links.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/rustdoc-ui/intra-doc/ambiguity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ pub mod foo {
/// Ambiguous non-implied shortcut link [`foo::bar`]. //~ERROR `foo::bar`
pub struct Docs {}

/// [true] //~ ERROR `true` is both a module and a builtin type
/// [true] //~ ERROR `true` is both a module and a primitive type
/// [primitive@true]
pub mod r#true {}
54 changes: 27 additions & 27 deletions tests/rustdoc-ui/intra-doc/ambiguity.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `true` is both a module and a builtin type
error: `true` is both a module and a primitive type
--> $DIR/ambiguity.rs:38:6
|
LL | /// [true]
Expand All @@ -13,89 +13,89 @@ help: to link to the module, prefix with `mod@`
|
LL | /// [mod@true]
| ++++
help: to link to the builtin type, prefix with `prim@`
help: to link to the primitive type, prefix with `prim@`
|
LL | /// [prim@true]
| +++++

error: `ambiguous` is both a struct and a function
error: `ambiguous` is both a function and a struct
--> $DIR/ambiguity.rs:27:7
|
LL | /// [`ambiguous`] is ambiguous.
| ^^^^^^^^^ ambiguous link
|
help: to link to the struct, prefix with `struct@`
|
LL | /// [`struct@ambiguous`] is ambiguous.
| +++++++
help: to link to the function, add parentheses
|
LL | /// [`ambiguous()`] is ambiguous.
| ++
help: to link to the struct, prefix with `struct@`
|
LL | /// [`struct@ambiguous`] is ambiguous.
| +++++++

error: `ambiguous` is both a struct and a function
error: `ambiguous` is both a function and a struct
--> $DIR/ambiguity.rs:29:6
|
LL | /// [ambiguous] is ambiguous.
| ^^^^^^^^^ ambiguous link
|
help: to link to the struct, prefix with `struct@`
|
LL | /// [struct@ambiguous] is ambiguous.
| +++++++
help: to link to the function, add parentheses
|
LL | /// [ambiguous()] is ambiguous.
| ++
help: to link to the struct, prefix with `struct@`
|
LL | /// [struct@ambiguous] is ambiguous.
| +++++++

error: `multi_conflict` is a struct, a function, and a macro
error: `multi_conflict` is a function, a struct, and a macro
--> $DIR/ambiguity.rs:31:7
|
LL | /// [`multi_conflict`] is a three-way conflict.
| ^^^^^^^^^^^^^^ ambiguous link
|
help: to link to the struct, prefix with `struct@`
|
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 struct, prefix with `struct@`
|
LL | /// [`struct@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
error: `type_and_value` is both a constant and a module
--> $DIR/ambiguity.rs:33:16
|
LL | /// Ambiguous [type_and_value].
| ^^^^^^^^^^^^^^ ambiguous link
|
help: to link to the module, prefix with `mod@`
|
LL | /// Ambiguous [mod@type_and_value].
| ++++
help: to link to the constant, prefix with `const@`
|
LL | /// Ambiguous [const@type_and_value].
| ++++++
help: to link to the module, prefix with `mod@`
|
LL | /// Ambiguous [mod@type_and_value].
| ++++

error: `foo::bar` is both an enum and a function
error: `foo::bar` is both a function and an enum
--> $DIR/ambiguity.rs:35:43
|
LL | /// Ambiguous non-implied shortcut link [`foo::bar`].
| ^^^^^^^^ ambiguous link
|
help: to link to the enum, prefix with `enum@`
|
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()`].
| ++
help: to link to the enum, prefix with `enum@`
|
LL | /// Ambiguous non-implied shortcut link [`enum@foo::bar`].
| +++++

error: aborting due to 6 previous errors

4 changes: 2 additions & 2 deletions tests/rustdoc-ui/intra-doc/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@

/// [u8::not_found]
//~^ ERROR unresolved link
//~| NOTE the builtin type `u8` has no associated item named `not_found`
//~| NOTE the primitive type `u8` has no associated item named `not_found`

/// [std::primitive::u8::not_found]
//~^ ERROR unresolved link
//~| NOTE the builtin type `u8` has no associated item named `not_found`
//~| NOTE the primitive type `u8` has no associated item named `not_found`

/// [type@Vec::into_iter]
//~^ ERROR unresolved link
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc-ui/intra-doc/errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ error: unresolved link to `u8::not_found`
--> $DIR/errors.rs:55:6
|
LL | /// [u8::not_found]
| ^^^^^^^^^^^^^ the builtin type `u8` has no associated item named `not_found`
| ^^^^^^^^^^^^^ the primitive type `u8` has no associated item named `not_found`

error: unresolved link to `std::primitive::u8::not_found`
--> $DIR/errors.rs:59:6
|
LL | /// [std::primitive::u8::not_found]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the builtin type `u8` has no associated item named `not_found`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the primitive type `u8` has no associated item named `not_found`

error: unresolved link to `Vec::into_iter`
--> $DIR/errors.rs:63:6
Expand Down
22 changes: 22 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-10.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This test ensures that this warning doesn't show up:
// warning: `PartialEq` is both a trait and a derive macro
// --> tests/rustdoc-ui/intra-doc/issue-108653-associated-items-10.rs:1:7
// |
// 1 | //! [`PartialEq`]
// | ^^^^^^^^^ ambiguous link
// |
// = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
// help: to link to the trait, prefix with `trait@`
// |
// 1 | //! [`trait@PartialEq`]
// | ++++++
// help: to link to the derive macro, prefix with `derive@`
// |
// 1 | //! [`derive@PartialEq`]
// | +++++++

// check-pass

#![deny(rustdoc::broken_intra_doc_links)]

//! [`PartialEq`]
17 changes: 17 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This is ensuring that the UI output for associated items is as expected.

#![deny(rustdoc::broken_intra_doc_links)]

/// [`Trait::IDENT`]
//~^ ERROR both an associated constant and an associated type
pub trait Trait {
type IDENT;
const IDENT: usize;
}

/// [`Trait2::IDENT`]
//~^ ERROR both an associated function and an associated type
pub trait Trait2 {
type IDENT;
fn IDENT() {}
}
37 changes: 37 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error: `Trait::IDENT` is both an associated constant and an associated type
--> $DIR/issue-108653-associated-items-2.rs:5:7
|
LL | /// [`Trait::IDENT`]
| ^^^^^^^^^^^^ ambiguous link
|
note: the lint level is defined here
--> $DIR/issue-108653-associated-items-2.rs:3:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the associated constant, prefix with `const@`
|
LL | /// [`const@Trait::IDENT`]
| ++++++
help: to link to the associated type, prefix with `type@`
|
LL | /// [`type@Trait::IDENT`]
| +++++

error: `Trait2::IDENT` is both an associated function and an associated type
--> $DIR/issue-108653-associated-items-2.rs:12:7
|
LL | /// [`Trait2::IDENT`]
| ^^^^^^^^^^^^^ ambiguous link
|
help: to link to the associated function, add parentheses
|
LL | /// [`Trait2::IDENT()`]
| ++
help: to link to the associated type, prefix with `type@`
|
LL | /// [`type@Trait2::IDENT`]
| +++++

error: aborting due to 2 previous errors

16 changes: 16 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is ensuring that the UI output for associated items works when it's being documented
// from another item.

#![deny(rustdoc::broken_intra_doc_links)]
#![allow(nonstandard_style)]

pub trait Trait {
type Trait;
const Trait: usize;
}

/// [`Trait`]
//~^ ERROR both a constant and a trait
/// [`Trait::Trait`]
//~^ ERROR both an associated constant and an associated type
pub const Trait: usize = 0;
37 changes: 37 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error: `Trait` is both a constant and a trait
--> $DIR/issue-108653-associated-items-3.rs:12:7
|
LL | /// [`Trait`]
| ^^^^^ ambiguous link
|
note: the lint level is defined here
--> $DIR/issue-108653-associated-items-3.rs:4:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the constant, prefix with `const@`
|
LL | /// [`const@Trait`]
| ++++++
help: to link to the trait, prefix with `trait@`
|
LL | /// [`trait@Trait`]
| ++++++

error: `Trait::Trait` is both an associated constant and an associated type
--> $DIR/issue-108653-associated-items-3.rs:14:7
|
LL | /// [`Trait::Trait`]
| ^^^^^^^^^^^^ ambiguous link
|
help: to link to the associated constant, prefix with `const@`
|
LL | /// [`const@Trait::Trait`]
| ++++++
help: to link to the associated type, prefix with `type@`
|
LL | /// [`type@Trait::Trait`]
| +++++

error: aborting due to 2 previous errors

21 changes: 21 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This is ensuring that the UI output for associated items works when it's being documented
// from another item.

#![deny(rustdoc::broken_intra_doc_links)]
#![allow(nonstandard_style)]

pub trait Trait {
type Trait;
}

/// [`Struct::Trait`]
//~^ ERROR both an associated constant and an associated type
pub struct Struct;

impl Trait for Struct {
type Trait = Struct;
}

impl Struct {
pub const Trait: usize = 0;
}
22 changes: 22 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-4.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: `Struct::Trait` is both an associated constant and an associated type
--> $DIR/issue-108653-associated-items-4.rs:11:7
|
LL | /// [`Struct::Trait`]
| ^^^^^^^^^^^^^ ambiguous link
|
note: the lint level is defined here
--> $DIR/issue-108653-associated-items-4.rs:4:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the associated constant, prefix with `const@`
|
LL | /// [`const@Struct::Trait`]
| ++++++
help: to link to the associated type, prefix with `type@`
|
LL | /// [`type@Struct::Trait`]
| +++++

error: aborting due to previous error

8 changes: 8 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-5.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![allow(nonstandard_style)]

/// [`u32::MAX`]
//~^ ERROR both an associated constant and a trait
pub mod u32 {
pub trait MAX {}
}
22 changes: 22 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-5.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: `u32::MAX` is both an associated constant and a trait
--> $DIR/issue-108653-associated-items-5.rs:4:7
|
LL | /// [`u32::MAX`]
| ^^^^^^^^ ambiguous link
|
note: the lint level is defined here
--> $DIR/issue-108653-associated-items-5.rs:1:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the associated constant, prefix with `const@`
|
LL | /// [`const@u32::MAX`]
| ++++++
help: to link to the trait, prefix with `trait@`
|
LL | /// [`trait@u32::MAX`]
| ++++++

error: aborting due to previous error

8 changes: 8 additions & 0 deletions tests/rustdoc-ui/intra-doc/issue-108653-associated-items-6.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![allow(nonstandard_style)]

/// [`u32::MAX`]
//~^ ERROR both an associated constant and a primitive type
pub mod u32 {
pub use std::primitive::u32 as MAX;
}
Loading

0 comments on commit 8fe5b56

Please sign in to comment.