@@ -17,10 +17,10 @@ use rustc_abi::ExternAbi;
1717use rustc_ast:: join_path_syms;
1818use rustc_data_structures:: fx:: FxHashSet ;
1919use rustc_hir as hir;
20- use rustc_hir:: def:: DefKind ;
20+ use rustc_hir:: def:: { DefKind , MacroKinds } ;
2121use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
2222use rustc_hir:: { ConstStability , StabilityLevel , StableSince } ;
23- use rustc_metadata:: creader:: { CStore , LoadedMacro } ;
23+ use rustc_metadata:: creader:: CStore ;
2424use rustc_middle:: ty:: { self , TyCtxt , TypingMode } ;
2525use rustc_span:: symbol:: kw;
2626use rustc_span:: { Symbol , sym} ;
@@ -360,36 +360,33 @@ fn generate_macro_def_id_path(
360360 let crate_name = tcx. crate_name ( def_id. krate ) ;
361361 let cache = cx. cache ( ) ;
362362
363- let fqp = clean:: inline:: item_relative_path ( tcx, def_id) ;
364- let mut relative = fqp. iter ( ) . copied ( ) ;
365363 let cstore = CStore :: from_tcx ( tcx) ;
366364 // We need this to prevent a `panic` when this function is used from intra doc links...
367365 if !cstore. has_crate_data ( def_id. krate ) {
368366 debug ! ( "No data for crate {crate_name}" ) ;
369367 return Err ( HrefError :: NotInExternalCache ) ;
370368 }
371- // Check to see if it is a macro 2.0 or built-in macro.
372- // More information in <https://rust-lang.github.io/rfcs/1584-macros.html>.
373- let is_macro_2 = match cstore. load_macro_untracked ( def_id, tcx) {
374- // If `def.macro_rules` is `true`, then it's not a macro 2.0.
375- LoadedMacro :: MacroDef { def, .. } => !def. macro_rules ,
376- _ => false ,
369+ let DefKind :: Macro ( kinds) = tcx. def_kind ( def_id) else {
370+ unreachable ! ( ) ;
377371 } ;
378-
379- let mut path = if is_macro_2 {
380- once ( crate_name) . chain ( relative) . collect ( )
372+ let item_type = if kinds == MacroKinds :: DERIVE {
373+ ItemType :: ProcDerive
374+ } else if kinds == MacroKinds :: ATTR {
375+ ItemType :: ProcAttribute
381376 } else {
382- vec ! [ crate_name , relative . next_back ( ) . unwrap ( ) ]
377+ ItemType :: Macro
383378 } ;
379+ let mut path = clean:: inline:: get_item_path ( tcx, def_id, item_type) ;
384380 if path. len ( ) < 2 {
385381 // The minimum we can have is the crate name followed by the macro name. If shorter, then
386382 // it means that `relative` was empty, which is an error.
387383 debug ! ( "macro path cannot be empty!" ) ;
388384 return Err ( HrefError :: NotInExternalCache ) ;
389385 }
390386
387+ let fqp = path. clone ( ) ;
391388 if let Some ( last) = path. last_mut ( ) {
392- * last = Symbol :: intern ( & format ! ( "macro .{last}.html" ) ) ;
389+ * last = Symbol :: intern ( & format ! ( "{} .{last}.html" , item_type . as_str ( ) ) ) ;
393390 }
394391
395392 let url = match cache. extern_locations [ & def_id. krate ] {
@@ -410,7 +407,7 @@ fn generate_macro_def_id_path(
410407 return Err ( HrefError :: NotInExternalCache ) ;
411408 }
412409 } ;
413- Ok ( ( url, ItemType :: Macro , fqp) )
410+ Ok ( ( url, item_type , fqp) )
414411}
415412
416413fn generate_item_def_id_path (
0 commit comments