@@ -1015,8 +1015,8 @@ impl LinkCollector<'_, '_> {
1015
1015
res = prim;
1016
1016
} else {
1017
1017
// `[char]` when a `char` module is in scope
1018
- let candidates = vec ! [ ( res, res. def_id( self . cx. tcx) ) , ( prim, None ) ] ;
1019
- ambiguity_error ( self . cx , & diag_info, path_str, & candidates) ;
1018
+ let candidates = & [ ( res, res. def_id ( self . cx . tcx ) ) , ( prim, None ) ] ;
1019
+ ambiguity_error ( self . cx , & diag_info, path_str, candidates) ;
1020
1020
return None ;
1021
1021
}
1022
1022
}
@@ -1206,6 +1206,10 @@ impl LinkCollector<'_, '_> {
1206
1206
}
1207
1207
}
1208
1208
1209
+ // If there are multiple items with the same "kind" (for example, both "associated types")
1210
+ // and after removing duplicated kinds, only one remains, the `ambiguity_error` function
1211
+ // won't emit an error. So at this point, we can just take the first candidate as it was
1212
+ // the first retrieved and use it to generate the link.
1209
1213
if candidates. len ( ) > 1 && !ambiguity_error ( self . cx , & diag, & key. path_str , & candidates) {
1210
1214
candidates = vec ! [ candidates[ 0 ] ] ;
1211
1215
}
@@ -1901,29 +1905,31 @@ fn report_malformed_generics(
1901
1905
/// Report an ambiguity error, where there were multiple possible resolutions.
1902
1906
///
1903
1907
/// If all `candidates` have the same kind, it's not possible to disambiguate so in this case,
1904
- /// the function returns `false`. Otherwise, it'll emit the error and return `true`.
1908
+ /// the function won't emit an error and will return `false`. Otherwise, it'll emit the error and
1909
+ /// return `true`.
1905
1910
fn ambiguity_error (
1906
1911
cx : & DocContext < ' _ > ,
1907
1912
diag_info : & DiagnosticInfo < ' _ > ,
1908
1913
path_str : & str ,
1909
1914
candidates : & [ ( Res , Option < DefId > ) ] ,
1910
1915
) -> bool {
1911
- let mut msg = format ! ( "`{}` is " , path_str ) ;
1916
+ let mut descrs = FxHashSet :: default ( ) ;
1912
1917
let kinds = candidates
1913
1918
. iter ( )
1914
1919
. map (
1915
1920
|( res, def_id) | {
1916
1921
if let Some ( def_id) = def_id { Res :: from_def_id ( cx. tcx , * def_id) } else { * res }
1917
1922
} ,
1918
1923
)
1924
+ . filter ( |res| descrs. insert ( res. descr ( ) ) )
1919
1925
. collect :: < Vec < _ > > ( ) ;
1920
- let descrs = kinds. iter ( ) . map ( |res| res. descr ( ) ) . collect :: < FxHashSet < & ' static str > > ( ) ;
1921
1926
if descrs. len ( ) == 1 {
1922
1927
// There is no way for users to disambiguate at this point, so better return the first
1923
1928
// candidate and not show a warning.
1924
1929
return false ;
1925
1930
}
1926
1931
1932
+ let mut msg = format ! ( "`{}` is " , path_str) ;
1927
1933
match kinds. as_slice ( ) {
1928
1934
[ res1, res2] => {
1929
1935
msg += & format ! (
0 commit comments