@@ -992,9 +992,9 @@ fn preprocess_link<'a>(
992
992
}
993
993
994
994
// Parse and strip the disambiguator from the link, if present.
995
- let ( path_str, disambiguator ) = match Disambiguator :: from_str ( & link) {
996
- Ok ( Some ( ( d, path) ) ) => ( path. trim ( ) , Some ( d ) ) ,
997
- Ok ( None ) => ( link. trim ( ) , None ) ,
995
+ let ( disambiguator , path_str, link_text ) = match Disambiguator :: from_str ( & link) {
996
+ Ok ( Some ( ( d, path, link_text ) ) ) => ( Some ( d ) , path. trim ( ) , link_text . trim ( ) ) ,
997
+ Ok ( None ) => ( None , link. trim ( ) , link . trim ( ) ) ,
998
998
Err ( ( err_msg, relative_range) ) => {
999
999
// Only report error if we would not have ignored this link. See issue #83859.
1000
1000
if !should_ignore_link_with_disambiguators ( link) {
@@ -1012,11 +1012,6 @@ fn preprocess_link<'a>(
1012
1012
return None ;
1013
1013
}
1014
1014
1015
- // We stripped `()` and `!` when parsing the disambiguator.
1016
- // Add them back to be displayed, but not prefix disambiguators.
1017
- let link_text =
1018
- disambiguator. map ( |d| d. display_for ( path_str) ) . unwrap_or_else ( || path_str. to_owned ( ) ) ;
1019
-
1020
1015
// Strip generics from the path.
1021
1016
let path_str = if path_str. contains ( [ '<' , '>' ] . as_slice ( ) ) {
1022
1017
match strip_generics_from_path ( & path_str) {
@@ -1046,7 +1041,7 @@ fn preprocess_link<'a>(
1046
1041
path_str,
1047
1042
disambiguator,
1048
1043
extra_fragment : extra_fragment. map ( String :: from) ,
1049
- link_text,
1044
+ link_text : link_text . to_owned ( ) ,
1050
1045
} ) )
1051
1046
}
1052
1047
@@ -1554,24 +1549,12 @@ enum Disambiguator {
1554
1549
}
1555
1550
1556
1551
impl Disambiguator {
1557
- /// The text that should be displayed when the path is rendered as HTML.
1558
- ///
1559
- /// NOTE: `path` is not the original link given by the user, but a name suitable for passing to `resolve`.
1560
- fn display_for ( & self , path : & str ) -> String {
1561
- match self {
1562
- // FIXME: this will have different output if the user had `m!()` originally.
1563
- Self :: Kind ( DefKind :: Macro ( MacroKind :: Bang ) ) => format ! ( "{}!" , path) ,
1564
- Self :: Kind ( DefKind :: Fn ) => format ! ( "{}()" , path) ,
1565
- _ => path. to_owned ( ) ,
1566
- }
1567
- }
1568
-
1569
- /// Given a link, parse and return `(disambiguator, path_str)`.
1552
+ /// Given a link, parse and return `(disambiguator, path_str, link_text)`.
1570
1553
///
1571
1554
/// This returns `Ok(Some(...))` if a disambiguator was found,
1572
1555
/// `Ok(None)` if no disambiguator was found, or `Err(...)`
1573
1556
/// if there was a problem with the disambiguator.
1574
- fn from_str ( link : & str ) -> Result < Option < ( Self , & str ) > , ( String , Range < usize > ) > {
1557
+ fn from_str ( link : & str ) -> Result < Option < ( Self , & str , & str ) > , ( String , Range < usize > ) > {
1575
1558
use Disambiguator :: { Kind , Namespace as NS , Primitive } ;
1576
1559
1577
1560
if let Some ( idx) = link. find ( '@' ) {
@@ -1592,18 +1575,20 @@ impl Disambiguator {
1592
1575
"prim" | "primitive" => Primitive ,
1593
1576
_ => return Err ( ( format ! ( "unknown disambiguator `{}`" , prefix) , 0 ..idx) ) ,
1594
1577
} ;
1595
- Ok ( Some ( ( d, & rest[ 1 ..] ) ) )
1578
+ Ok ( Some ( ( d, & rest[ 1 ..] , & rest [ 1 .. ] ) ) )
1596
1579
} else {
1597
1580
let suffixes = [
1598
1581
( "!()" , DefKind :: Macro ( MacroKind :: Bang ) ) ,
1582
+ ( "!{}" , DefKind :: Macro ( MacroKind :: Bang ) ) ,
1583
+ ( "![]" , DefKind :: Macro ( MacroKind :: Bang ) ) ,
1599
1584
( "()" , DefKind :: Fn ) ,
1600
1585
( "!" , DefKind :: Macro ( MacroKind :: Bang ) ) ,
1601
1586
] ;
1602
1587
for ( suffix, kind) in suffixes {
1603
- if let Some ( link ) = link. strip_suffix ( suffix) {
1588
+ if let Some ( path_str ) = link. strip_suffix ( suffix) {
1604
1589
// Avoid turning `!` or `()` into an empty string
1605
- if !link . is_empty ( ) {
1606
- return Ok ( Some ( ( Kind ( kind) , link) ) ) ;
1590
+ if !path_str . is_empty ( ) {
1591
+ return Ok ( Some ( ( Kind ( kind) , path_str , link) ) ) ;
1607
1592
}
1608
1593
}
1609
1594
}
0 commit comments