Skip to content

Commit 961ec90

Browse files
committed
only store valid proc marco item for doc link
1 parent b19329a commit 961ec90

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

compiler/rustc_resolve/src/late.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -4794,14 +4794,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
47944794
let res = self.r.resolve_rustdoc_path(path.as_str(), *ns, self.parent_scope);
47954795
if let Some(res) = res
47964796
&& 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)
48034798
{
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.
48054801
return None;
48064802
}
48074803
res
@@ -4810,6 +4806,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
48104806
res
48114807
}
48124808

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+
48134820
fn resolve_doc_links(&mut self, attrs: &[Attribute], maybe_exported: MaybeExported<'_>) {
48144821
match self.r.tcx.sess.opts.resolve_doc_links {
48154822
ResolveDocLinks::None => return,
@@ -4872,14 +4879,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
48724879
.traits_in_scope(None, &self.parent_scope, SyntaxContext::root(), None)
48734880
.into_iter()
48744881
.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.
48834885
return None;
48844886
}
48854887
Some(tr.def_id)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ force-host
2+
//@ no-prefer-dynamic
3+
#![crate_type = "proc-macro"]
4+
5+
extern crate proc_macro;
6+
use proc_macro::TokenStream;
7+
8+
mod view {}
9+
10+
/// [`view`]
11+
#[proc_macro]
12+
pub fn f(_: TokenStream) -> TokenStream {
13+
todo!()
14+
}
15+
16+
/// [`f()`]
17+
#[proc_macro]
18+
pub fn g(_: TokenStream) -> TokenStream {
19+
todo!()
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ aux-build:in-proc-item-comment.rs
2+
//@ check-pass
3+
4+
// issue#132743
5+
6+
extern crate in_proc_item_comment;
7+
8+
pub use in_proc_item_comment::{f, g};

0 commit comments

Comments
 (0)