Skip to content

Commit 9c4007c

Browse files
committed
store the defs in proc macro crate
1 parent 46e8d20 commit 9c4007c

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::ty::{AssocItemContainer, SymbolName};
2525
use rustc_middle::util::common::to_readable_str;
2626
use rustc_middle::{bug, span_bug};
2727
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque};
28-
use rustc_session::config::{CrateType, OptLevel};
28+
use rustc_session::config::{CrateType, OptLevel, ResolveDocLinks};
2929
use rustc_span::hygiene::HygieneEncodeContext;
3030
use rustc_span::symbol::sym;
3131
use rustc_span::{
@@ -134,7 +134,13 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for ExpnIndex {
134134

135135
impl<'a, 'tcx> SpanEncoder for EncodeContext<'a, 'tcx> {
136136
fn encode_crate_num(&mut self, crate_num: CrateNum) {
137-
if crate_num != LOCAL_CRATE && self.is_proc_macro {
137+
if crate_num != LOCAL_CRATE
138+
&& (self.is_proc_macro
139+
&& !matches!(
140+
self.tcx.sess.opts.resolve_doc_links,
141+
ResolveDocLinks::ExportedMetadata
142+
))
143+
{
138144
panic!("Attempted to encode non-local CrateNum {crate_num:?} for proc-macro crate");
139145
}
140146
self.emit_u32(crate_num.as_u32());
@@ -495,7 +501,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
495501

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

13741382
// Proc-macro crates only export proc-macro items, which are looked
13751383
// up using `proc_macro_data`
1376-
if self.is_proc_macro {
1384+
if self.is_proc_macro
1385+
&& !matches!(self.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata)
1386+
{
13771387
return;
13781388
}
13791389

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}
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;

0 commit comments

Comments
 (0)