@@ -9,7 +9,7 @@ use rustc_hir::def::{
9
9
Namespace :: { self , * } ,
10
10
PerNS ,
11
11
} ;
12
- use rustc_hir:: def_id:: { CrateNum , DefId , CRATE_DEF_ID } ;
12
+ use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID } ;
13
13
use rustc_hir:: Mutability ;
14
14
use rustc_middle:: ty:: { DefIdTree , Ty , TyCtxt } ;
15
15
use rustc_middle:: { bug, span_bug, ty} ;
@@ -1043,16 +1043,11 @@ impl<'a, 'tcx> DocVisitor for LinkCollector<'a, 'tcx> {
1043
1043
// so we know which module it came from.
1044
1044
for ( parent_module, doc) in item. attrs . collapsed_doc_value_by_module_level ( ) {
1045
1045
debug ! ( "combined_docs={}" , doc) ;
1046
-
1047
- let ( krate, parent_node) = if let Some ( id) = parent_module {
1048
- ( id. krate , Some ( id) )
1049
- } else {
1050
- ( item. def_id . krate ( ) , parent_node)
1051
- } ;
1052
1046
// NOTE: if there are links that start in one crate and end in another, this will not resolve them.
1053
1047
// This is a degenerate case and it's not supported by rustdoc.
1048
+ let parent_node = parent_module. or ( parent_node) ;
1054
1049
for md_link in markdown_links ( & doc) {
1055
- let link = self . resolve_link ( & item, & doc, parent_node, krate , md_link) ;
1050
+ let link = self . resolve_link ( & item, & doc, parent_node, md_link) ;
1056
1051
if let Some ( link) = link {
1057
1052
self . cx . cache . intra_doc_links . entry ( item. def_id ) . or_default ( ) . push ( link) ;
1058
1053
}
@@ -1187,7 +1182,6 @@ impl LinkCollector<'_, '_> {
1187
1182
item : & Item ,
1188
1183
dox : & str ,
1189
1184
parent_node : Option < DefId > ,
1190
- krate : CrateNum ,
1191
1185
ori_link : MarkdownLink ,
1192
1186
) -> Option < ItemLink > {
1193
1187
trace ! ( "considering link '{}'" , ori_link. link) ;
@@ -1199,7 +1193,7 @@ impl LinkCollector<'_, '_> {
1199
1193
link_range : ori_link. range . clone ( ) ,
1200
1194
} ;
1201
1195
1202
- let PreprocessingInfo { path_str, disambiguator, extra_fragment, link_text } =
1196
+ let PreprocessingInfo { ref path_str, disambiguator, extra_fragment, link_text } =
1203
1197
match preprocess_link ( & ori_link) ? {
1204
1198
Ok ( x) => x,
1205
1199
Err ( err) => {
@@ -1221,7 +1215,6 @@ impl LinkCollector<'_, '_> {
1221
1215
return None ;
1222
1216
}
1223
1217
} ;
1224
- let mut path_str = & * path_str;
1225
1218
1226
1219
let inner_docs = item. inner_docs ( self . cx . tcx ) ;
1227
1220
@@ -1239,7 +1232,7 @@ impl LinkCollector<'_, '_> {
1239
1232
let base_node =
1240
1233
if item. is_mod ( ) && inner_docs { self . mod_ids . last ( ) . copied ( ) } else { parent_node } ;
1241
1234
1242
- let Some ( mut module_id) = base_node else {
1235
+ let Some ( module_id) = base_node else {
1243
1236
// This is a bug.
1244
1237
debug ! ( "attempting to resolve item without parent module: {}" , path_str) ;
1245
1238
resolution_failure (
@@ -1252,26 +1245,6 @@ impl LinkCollector<'_, '_> {
1252
1245
return None ;
1253
1246
} ;
1254
1247
1255
- let resolved_self;
1256
- let is_lone_crate = path_str == "crate" ;
1257
- if path_str. starts_with ( "crate::" ) || is_lone_crate {
1258
- use rustc_span:: def_id:: CRATE_DEF_INDEX ;
1259
-
1260
- // HACK(jynelson): rustc_resolve thinks that `crate` is the crate currently being documented.
1261
- // But rustdoc wants it to mean the crate this item was originally present in.
1262
- // To work around this, remove it and resolve relative to the crate root instead.
1263
- // HACK(jynelson)(2): If we just strip `crate::` then suddenly primitives become ambiguous
1264
- // (consider `crate::char`). Instead, change it to `self::`. This works because 'self' is now the crate root.
1265
- // FIXME(#78696): This doesn't always work.
1266
- if is_lone_crate {
1267
- path_str = "self" ;
1268
- } else {
1269
- resolved_self = format ! ( "self::{}" , & path_str[ "crate::" . len( ) ..] ) ;
1270
- path_str = & resolved_self;
1271
- }
1272
- module_id = DefId { krate, index : CRATE_DEF_INDEX } ;
1273
- }
1274
-
1275
1248
let ( mut res, fragment) = self . resolve_with_disambiguator_cached (
1276
1249
ResolutionInfo {
1277
1250
item_id : item. def_id ,
0 commit comments