Skip to content

Commit 15af98d

Browse files
authored
Rollup merge of #87078 - fee1-dead:rustdoc, r=jyn514
Rustdoc: suggest removing disambiguator if linking to field This fixes #85615. `@rustbot` label T-rustdoc
2 parents 4eba19a + 3dab2d2 commit 15af98d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,8 @@ impl Disambiguator {
16101610
return Suggestion::Macro;
16111611
} else if kind == DefKind::Fn || kind == DefKind::AssocFn {
16121612
return Suggestion::Function;
1613+
} else if kind == DefKind::Field {
1614+
return Suggestion::RemoveDisambiguator;
16131615
}
16141616

16151617
let prefix = match kind {
@@ -1674,6 +1676,8 @@ enum Suggestion {
16741676
Function,
16751677
/// `m!`
16761678
Macro,
1679+
/// `foo` without any disambiguator
1680+
RemoveDisambiguator,
16771681
}
16781682

16791683
impl Suggestion {
@@ -1682,6 +1686,7 @@ impl Suggestion {
16821686
Self::Prefix(x) => format!("prefix with `{}@`", x).into(),
16831687
Self::Function => "add parentheses".into(),
16841688
Self::Macro => "add an exclamation mark".into(),
1689+
Self::RemoveDisambiguator => "remove the disambiguator".into(),
16851690
}
16861691
}
16871692

@@ -1691,6 +1696,7 @@ impl Suggestion {
16911696
Self::Prefix(prefix) => format!("{}@{}", prefix, path_str),
16921697
Self::Function => format!("{}()", path_str),
16931698
Self::Macro => format!("{}!", path_str),
1699+
Self::RemoveDisambiguator => path_str.into(),
16941700
}
16951701
}
16961702
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![deny(rustdoc::broken_intra_doc_links)]
2+
//~^NOTE the lint level is defined here
3+
4+
/// [`Foo::bar`]
5+
/// [`Foo::bar()`]
6+
//~^ERROR incompatible link kind for `Foo::bar`
7+
//~|HELP to link to the field, remove the disambiguator
8+
//~|NOTE this link resolved to a field, which is not a function
9+
pub struct Foo {
10+
pub bar: u8
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: incompatible link kind for `Foo::bar`
2+
--> $DIR/field-ice.rs:5:6
3+
|
4+
LL | /// [`Foo::bar()`]
5+
| ^^^^^^^^^^^^ help: to link to the field, remove the disambiguator: ``Foo::bar``
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/field-ice.rs:1:9
9+
|
10+
LL | #![deny(rustdoc::broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: this link resolved to a field, which is not a function
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)