Skip to content

Commit

Permalink
Suggest f() for functions and add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Aug 6, 2020
1 parent fc273a0 commit 2dad90d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/librustdoc/passes/collect_intra_doc_links.rs
Expand Up @@ -893,6 +893,8 @@ impl Disambiguator {
fn display_for(kind: DefKind, path_str: &str) -> String {
if kind == DefKind::Macro(MacroKind::Bang) {
return format!("{}!", path_str);
} else if kind == DefKind::Fn || kind == DefKind::AssocFn {
return format!("{}()", path_str);
}
let prefix = match kind {
DefKind::Struct => "struct",
Expand All @@ -904,7 +906,6 @@ impl Disambiguator {
"const"
}
DefKind::Static => "static",
DefKind::Fn | DefKind::AssocFn => "fn",
DefKind::Macro(MacroKind::Derive) => "derive",
// Now handle things that don't have a specific disambiguator
_ => match kind
Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc-ui/intra-links-disambiguator-mismatch.rs
Expand Up @@ -60,4 +60,9 @@ trait T {}
//~^ ERROR incompatible link kind for `c`
//~| NOTE this link resolved
//~| HELP use its disambiguator

/// Link to [const@f]
//~^ ERROR incompatible link kind for `f`
//~| NOTE this link resolved
//~| HELP use its disambiguator
pub fn f() {}
10 changes: 9 additions & 1 deletion src/test/rustdoc-ui/intra-links-disambiguator-mismatch.stderr
Expand Up @@ -83,5 +83,13 @@ LL | /// Link to [c()]
|
= note: this link resolved to a constant, which is not a function

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

error: aborting due to 11 previous errors

0 comments on commit 2dad90d

Please sign in to comment.