Rollup merge of #87078 - fee1-dead:rustdoc, r=jyn514
Rustdoc: suggest removing disambiguator if linking to field This fixes #85615. `@rustbot` label T-rustdoc
This commit is contained in:
commit
15af98d070
3 changed files with 32 additions and 0 deletions
|
@ -1610,6 +1610,8 @@ impl Disambiguator {
|
||||||
return Suggestion::Macro;
|
return Suggestion::Macro;
|
||||||
} else if kind == DefKind::Fn || kind == DefKind::AssocFn {
|
} else if kind == DefKind::Fn || kind == DefKind::AssocFn {
|
||||||
return Suggestion::Function;
|
return Suggestion::Function;
|
||||||
|
} else if kind == DefKind::Field {
|
||||||
|
return Suggestion::RemoveDisambiguator;
|
||||||
}
|
}
|
||||||
|
|
||||||
let prefix = match kind {
|
let prefix = match kind {
|
||||||
|
@ -1674,6 +1676,8 @@ enum Suggestion {
|
||||||
Function,
|
Function,
|
||||||
/// `m!`
|
/// `m!`
|
||||||
Macro,
|
Macro,
|
||||||
|
/// `foo` without any disambiguator
|
||||||
|
RemoveDisambiguator,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Suggestion {
|
impl Suggestion {
|
||||||
|
@ -1682,6 +1686,7 @@ impl Suggestion {
|
||||||
Self::Prefix(x) => format!("prefix with `{}@`", x).into(),
|
Self::Prefix(x) => format!("prefix with `{}@`", x).into(),
|
||||||
Self::Function => "add parentheses".into(),
|
Self::Function => "add parentheses".into(),
|
||||||
Self::Macro => "add an exclamation mark".into(),
|
Self::Macro => "add an exclamation mark".into(),
|
||||||
|
Self::RemoveDisambiguator => "remove the disambiguator".into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1691,6 +1696,7 @@ impl Suggestion {
|
||||||
Self::Prefix(prefix) => format!("{}@{}", prefix, path_str),
|
Self::Prefix(prefix) => format!("{}@{}", prefix, path_str),
|
||||||
Self::Function => format!("{}()", path_str),
|
Self::Function => format!("{}()", path_str),
|
||||||
Self::Macro => format!("{}!", path_str),
|
Self::Macro => format!("{}!", path_str),
|
||||||
|
Self::RemoveDisambiguator => path_str.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/test/rustdoc-ui/intra-doc/field-ice.rs
Normal file
11
src/test/rustdoc-ui/intra-doc/field-ice.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#![deny(rustdoc::broken_intra_doc_links)]
|
||||||
|
//~^NOTE the lint level is defined here
|
||||||
|
|
||||||
|
/// [`Foo::bar`]
|
||||||
|
/// [`Foo::bar()`]
|
||||||
|
//~^ERROR incompatible link kind for `Foo::bar`
|
||||||
|
//~|HELP to link to the field, remove the disambiguator
|
||||||
|
//~|NOTE this link resolved to a field, which is not a function
|
||||||
|
pub struct Foo {
|
||||||
|
pub bar: u8
|
||||||
|
}
|
15
src/test/rustdoc-ui/intra-doc/field-ice.stderr
Normal file
15
src/test/rustdoc-ui/intra-doc/field-ice.stderr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
error: incompatible link kind for `Foo::bar`
|
||||||
|
--> $DIR/field-ice.rs:5:6
|
||||||
|
|
|
||||||
|
LL | /// [`Foo::bar()`]
|
||||||
|
| ^^^^^^^^^^^^ help: to link to the field, remove the disambiguator: ``Foo::bar``
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/field-ice.rs:1:9
|
||||||
|
|
|
||||||
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
= note: this link resolved to a field, which is not a function
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue