@@ -973,10 +973,13 @@ impl LinkCollector<'_, '_> {
973
973
} ;
974
974
975
975
// Parse and strip the disambiguator from the link, if present.
976
- let ( mut path_str, disambiguator) = if let Ok ( ( d, path) ) = Disambiguator :: from_str ( & link) {
977
- ( path. trim ( ) , Some ( d) )
978
- } else {
979
- ( link. trim ( ) , None )
976
+ let ( mut path_str, disambiguator) = match Disambiguator :: from_str ( & link) {
977
+ Ok ( Some ( ( d, path) ) ) => ( path. trim ( ) , Some ( d) ) ,
978
+ Ok ( None ) => ( link. trim ( ) , None ) ,
979
+ Err ( err_msg) => {
980
+ disambiguator_error ( self . cx , & item, dox, ori_link. range , & err_msg) ;
981
+ return None ;
982
+ }
980
983
} ;
981
984
982
985
if path_str. contains ( |ch : char | !( ch. is_alphanumeric ( ) || ":_<>, !*&;" . contains ( ch) ) ) {
@@ -1514,8 +1517,12 @@ impl Disambiguator {
1514
1517
}
1515
1518
}
1516
1519
1517
- /// Given a link, parse and return `(disambiguator, path_str)`
1518
- fn from_str ( link : & str ) -> Result < ( Self , & str ) , ( ) > {
1520
+ /// Given a link, parse and return `(disambiguator, path_str)`.
1521
+ ///
1522
+ /// This returns `Ok(Some(...))` if a disambiguator was found,
1523
+ /// `Ok(None)` if no disambiguator was found, or `Err(...)`
1524
+ /// if there was a problem with the disambiguator.
1525
+ fn from_str ( link : & str ) -> Result < Option < ( Self , & str ) > , String > {
1519
1526
use Disambiguator :: { Kind , Namespace as NS , Primitive } ;
1520
1527
1521
1528
let find_suffix = || {
@@ -1528,11 +1535,11 @@ impl Disambiguator {
1528
1535
if let Some ( link) = link. strip_suffix ( suffix) {
1529
1536
// Avoid turning `!` or `()` into an empty string
1530
1537
if !link. is_empty ( ) {
1531
- return Ok ( ( Kind ( kind) , link) ) ;
1538
+ return Some ( ( Kind ( kind) , link) ) ;
1532
1539
}
1533
1540
}
1534
1541
}
1535
- Err ( ( ) )
1542
+ None
1536
1543
} ;
1537
1544
1538
1545
if let Some ( idx) = link. find ( '@' ) {
@@ -1551,11 +1558,11 @@ impl Disambiguator {
1551
1558
"value" => NS ( Namespace :: ValueNS ) ,
1552
1559
"macro" => NS ( Namespace :: MacroNS ) ,
1553
1560
"prim" | "primitive" => Primitive ,
1554
- _ => return find_suffix ( ) ,
1561
+ _ => return Err ( format ! ( "unknown disambiguator `{}`" , prefix ) ) ,
1555
1562
} ;
1556
- Ok ( ( d, & rest[ 1 ..] ) )
1563
+ Ok ( Some ( ( d, & rest[ 1 ..] ) ) )
1557
1564
} else {
1558
- find_suffix ( )
1565
+ Ok ( find_suffix ( ) )
1559
1566
}
1560
1567
}
1561
1568
@@ -1979,6 +1986,22 @@ fn anchor_failure(
1979
1986
} ) ;
1980
1987
}
1981
1988
1989
+ /// Report an error in the link disambiguator.
1990
+ fn disambiguator_error (
1991
+ cx : & DocContext < ' _ > ,
1992
+ item : & Item ,
1993
+ dox : & str ,
1994
+ link_range : Range < usize > ,
1995
+ msg : & str ,
1996
+ ) {
1997
+ report_diagnostic ( cx. tcx , BROKEN_INTRA_DOC_LINKS , msg, item, dox, & link_range, |diag, _sp| {
1998
+ diag. note (
1999
+ "the disambiguator is the part of the link before the `@` sign, \
2000
+ or a suffix such as `()` for functions",
2001
+ ) ;
2002
+ } ) ;
2003
+ }
2004
+
1982
2005
/// Report an ambiguity error, where there were multiple possible resolutions.
1983
2006
fn ambiguity_error (
1984
2007
cx : & DocContext < ' _ > ,
0 commit comments