Skip to content

Commit 8fe5b56

Browse files
Rollup merge of #109104 - GuillaumeGomez:fix-invalid-suggestion-ambiguous-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`
2 parents 480068c + 415a3ca commit 8fe5b56

26 files changed

+702
-189
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+242-142
Large diffs are not rendered by default.

tests/rustdoc-ui/intra-doc/ambiguity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ pub mod foo {
3535
/// Ambiguous non-implied shortcut link [`foo::bar`]. //~ERROR `foo::bar`
3636
pub struct Docs {}
3737

38-
/// [true] //~ ERROR `true` is both a module and a builtin type
38+
/// [true] //~ ERROR `true` is both a module and a primitive type
3939
/// [primitive@true]
4040
pub mod r#true {}
+27-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `true` is both a module and a builtin type
1+
error: `true` is both a module and a primitive type
22
--> $DIR/ambiguity.rs:38:6
33
|
44
LL | /// [true]
@@ -13,89 +13,89 @@ help: to link to the module, prefix with `mod@`
1313
|
1414
LL | /// [mod@true]
1515
| ++++
16-
help: to link to the builtin type, prefix with `prim@`
16+
help: to link to the primitive type, prefix with `prim@`
1717
|
1818
LL | /// [prim@true]
1919
| +++++
2020

21-
error: `ambiguous` is both a struct and a function
21+
error: `ambiguous` is both a function and a struct
2222
--> $DIR/ambiguity.rs:27:7
2323
|
2424
LL | /// [`ambiguous`] is ambiguous.
2525
| ^^^^^^^^^ ambiguous link
2626
|
27-
help: to link to the struct, prefix with `struct@`
28-
|
29-
LL | /// [`struct@ambiguous`] is ambiguous.
30-
| +++++++
3127
help: to link to the function, add parentheses
3228
|
3329
LL | /// [`ambiguous()`] is ambiguous.
3430
| ++
31+
help: to link to the struct, prefix with `struct@`
32+
|
33+
LL | /// [`struct@ambiguous`] is ambiguous.
34+
| +++++++
3535

36-
error: `ambiguous` is both a struct and a function
36+
error: `ambiguous` is both a function and a struct
3737
--> $DIR/ambiguity.rs:29:6
3838
|
3939
LL | /// [ambiguous] is ambiguous.
4040
| ^^^^^^^^^ ambiguous link
4141
|
42-
help: to link to the struct, prefix with `struct@`
43-
|
44-
LL | /// [struct@ambiguous] is ambiguous.
45-
| +++++++
4642
help: to link to the function, add parentheses
4743
|
4844
LL | /// [ambiguous()] is ambiguous.
4945
| ++
46+
help: to link to the struct, prefix with `struct@`
47+
|
48+
LL | /// [struct@ambiguous] is ambiguous.
49+
| +++++++
5050

51-
error: `multi_conflict` is a struct, a function, and a macro
51+
error: `multi_conflict` is a function, a struct, and a macro
5252
--> $DIR/ambiguity.rs:31:7
5353
|
5454
LL | /// [`multi_conflict`] is a three-way conflict.
5555
| ^^^^^^^^^^^^^^ ambiguous link
5656
|
57-
help: to link to the struct, prefix with `struct@`
58-
|
59-
LL | /// [`struct@multi_conflict`] is a three-way conflict.
60-
| +++++++
6157
help: to link to the function, add parentheses
6258
|
6359
LL | /// [`multi_conflict()`] is a three-way conflict.
6460
| ++
61+
help: to link to the struct, prefix with `struct@`
62+
|
63+
LL | /// [`struct@multi_conflict`] is a three-way conflict.
64+
| +++++++
6565
help: to link to the macro, add an exclamation mark
6666
|
6767
LL | /// [`multi_conflict!`] is a three-way conflict.
6868
| +
6969

70-
error: `type_and_value` is both a module and a constant
70+
error: `type_and_value` is both a constant and a module
7171
--> $DIR/ambiguity.rs:33:16
7272
|
7373
LL | /// Ambiguous [type_and_value].
7474
| ^^^^^^^^^^^^^^ ambiguous link
7575
|
76-
help: to link to the module, prefix with `mod@`
77-
|
78-
LL | /// Ambiguous [mod@type_and_value].
79-
| ++++
8076
help: to link to the constant, prefix with `const@`
8177
|
8278
LL | /// Ambiguous [const@type_and_value].
8379
| ++++++
80+
help: to link to the module, prefix with `mod@`
81+
|
82+
LL | /// Ambiguous [mod@type_and_value].
83+
| ++++
8484

85-
error: `foo::bar` is both an enum and a function
85+
error: `foo::bar` is both a function and an enum
8686
--> $DIR/ambiguity.rs:35:43
8787
|
8888
LL | /// Ambiguous non-implied shortcut link [`foo::bar`].
8989
| ^^^^^^^^ ambiguous link
9090
|
91-
help: to link to the enum, prefix with `enum@`
92-
|
93-
LL | /// Ambiguous non-implied shortcut link [`enum@foo::bar`].
94-
| +++++
9591
help: to link to the function, add parentheses
9692
|
9793
LL | /// Ambiguous non-implied shortcut link [`foo::bar()`].
9894
| ++
95+
help: to link to the enum, prefix with `enum@`
96+
|
97+
LL | /// Ambiguous non-implied shortcut link [`enum@foo::bar`].
98+
| +++++
9999

100100
error: aborting due to 6 previous errors
101101

tests/rustdoc-ui/intra-doc/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454

5555
/// [u8::not_found]
5656
//~^ ERROR unresolved link
57-
//~| NOTE the builtin type `u8` has no associated item named `not_found`
57+
//~| NOTE the primitive type `u8` has no associated item named `not_found`
5858

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

6363
/// [type@Vec::into_iter]
6464
//~^ ERROR unresolved link

tests/rustdoc-ui/intra-doc/errors.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ error: unresolved link to `u8::not_found`
8080
--> $DIR/errors.rs:55:6
8181
|
8282
LL | /// [u8::not_found]
83-
| ^^^^^^^^^^^^^ the builtin type `u8` has no associated item named `not_found`
83+
| ^^^^^^^^^^^^^ the primitive type `u8` has no associated item named `not_found`
8484

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

9191
error: unresolved link to `Vec::into_iter`
9292
--> $DIR/errors.rs:63:6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This test ensures that this warning doesn't show up:
2+
// warning: `PartialEq` is both a trait and a derive macro
3+
// --> tests/rustdoc-ui/intra-doc/issue-108653-associated-items-10.rs:1:7
4+
// |
5+
// 1 | //! [`PartialEq`]
6+
// | ^^^^^^^^^ ambiguous link
7+
// |
8+
// = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
9+
// help: to link to the trait, prefix with `trait@`
10+
// |
11+
// 1 | //! [`trait@PartialEq`]
12+
// | ++++++
13+
// help: to link to the derive macro, prefix with `derive@`
14+
// |
15+
// 1 | //! [`derive@PartialEq`]
16+
// | +++++++
17+
18+
// check-pass
19+
20+
#![deny(rustdoc::broken_intra_doc_links)]
21+
22+
//! [`PartialEq`]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This is ensuring that the UI output for associated items is as expected.
2+
3+
#![deny(rustdoc::broken_intra_doc_links)]
4+
5+
/// [`Trait::IDENT`]
6+
//~^ ERROR both an associated constant and an associated type
7+
pub trait Trait {
8+
type IDENT;
9+
const IDENT: usize;
10+
}
11+
12+
/// [`Trait2::IDENT`]
13+
//~^ ERROR both an associated function and an associated type
14+
pub trait Trait2 {
15+
type IDENT;
16+
fn IDENT() {}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error: `Trait::IDENT` is both an associated constant and an associated type
2+
--> $DIR/issue-108653-associated-items-2.rs:5:7
3+
|
4+
LL | /// [`Trait::IDENT`]
5+
| ^^^^^^^^^^^^ ambiguous link
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-108653-associated-items-2.rs:3:9
9+
|
10+
LL | #![deny(rustdoc::broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: to link to the associated constant, prefix with `const@`
13+
|
14+
LL | /// [`const@Trait::IDENT`]
15+
| ++++++
16+
help: to link to the associated type, prefix with `type@`
17+
|
18+
LL | /// [`type@Trait::IDENT`]
19+
| +++++
20+
21+
error: `Trait2::IDENT` is both an associated function and an associated type
22+
--> $DIR/issue-108653-associated-items-2.rs:12:7
23+
|
24+
LL | /// [`Trait2::IDENT`]
25+
| ^^^^^^^^^^^^^ ambiguous link
26+
|
27+
help: to link to the associated function, add parentheses
28+
|
29+
LL | /// [`Trait2::IDENT()`]
30+
| ++
31+
help: to link to the associated type, prefix with `type@`
32+
|
33+
LL | /// [`type@Trait2::IDENT`]
34+
| +++++
35+
36+
error: aborting due to 2 previous errors
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This is ensuring that the UI output for associated items works when it's being documented
2+
// from another item.
3+
4+
#![deny(rustdoc::broken_intra_doc_links)]
5+
#![allow(nonstandard_style)]
6+
7+
pub trait Trait {
8+
type Trait;
9+
const Trait: usize;
10+
}
11+
12+
/// [`Trait`]
13+
//~^ ERROR both a constant and a trait
14+
/// [`Trait::Trait`]
15+
//~^ ERROR both an associated constant and an associated type
16+
pub const Trait: usize = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error: `Trait` is both a constant and a trait
2+
--> $DIR/issue-108653-associated-items-3.rs:12:7
3+
|
4+
LL | /// [`Trait`]
5+
| ^^^^^ ambiguous link
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-108653-associated-items-3.rs:4:9
9+
|
10+
LL | #![deny(rustdoc::broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: to link to the constant, prefix with `const@`
13+
|
14+
LL | /// [`const@Trait`]
15+
| ++++++
16+
help: to link to the trait, prefix with `trait@`
17+
|
18+
LL | /// [`trait@Trait`]
19+
| ++++++
20+
21+
error: `Trait::Trait` is both an associated constant and an associated type
22+
--> $DIR/issue-108653-associated-items-3.rs:14:7
23+
|
24+
LL | /// [`Trait::Trait`]
25+
| ^^^^^^^^^^^^ ambiguous link
26+
|
27+
help: to link to the associated constant, prefix with `const@`
28+
|
29+
LL | /// [`const@Trait::Trait`]
30+
| ++++++
31+
help: to link to the associated type, prefix with `type@`
32+
|
33+
LL | /// [`type@Trait::Trait`]
34+
| +++++
35+
36+
error: aborting due to 2 previous errors
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This is ensuring that the UI output for associated items works when it's being documented
2+
// from another item.
3+
4+
#![deny(rustdoc::broken_intra_doc_links)]
5+
#![allow(nonstandard_style)]
6+
7+
pub trait Trait {
8+
type Trait;
9+
}
10+
11+
/// [`Struct::Trait`]
12+
//~^ ERROR both an associated constant and an associated type
13+
pub struct Struct;
14+
15+
impl Trait for Struct {
16+
type Trait = Struct;
17+
}
18+
19+
impl Struct {
20+
pub const Trait: usize = 0;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: `Struct::Trait` is both an associated constant and an associated type
2+
--> $DIR/issue-108653-associated-items-4.rs:11:7
3+
|
4+
LL | /// [`Struct::Trait`]
5+
| ^^^^^^^^^^^^^ ambiguous link
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-108653-associated-items-4.rs:4:9
9+
|
10+
LL | #![deny(rustdoc::broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: to link to the associated constant, prefix with `const@`
13+
|
14+
LL | /// [`const@Struct::Trait`]
15+
| ++++++
16+
help: to link to the associated type, prefix with `type@`
17+
|
18+
LL | /// [`type@Struct::Trait`]
19+
| +++++
20+
21+
error: aborting due to previous error
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![deny(rustdoc::broken_intra_doc_links)]
2+
#![allow(nonstandard_style)]
3+
4+
/// [`u32::MAX`]
5+
//~^ ERROR both an associated constant and a trait
6+
pub mod u32 {
7+
pub trait MAX {}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: `u32::MAX` is both an associated constant and a trait
2+
--> $DIR/issue-108653-associated-items-5.rs:4:7
3+
|
4+
LL | /// [`u32::MAX`]
5+
| ^^^^^^^^ ambiguous link
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-108653-associated-items-5.rs:1:9
9+
|
10+
LL | #![deny(rustdoc::broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: to link to the associated constant, prefix with `const@`
13+
|
14+
LL | /// [`const@u32::MAX`]
15+
| ++++++
16+
help: to link to the trait, prefix with `trait@`
17+
|
18+
LL | /// [`trait@u32::MAX`]
19+
| ++++++
20+
21+
error: aborting due to previous error
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![deny(rustdoc::broken_intra_doc_links)]
2+
#![allow(nonstandard_style)]
3+
4+
/// [`u32::MAX`]
5+
//~^ ERROR both an associated constant and a primitive type
6+
pub mod u32 {
7+
pub use std::primitive::u32 as MAX;
8+
}

0 commit comments

Comments
 (0)