@@ -1024,12 +1024,18 @@ impl LinkCollector<'_, '_> {
1024
1024
1025
1025
let resolved_self;
1026
1026
// replace `Self` with suitable item's parent name
1027
- if path_str. starts_with ( "Self::" ) {
1027
+ let is_lone_self = path_str == "Self" ;
1028
+ let is_lone_crate = path_str == "crate" ;
1029
+ if path_str. starts_with ( "Self::" ) || is_lone_self {
1028
1030
if let Some ( ref name) = self_name {
1029
- resolved_self = format ! ( "{}::{}" , name, & path_str[ 6 ..] ) ;
1030
- path_str = & resolved_self;
1031
+ if is_lone_self {
1032
+ path_str = name;
1033
+ } else {
1034
+ resolved_self = format ! ( "{}::{}" , name, & path_str[ 6 ..] ) ;
1035
+ path_str = & resolved_self;
1036
+ }
1031
1037
}
1032
- } else if path_str. starts_with ( "crate::" ) {
1038
+ } else if path_str. starts_with ( "crate::" ) || is_lone_crate {
1033
1039
use rustc_span:: def_id:: CRATE_DEF_INDEX ;
1034
1040
1035
1041
// HACK(jynelson): rustc_resolve thinks that `crate` is the crate currently being documented.
@@ -1038,8 +1044,12 @@ impl LinkCollector<'_, '_> {
1038
1044
// HACK(jynelson)(2): If we just strip `crate::` then suddenly primitives become ambiguous
1039
1045
// (consider `crate::char`). Instead, change it to `self::`. This works because 'self' is now the crate root.
1040
1046
// FIXME(#78696): This doesn't always work.
1041
- resolved_self = format ! ( "self::{}" , & path_str[ "crate::" . len( ) ..] ) ;
1042
- path_str = & resolved_self;
1047
+ if is_lone_crate {
1048
+ path_str = "self" ;
1049
+ } else {
1050
+ resolved_self = format ! ( "self::{}" , & path_str[ "crate::" . len( ) ..] ) ;
1051
+ path_str = & resolved_self;
1052
+ }
1043
1053
module_id = DefId { krate, index : CRATE_DEF_INDEX } ;
1044
1054
}
1045
1055
0 commit comments