Skip to content

Commit 2dad90d

Browse files
committed
Suggest f() for functions and add a test case
1 parent fc273a0 commit 2dad90d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ impl Disambiguator {
893893
fn display_for(kind: DefKind, path_str: &str) -> String {
894894
if kind == DefKind::Macro(MacroKind::Bang) {
895895
return format!("{}!", path_str);
896+
} else if kind == DefKind::Fn || kind == DefKind::AssocFn {
897+
return format!("{}()", path_str);
896898
}
897899
let prefix = match kind {
898900
DefKind::Struct => "struct",
@@ -904,7 +906,6 @@ impl Disambiguator {
904906
"const"
905907
}
906908
DefKind::Static => "static",
907-
DefKind::Fn | DefKind::AssocFn => "fn",
908909
DefKind::Macro(MacroKind::Derive) => "derive",
909910
// Now handle things that don't have a specific disambiguator
910911
_ => match kind

src/test/rustdoc-ui/intra-links-disambiguator-mismatch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ trait T {}
6060
//~^ ERROR incompatible link kind for `c`
6161
//~| NOTE this link resolved
6262
//~| HELP use its disambiguator
63+
64+
/// Link to [const@f]
65+
//~^ ERROR incompatible link kind for `f`
66+
//~| NOTE this link resolved
67+
//~| HELP use its disambiguator
6368
pub fn f() {}

src/test/rustdoc-ui/intra-links-disambiguator-mismatch.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,13 @@ LL | /// Link to [c()]
8383
|
8484
= note: this link resolved to a constant, which is not a function
8585

86-
error: aborting due to 10 previous errors
86+
error: incompatible link kind for `f`
87+
--> $DIR/intra-links-disambiguator-mismatch.rs:64:14
88+
|
89+
LL | /// Link to [const@f]
90+
| ^^^^^^^ help: to link to the function, use its disambiguator: `f()`
91+
|
92+
= note: this link resolved to a function, which is not a constant
93+
94+
error: aborting due to 11 previous errors
8795

0 commit comments

Comments
 (0)