Rollup merge of #107951 - petrochenkov:procmacdoc, r=jackh726

resolve: Fix doc links referring to other crates when documenting proc macro crates directly

Fixes https://github.com/rust-lang/rust/issues/107950
This commit is contained in:
Dylan DPC 2023-02-19 13:03:41 +05:30 committed by GitHub
commit 4a0f088f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -4211,7 +4211,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
if let Some(res) = res
&& let Some(def_id) = res.opt_def_id()
&& !def_id.is_local()
&& self.r.session.crate_types().contains(&CrateType::ProcMacro) {
&& self.r.session.crate_types().contains(&CrateType::ProcMacro)
&& matches!(self.r.session.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata) {
// Encoding foreign def ids in proc macro crate metadata will ICE.
return None;
}
@ -4281,6 +4282,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
.filter_map(|tr| {
if !tr.def_id.is_local()
&& self.r.session.crate_types().contains(&CrateType::ProcMacro)
&& matches!(
self.r.session.opts.resolve_doc_links,
ResolveDocLinks::ExportedMetadata
)
{
// Encoding foreign def ids in proc macro crate metadata will ICE.
return None;

View File

@ -0,0 +1,27 @@
// check-pass
// force-host
// no-prefer-dynamic
// compile-flags: --crate-type proc-macro
#![deny(rustdoc::broken_intra_doc_links)]
extern crate proc_macro;
use proc_macro::*;
/// [`Unpin`]
#[proc_macro_derive(F)]
pub fn derive_(t: proc_macro::TokenStream) -> proc_macro::TokenStream {
t
}
/// [`Vec`]
#[proc_macro_attribute]
pub fn attr(t: proc_macro::TokenStream, _: proc_macro::TokenStream) -> proc_macro::TokenStream {
t
}
/// [`std::fs::File`]
#[proc_macro]
pub fn func(t: proc_macro::TokenStream) -> proc_macro::TokenStream {
t
}