@@ -951,9 +951,9 @@ fn preprocess_link<'a>(
951
951
}
952
952
953
953
// Parse and strip the disambiguator from the link, if present.
954
- let ( path_str, disambiguator) = match Disambiguator :: from_str ( & link) {
955
- Ok ( Some ( ( d, path) ) ) => ( path. trim ( ) , Some ( d) ) ,
956
- Ok ( None ) => ( link. trim ( ) , None ) ,
954
+ let ( link_text , path_str, disambiguator) = match Disambiguator :: from_str ( & link) {
955
+ Ok ( Some ( ( d, path, link_text ) ) ) => ( link_text . trim ( ) , path. trim ( ) , Some ( d) ) ,
956
+ Ok ( None ) => ( link. trim ( ) , link . trim ( ) , None ) ,
957
957
Err ( ( err_msg, relative_range) ) => {
958
958
// Only report error if we would not have ignored this link. See issue #83859.
959
959
if !should_ignore_link_with_disambiguators ( link) {
@@ -971,11 +971,6 @@ fn preprocess_link<'a>(
971
971
return None ;
972
972
}
973
973
974
- // We stripped `()` and `!` when parsing the disambiguator.
975
- // Add them back to be displayed, but not prefix disambiguators.
976
- let link_text =
977
- disambiguator. map ( |d| d. display_for ( path_str) ) . unwrap_or_else ( || path_str. to_owned ( ) ) ;
978
-
979
974
// Strip generics from the path.
980
975
let path_str = if path_str. contains ( [ '<' , '>' ] . as_slice ( ) ) {
981
976
match strip_generics_from_path ( & path_str) {
@@ -1005,7 +1000,7 @@ fn preprocess_link<'a>(
1005
1000
path_str,
1006
1001
disambiguator,
1007
1002
extra_fragment : extra_fragment. map ( String :: from) ,
1008
- link_text,
1003
+ link_text : link_text . to_owned ( ) ,
1009
1004
} ) )
1010
1005
}
1011
1006
@@ -1513,24 +1508,12 @@ enum Disambiguator {
1513
1508
}
1514
1509
1515
1510
impl Disambiguator {
1516
- /// The text that should be displayed when the path is rendered as HTML.
1517
- ///
1518
- /// NOTE: `path` is not the original link given by the user, but a name suitable for passing to `resolve`.
1519
- fn display_for ( & self , path : & str ) -> String {
1520
- match self {
1521
- // FIXME: this will have different output if the user had `m!()` originally.
1522
- Self :: Kind ( DefKind :: Macro ( MacroKind :: Bang ) ) => format ! ( "{}!" , path) ,
1523
- Self :: Kind ( DefKind :: Fn ) => format ! ( "{}()" , path) ,
1524
- _ => path. to_owned ( ) ,
1525
- }
1526
- }
1527
-
1528
- /// Given a link, parse and return `(disambiguator, path_str)`.
1511
+ /// Given a link, parse and return `(disambiguator, path_str, link_text)`.
1529
1512
///
1530
1513
/// This returns `Ok(Some(...))` if a disambiguator was found,
1531
1514
/// `Ok(None)` if no disambiguator was found, or `Err(...)`
1532
1515
/// if there was a problem with the disambiguator.
1533
- fn from_str ( link : & str ) -> Result < Option < ( Self , & str ) > , ( String , Range < usize > ) > {
1516
+ fn from_str ( link : & str ) -> Result < Option < ( Self , & str , & str ) > , ( String , Range < usize > ) > {
1534
1517
use Disambiguator :: { Kind , Namespace as NS , Primitive } ;
1535
1518
1536
1519
if let Some ( idx) = link. find ( '@' ) {
@@ -1551,18 +1534,18 @@ impl Disambiguator {
1551
1534
"prim" | "primitive" => Primitive ,
1552
1535
_ => return Err ( ( format ! ( "unknown disambiguator `{}`" , prefix) , 0 ..idx) ) ,
1553
1536
} ;
1554
- Ok ( Some ( ( d, & rest[ 1 ..] ) ) )
1537
+ Ok ( Some ( ( d, & rest[ 1 ..] , & rest [ 1 .. ] ) ) )
1555
1538
} else {
1556
1539
let suffixes = [
1557
1540
( "!()" , DefKind :: Macro ( MacroKind :: Bang ) ) ,
1558
1541
( "()" , DefKind :: Fn ) ,
1559
1542
( "!" , DefKind :: Macro ( MacroKind :: Bang ) ) ,
1560
1543
] ;
1561
1544
for ( suffix, kind) in suffixes {
1562
- if let Some ( link ) = link. strip_suffix ( suffix) {
1545
+ if let Some ( path_str ) = link. strip_suffix ( suffix) {
1563
1546
// Avoid turning `!` or `()` into an empty string
1564
- if !link . is_empty ( ) {
1565
- return Ok ( Some ( ( Kind ( kind) , link) ) ) ;
1547
+ if !path_str . is_empty ( ) {
1548
+ return Ok ( Some ( ( Kind ( kind) , path_str , link) ) ) ;
1566
1549
}
1567
1550
}
1568
1551
}
0 commit comments