@@ -9,7 +9,7 @@ use rustc_hir::def::{
99 Namespace :: { self , * } ,
1010 PerNS ,
1111} ;
12- use rustc_hir:: def_id:: { CrateNum , DefId , CRATE_DEF_ID } ;
12+ use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID } ;
1313use rustc_hir:: Mutability ;
1414use rustc_middle:: ty:: { DefIdTree , Ty , TyCtxt } ;
1515use rustc_middle:: { bug, span_bug, ty} ;
@@ -1043,16 +1043,11 @@ impl<'a, 'tcx> DocVisitor for LinkCollector<'a, 'tcx> {
10431043 // so we know which module it came from.
10441044 for ( parent_module, doc) in item. attrs . collapsed_doc_value_by_module_level ( ) {
10451045 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- } ;
10521046 // NOTE: if there are links that start in one crate and end in another, this will not resolve them.
10531047 // This is a degenerate case and it's not supported by rustdoc.
1048+ let parent_node = parent_module. or ( parent_node) ;
10541049 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) ;
10561051 if let Some ( link) = link {
10571052 self . cx . cache . intra_doc_links . entry ( item. def_id ) . or_default ( ) . push ( link) ;
10581053 }
@@ -1187,7 +1182,6 @@ impl LinkCollector<'_, '_> {
11871182 item : & Item ,
11881183 dox : & str ,
11891184 parent_node : Option < DefId > ,
1190- krate : CrateNum ,
11911185 ori_link : MarkdownLink ,
11921186 ) -> Option < ItemLink > {
11931187 trace ! ( "considering link '{}'" , ori_link. link) ;
@@ -1199,7 +1193,7 @@ impl LinkCollector<'_, '_> {
11991193 link_range : ori_link. range . clone ( ) ,
12001194 } ;
12011195
1202- let PreprocessingInfo { path_str, disambiguator, extra_fragment, link_text } =
1196+ let PreprocessingInfo { ref path_str, disambiguator, extra_fragment, link_text } =
12031197 match preprocess_link ( & ori_link) ? {
12041198 Ok ( x) => x,
12051199 Err ( err) => {
@@ -1221,7 +1215,6 @@ impl LinkCollector<'_, '_> {
12211215 return None ;
12221216 }
12231217 } ;
1224- let mut path_str = & * path_str;
12251218
12261219 let inner_docs = item. inner_docs ( self . cx . tcx ) ;
12271220
@@ -1239,7 +1232,7 @@ impl LinkCollector<'_, '_> {
12391232 let base_node =
12401233 if item. is_mod ( ) && inner_docs { self . mod_ids . last ( ) . copied ( ) } else { parent_node } ;
12411234
1242- let Some ( mut module_id) = base_node else {
1235+ let Some ( module_id) = base_node else {
12431236 // This is a bug.
12441237 debug ! ( "attempting to resolve item without parent module: {}" , path_str) ;
12451238 resolution_failure (
@@ -1252,26 +1245,6 @@ impl LinkCollector<'_, '_> {
12521245 return None ;
12531246 } ;
12541247
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-
12751248 let ( mut res, fragment) = self . resolve_with_disambiguator_cached (
12761249 ResolutionInfo {
12771250 item_id : item. def_id ,
0 commit comments