@@ -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} ;
@@ -358,27 +358,23 @@ fn generate_macro_def_id_path(
358358 let crate_name = tcx. crate_name ( def_id. krate ) ;
359359 let cache = cx. cache ( ) ;
360360
361- let fqp = clean:: inline:: item_relative_path ( tcx, def_id) ;
362- let mut relative = fqp. iter ( ) . copied ( ) ;
363361 let cstore = CStore :: from_tcx ( tcx) ;
364362 // We need this to prevent a `panic` when this function is used from intra doc links...
365363 if !cstore. has_crate_data ( def_id. krate ) {
366364 debug ! ( "No data for crate {crate_name}" ) ;
367365 return Err ( HrefError :: NotInExternalCache ) ;
368366 }
369- // Check to see if it is a macro 2.0 or built-in macro.
370- // More information in <https://rust-lang.github.io/rfcs/1584-macros.html>.
371- let is_macro_2 = match cstore. load_macro_untracked ( def_id, tcx) {
372- // If `def.macro_rules` is `true`, then it's not a macro 2.0.
373- LoadedMacro :: MacroDef { def, .. } => !def. macro_rules ,
374- _ => false ,
367+ let DefKind :: Macro ( kinds) = tcx. def_kind ( def_id) else {
368+ unreachable ! ( ) ;
375369 } ;
376-
377- let mut path = if is_macro_2 {
378- once ( crate_name) . chain ( relative) . collect ( )
370+ let item_type = if kinds == MacroKinds :: DERIVE {
371+ ItemType :: ProcDerive
372+ } else if kinds == MacroKinds :: ATTR {
373+ ItemType :: ProcAttribute
379374 } else {
380- vec ! [ crate_name , relative . next_back ( ) . unwrap ( ) ]
375+ ItemType :: Macro
381376 } ;
377+ let mut path = clean:: inline:: get_item_path ( tcx, def_id, item_type) ;
382378 if path. len ( ) < 2 {
383379 // The minimum we can have is the crate name followed by the macro name. If shorter, then
384380 // it means that `relative` was empty, which is an error.
@@ -387,7 +383,7 @@ fn generate_macro_def_id_path(
387383 }
388384
389385 if let Some ( last) = path. last_mut ( ) {
390- * last = Symbol :: intern ( & format ! ( "macro .{last}.html" ) ) ;
386+ * last = Symbol :: intern ( & format ! ( "{} .{last}.html" , item_type . as_str ( ) ) ) ;
391387 }
392388
393389 let url = match cache. extern_locations [ & def_id. krate ] {
@@ -408,7 +404,7 @@ fn generate_macro_def_id_path(
408404 return Err ( HrefError :: NotInExternalCache ) ;
409405 }
410406 } ;
411- Ok ( ( url, ItemType :: Macro , fqp ) )
407+ Ok ( ( url, item_type , path ) )
412408}
413409
414410fn generate_item_def_id_path (
0 commit comments