mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Rollup merge of #133105 - bvanjoi:issue-132743, r=petrochenkov
only store valid proc macro item for doc link Fixes #132743 The definition item can be detected if it is exported in the doc, so store these items rather than skipping. r? `@petrochenkov`
This commit is contained in:
commit
6b07382b59
@ -4794,14 +4794,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
let res = self.r.resolve_rustdoc_path(path.as_str(), *ns, self.parent_scope);
|
||||
if let Some(res) = res
|
||||
&& let Some(def_id) = res.opt_def_id()
|
||||
&& !def_id.is_local()
|
||||
&& self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
|
||||
&& matches!(
|
||||
self.r.tcx.sess.opts.resolve_doc_links,
|
||||
ResolveDocLinks::ExportedMetadata
|
||||
)
|
||||
&& self.is_invalid_proc_macro_item_for_doc(def_id)
|
||||
{
|
||||
// Encoding foreign def ids in proc macro crate metadata will ICE.
|
||||
// Encoding def ids in proc macro crate metadata will ICE,
|
||||
// because it will only store proc macros for it.
|
||||
return None;
|
||||
}
|
||||
res
|
||||
@ -4810,6 +4806,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
res
|
||||
}
|
||||
|
||||
fn is_invalid_proc_macro_item_for_doc(&self, did: DefId) -> bool {
|
||||
if !matches!(self.r.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata)
|
||||
|| !self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let Some(local_did) = did.as_local() else { return true };
|
||||
let Some(node_id) = self.r.def_id_to_node_id.get(local_did) else { return true };
|
||||
!self.r.proc_macros.contains(node_id)
|
||||
}
|
||||
|
||||
fn resolve_doc_links(&mut self, attrs: &[Attribute], maybe_exported: MaybeExported<'_>) {
|
||||
match self.r.tcx.sess.opts.resolve_doc_links {
|
||||
ResolveDocLinks::None => return,
|
||||
@ -4872,14 +4879,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
.traits_in_scope(None, &self.parent_scope, SyntaxContext::root(), None)
|
||||
.into_iter()
|
||||
.filter_map(|tr| {
|
||||
if !tr.def_id.is_local()
|
||||
&& self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
|
||||
&& matches!(
|
||||
self.r.tcx.sess.opts.resolve_doc_links,
|
||||
ResolveDocLinks::ExportedMetadata
|
||||
)
|
||||
{
|
||||
// Encoding foreign def ids in proc macro crate metadata will ICE.
|
||||
if self.is_invalid_proc_macro_item_for_doc(tr.def_id) {
|
||||
// Encoding def ids in proc macro crate metadata will ICE.
|
||||
// because it will only store proc macros for it.
|
||||
return None;
|
||||
}
|
||||
Some(tr.def_id)
|
||||
|
20
tests/rustdoc-ui/intra-doc/auxiliary/in-proc-item-comment.rs
Normal file
20
tests/rustdoc-ui/intra-doc/auxiliary/in-proc-item-comment.rs
Normal file
@ -0,0 +1,20 @@
|
||||
//@ force-host
|
||||
//@ no-prefer-dynamic
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
mod view {}
|
||||
|
||||
/// [`view`]
|
||||
#[proc_macro]
|
||||
pub fn f(_: TokenStream) -> TokenStream {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// [`f()`]
|
||||
#[proc_macro]
|
||||
pub fn g(_: TokenStream) -> TokenStream {
|
||||
todo!()
|
||||
}
|
8
tests/rustdoc-ui/intra-doc/pub-proc-item.rs
Normal file
8
tests/rustdoc-ui/intra-doc/pub-proc-item.rs
Normal file
@ -0,0 +1,8 @@
|
||||
//@ aux-build:in-proc-item-comment.rs
|
||||
//@ check-pass
|
||||
|
||||
// issue#132743
|
||||
|
||||
extern crate in_proc_item_comment;
|
||||
|
||||
pub use in_proc_item_comment::{f, g};
|
Loading…
Reference in New Issue
Block a user