diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2021-07-12 19:04:51 +0800 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2021-07-12 19:48:07 +0800 |
| commit | 3dab2d210f284ae9dcb6af657290b9e0a902c4bb (patch) | |
| tree | bbf232ff5427ae770f91730c7e7cce44bc3cc00e | |
| parent | e97c29bda238cf55ddd7eec772deb823364b1846 (diff) | |
| download | rust-3dab2d210f284ae9dcb6af657290b9e0a902c4bb.tar.gz rust-3dab2d210f284ae9dcb6af657290b9e0a902c4bb.zip | |
suggest removing disambiguator if linking to field
| -rw-r--r-- | src/librustdoc/passes/collect_intra_doc_links.rs | 6 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/intra-doc/field-ice.rs | 11 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/intra-doc/field-ice.stderr | 15 |
3 files changed, 32 insertions, 0 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 44a3faf6f7b..21bd3ebd21b 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1610,6 +1610,8 @@ impl Disambiguator { return Suggestion::Macro; } else if kind == DefKind::Fn || kind == DefKind::AssocFn { return Suggestion::Function; + } else if kind == DefKind::Field { + return Suggestion::RemoveDisambiguator; } let prefix = match kind { @@ -1674,6 +1676,8 @@ enum Suggestion { Function, /// `m!` Macro, + /// `foo` without any disambiguator + RemoveDisambiguator, } impl Suggestion { @@ -1682,6 +1686,7 @@ impl Suggestion { Self::Prefix(x) => format!("prefix with `{}@`", x).into(), Self::Function => "add parentheses".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::Function => format!("{}()", path_str), Self::Macro => format!("{}!", path_str), + Self::RemoveDisambiguator => path_str.into(), } } } diff --git a/src/test/rustdoc-ui/intra-doc/field-ice.rs b/src/test/rustdoc-ui/intra-doc/field-ice.rs new file mode 100644 index 00000000000..c5d501e38da --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/field-ice.rs @@ -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 +} diff --git a/src/test/rustdoc-ui/intra-doc/field-ice.stderr b/src/test/rustdoc-ui/intra-doc/field-ice.stderr new file mode 100644 index 00000000000..ccb05b84a72 --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/field-ice.stderr @@ -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 + |
