@@ -4794,14 +4794,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4794
4794
let res = self . r . resolve_rustdoc_path ( path. as_str ( ) , * ns, self . parent_scope ) ;
4795
4795
if let Some ( res) = res
4796
4796
&& let Some ( def_id) = res. opt_def_id ( )
4797
- && !def_id. is_local ( )
4798
- && self . r . tcx . crate_types ( ) . contains ( & CrateType :: ProcMacro )
4799
- && matches ! (
4800
- self . r. tcx. sess. opts. resolve_doc_links,
4801
- ResolveDocLinks :: ExportedMetadata
4802
- )
4797
+ && self . is_invalid_proc_macro_item_for_doc ( def_id)
4803
4798
{
4804
- // Encoding foreign def ids in proc macro crate metadata will ICE.
4799
+ // Encoding def ids in proc macro crate metadata will ICE,
4800
+ // because it will only store proc macros for it.
4805
4801
return None ;
4806
4802
}
4807
4803
res
@@ -4810,6 +4806,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4810
4806
res
4811
4807
}
4812
4808
4809
+ fn is_invalid_proc_macro_item_for_doc ( & self , did : DefId ) -> bool {
4810
+ if !self . r . tcx . crate_types ( ) . contains ( & CrateType :: ProcMacro )
4811
+ || !matches ! ( self . r. tcx. sess. opts. resolve_doc_links, ResolveDocLinks :: ExportedMetadata )
4812
+ {
4813
+ return false ;
4814
+ }
4815
+ let Some ( local_did) = did. as_local ( ) else { return true } ;
4816
+ let Some ( node_id) = self . r . def_id_to_node_id . get ( local_did) else { return true } ;
4817
+ !self . r . proc_macros . contains ( node_id)
4818
+ }
4819
+
4813
4820
fn resolve_doc_links ( & mut self , attrs : & [ Attribute ] , maybe_exported : MaybeExported < ' _ > ) {
4814
4821
match self . r . tcx . sess . opts . resolve_doc_links {
4815
4822
ResolveDocLinks :: None => return ,
@@ -4872,14 +4879,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4872
4879
. traits_in_scope ( None , & self . parent_scope , SyntaxContext :: root ( ) , None )
4873
4880
. into_iter ( )
4874
4881
. filter_map ( |tr| {
4875
- if !tr. def_id . is_local ( )
4876
- && self . r . tcx . crate_types ( ) . contains ( & CrateType :: ProcMacro )
4877
- && matches ! (
4878
- self . r. tcx. sess. opts. resolve_doc_links,
4879
- ResolveDocLinks :: ExportedMetadata
4880
- )
4881
- {
4882
- // Encoding foreign def ids in proc macro crate metadata will ICE.
4882
+ if self . is_invalid_proc_macro_item_for_doc ( tr. def_id ) {
4883
+ // Encoding def ids in proc macro crate metadata will ICE.
4884
+ // because it will only store proc macros for it.
4883
4885
return None ;
4884
4886
}
4885
4887
Some ( tr. def_id )
0 commit comments