Skip to content

Commit

Permalink
store the defs in proc macro crate
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Nov 16, 2024
1 parent 46e8d20 commit 9c4007c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
18 changes: 14 additions & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_middle::ty::{AssocItemContainer, SymbolName};
use rustc_middle::util::common::to_readable_str;
use rustc_middle::{bug, span_bug};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque};
use rustc_session::config::{CrateType, OptLevel};
use rustc_session::config::{CrateType, OptLevel, ResolveDocLinks};
use rustc_span::hygiene::HygieneEncodeContext;
use rustc_span::symbol::sym;
use rustc_span::{
Expand Down Expand Up @@ -134,7 +134,13 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for ExpnIndex {

impl<'a, 'tcx> SpanEncoder for EncodeContext<'a, 'tcx> {
fn encode_crate_num(&mut self, crate_num: CrateNum) {
if crate_num != LOCAL_CRATE && self.is_proc_macro {
if crate_num != LOCAL_CRATE
&& (self.is_proc_macro
&& !matches!(
self.tcx.sess.opts.resolve_doc_links,
ResolveDocLinks::ExportedMetadata
))
{
panic!("Attempted to encode non-local CrateNum {crate_num:?} for proc-macro crate");
}
self.emit_u32(crate_num.as_u32());
Expand Down Expand Up @@ -495,7 +501,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

fn encode_def_path_table(&mut self) {
let table = self.tcx.def_path_table();
if self.is_proc_macro {
if self.is_proc_macro
&& !matches!(self.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata)
{
for def_index in std::iter::once(CRATE_DEF_INDEX)
.chain(self.tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index))
{
Expand Down Expand Up @@ -1373,7 +1381,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

// Proc-macro crates only export proc-macro items, which are looked
// up using `proc_macro_data`
if self.is_proc_macro {
if self.is_proc_macro
&& !matches!(self.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata)
{
return;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/rustdoc-ui/intra-doc/auxiliary/in-proc-item-comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ 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!()
}
8 changes: 8 additions & 0 deletions tests/rustdoc-ui/intra-doc/pub-prco-item.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 9c4007c

Please sign in to comment.