Auto merge of #130587 - coolreader18:field-variant-doclink-disambig, r=notriddle,jyn514
Add `field@` and `variant@` doc-link disambiguators I'm not sure if this is big enough to need an fcp or not, but this is something I found missing when trying to refer to a field in macro-generated docs, not knowing if a method might be defined as well. Obviously, there are definitely other uses. In the case where it's not disambiguated, methods (and I suppose other associated items in the value namespace) still take priority, which `@jyn514` said was an oversight but I think is probably the desired behavior 99% of the time anyway - shadowing a field with an accessor method is a very common pattern. If fields and methods with the same name started conflicting, it would be a breaking change. Though, to quote them: > jyn: maybe you can break this only if both [the method and the field] are public > jyn: rustc has some future-incompat warning level > jyn: that gets through -A warnings and --cap-lints from cargo That'd be out of scope of this PR, though. Fixes #80283
This commit is contained in:
commit
f79ef02e4b
8 changed files with 138 additions and 66 deletions
|
@ -1,6 +1,8 @@
|
|||
#![deny(rustdoc::broken_intra_doc_links)]
|
||||
//~^ NOTE lint level is defined
|
||||
pub enum S {}
|
||||
pub enum S {
|
||||
A,
|
||||
}
|
||||
fn S() {}
|
||||
|
||||
#[macro_export]
|
||||
|
@ -13,6 +15,10 @@ const c: usize = 0;
|
|||
|
||||
trait T {}
|
||||
|
||||
struct X {
|
||||
y: usize,
|
||||
}
|
||||
|
||||
/// Link to [struct@S]
|
||||
//~^ ERROR incompatible link kind for `S`
|
||||
//~| NOTE this link resolved
|
||||
|
@ -78,4 +84,14 @@ trait T {}
|
|||
//~^ ERROR unresolved link to `std`
|
||||
//~| NOTE this link resolves to the crate `std`
|
||||
//~| HELP to link to the crate, prefix with `mod@`
|
||||
|
||||
/// Link to [method@X::y]
|
||||
//~^ ERROR incompatible link kind for `X::y`
|
||||
//~| NOTE this link resolved
|
||||
//~| HELP prefix with `field@`
|
||||
|
||||
/// Link to [field@S::A]
|
||||
//~^ ERROR incompatible link kind for `S::A`
|
||||
//~| NOTE this link resolved
|
||||
//~| HELP prefix with `variant@`
|
||||
pub fn f() {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: incompatible link kind for `S`
|
||||
--> $DIR/disambiguator-mismatch.rs:16:14
|
||||
--> $DIR/disambiguator-mismatch.rs:22:14
|
||||
|
|
||||
LL | /// Link to [struct@S]
|
||||
| ^^^^^^^^ this link resolved to an enum, which is not a struct
|
||||
|
@ -15,7 +15,7 @@ LL | /// Link to [enum@S]
|
|||
| ~~~~~
|
||||
|
||||
error: incompatible link kind for `S`
|
||||
--> $DIR/disambiguator-mismatch.rs:21:14
|
||||
--> $DIR/disambiguator-mismatch.rs:27:14
|
||||
|
|
||||
LL | /// Link to [mod@S]
|
||||
| ^^^^^ this link resolved to an enum, which is not a module
|
||||
|
@ -26,7 +26,7 @@ LL | /// Link to [enum@S]
|
|||
| ~~~~~
|
||||
|
||||
error: incompatible link kind for `S`
|
||||
--> $DIR/disambiguator-mismatch.rs:26:14
|
||||
--> $DIR/disambiguator-mismatch.rs:32:14
|
||||
|
|
||||
LL | /// Link to [union@S]
|
||||
| ^^^^^^^ this link resolved to an enum, which is not a union
|
||||
|
@ -37,7 +37,7 @@ LL | /// Link to [enum@S]
|
|||
| ~~~~~
|
||||
|
||||
error: incompatible link kind for `S`
|
||||
--> $DIR/disambiguator-mismatch.rs:31:14
|
||||
--> $DIR/disambiguator-mismatch.rs:37:14
|
||||
|
|
||||
LL | /// Link to [trait@S]
|
||||
| ^^^^^^^ this link resolved to an enum, which is not a trait
|
||||
|
@ -48,7 +48,7 @@ LL | /// Link to [enum@S]
|
|||
| ~~~~~
|
||||
|
||||
error: incompatible link kind for `T`
|
||||
--> $DIR/disambiguator-mismatch.rs:36:14
|
||||
--> $DIR/disambiguator-mismatch.rs:42:14
|
||||
|
|
||||
LL | /// Link to [struct@T]
|
||||
| ^^^^^^^^ this link resolved to a trait, which is not a struct
|
||||
|
@ -59,7 +59,7 @@ LL | /// Link to [trait@T]
|
|||
| ~~~~~~
|
||||
|
||||
error: incompatible link kind for `m`
|
||||
--> $DIR/disambiguator-mismatch.rs:41:14
|
||||
--> $DIR/disambiguator-mismatch.rs:47:14
|
||||
|
|
||||
LL | /// Link to [derive@m]
|
||||
| ^^^^^^^^ this link resolved to a macro, which is not a derive macro
|
||||
|
@ -71,7 +71,7 @@ LL + /// Link to [m!]
|
|||
|
|
||||
|
||||
error: unresolved link to `m`
|
||||
--> $DIR/disambiguator-mismatch.rs:46:14
|
||||
--> $DIR/disambiguator-mismatch.rs:52:14
|
||||
|
|
||||
LL | /// Link to [m()]
|
||||
| ^^^ this link resolves to the macro `m`, which is not in the value namespace
|
||||
|
@ -82,7 +82,7 @@ LL | /// Link to [m!()]
|
|||
| +
|
||||
|
||||
error: incompatible link kind for `s`
|
||||
--> $DIR/disambiguator-mismatch.rs:52:14
|
||||
--> $DIR/disambiguator-mismatch.rs:58:14
|
||||
|
|
||||
LL | /// Link to [const@s]
|
||||
| ^^^^^^^ this link resolved to a static, which is not a constant
|
||||
|
@ -93,7 +93,7 @@ LL | /// Link to [static@s]
|
|||
| ~~~~~~~
|
||||
|
||||
error: incompatible link kind for `c`
|
||||
--> $DIR/disambiguator-mismatch.rs:57:14
|
||||
--> $DIR/disambiguator-mismatch.rs:63:14
|
||||
|
|
||||
LL | /// Link to [static@c]
|
||||
| ^^^^^^^^ this link resolved to a constant, which is not a static
|
||||
|
@ -104,7 +104,7 @@ LL | /// Link to [const@c]
|
|||
| ~~~~~~
|
||||
|
||||
error: incompatible link kind for `c`
|
||||
--> $DIR/disambiguator-mismatch.rs:62:14
|
||||
--> $DIR/disambiguator-mismatch.rs:68:14
|
||||
|
|
||||
LL | /// Link to [fn@c]
|
||||
| ^^^^ this link resolved to a constant, which is not a function
|
||||
|
@ -115,7 +115,7 @@ LL | /// Link to [const@c]
|
|||
| ~~~~~~
|
||||
|
||||
error: incompatible link kind for `c`
|
||||
--> $DIR/disambiguator-mismatch.rs:67:14
|
||||
--> $DIR/disambiguator-mismatch.rs:73:14
|
||||
|
|
||||
LL | /// Link to [c()]
|
||||
| ^^^ this link resolved to a constant, which is not a function
|
||||
|
@ -127,7 +127,7 @@ LL + /// Link to [const@c]
|
|||
|
|
||||
|
||||
error: incompatible link kind for `f`
|
||||
--> $DIR/disambiguator-mismatch.rs:72:14
|
||||
--> $DIR/disambiguator-mismatch.rs:78:14
|
||||
|
|
||||
LL | /// Link to [const@f]
|
||||
| ^^^^^^^ this link resolved to a function, which is not a constant
|
||||
|
@ -139,7 +139,7 @@ LL + /// Link to [f()]
|
|||
|
|
||||
|
||||
error: unresolved link to `std`
|
||||
--> $DIR/disambiguator-mismatch.rs:77:14
|
||||
--> $DIR/disambiguator-mismatch.rs:83:14
|
||||
|
|
||||
LL | /// Link to [fn@std]
|
||||
| ^^^^^^ this link resolves to the crate `std`, which is not in the value namespace
|
||||
|
@ -149,5 +149,27 @@ help: to link to the crate, prefix with `mod@`
|
|||
LL | /// Link to [mod@std]
|
||||
| ~~~~
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: incompatible link kind for `X::y`
|
||||
--> $DIR/disambiguator-mismatch.rs:88:14
|
||||
|
|
||||
LL | /// Link to [method@X::y]
|
||||
| ^^^^^^^^^^^ this link resolved to a field, which is not a function
|
||||
|
|
||||
help: to link to the field, prefix with `field@`
|
||||
|
|
||||
LL | /// Link to [field@X::y]
|
||||
| ~~~~~~
|
||||
|
||||
error: incompatible link kind for `S::A`
|
||||
--> $DIR/disambiguator-mismatch.rs:93:14
|
||||
|
|
||||
LL | /// Link to [field@S::A]
|
||||
| ^^^^^^^^^^ this link resolved to a unit variant, which is not a field
|
||||
|
|
||||
help: to link to the unit variant, prefix with `variant@`
|
||||
|
|
||||
LL | /// Link to [variant@S::A]
|
||||
| ~~~~~~~~
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
/// [`Foo::bar`]
|
||||
/// [`Foo::bar()`]
|
||||
//~^ERROR incompatible link kind for `Foo::bar`
|
||||
//~|HELP to link to the field, remove the disambiguator
|
||||
//~|HELP to link to the field, prefix with `field@`
|
||||
//~|NOTE this link resolved to a field, which is not a function
|
||||
pub struct Foo {
|
||||
pub bar: u8
|
||||
pub bar: u8,
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@ note: the lint level is defined here
|
|||
|
|
||||
LL | #![deny(rustdoc::broken_intra_doc_links)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: to link to the field, remove the disambiguator
|
||||
help: to link to the field, prefix with `field@`
|
||||
|
|
||||
LL - /// [`Foo::bar()`]
|
||||
LL + /// [`field@Foo::bar`]
|
||||
|
|
||||
LL | /// [`Foo::bar`]
|
||||
| ~~~~~~~~
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
@ -43,10 +43,10 @@ help: to link to the associated function, add parentheses
|
|||
|
|
||||
LL | /// [`Self::IDENT()`]
|
||||
| ++
|
||||
help: to link to the variant, prefix with `type@`
|
||||
help: to link to the variant, prefix with `variant@`
|
||||
|
|
||||
LL | /// [`type@Self::IDENT`]
|
||||
| +++++
|
||||
LL | /// [`variant@Self::IDENT`]
|
||||
| ++++++++
|
||||
|
||||
error: `Self::IDENT2` is both an associated constant and an associated type
|
||||
--> $DIR/issue-108653-associated-items.rs:30:7
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue