Skip to content

Commit ee8cc77

Browse files
committed
Auto merge of #52361 - QuietMisdreavus:proc-macro-doc, r=ollie27
rustdoc: don't panic when the cross-re-export handler sees a proc-macro When i moved the macro cross-re-export inlining code into `clean::inline`, i thought that if a macro had a `Def` that said it was a bang macro, it wouldn't be a proc macro. I thought wrong. Turns out, the `quote!()` in `libproc_macro` is actually a proc-macro, and when the `quote!()` macro is re-exported, this proc-macro is accessed in its place. This causes any `proc_macro::*` glob re-export to pull in this proc-macro, causing the assertion i added to fire, leading to an ICE. This replaces that with an Option that ignores proc-macros for the time being. Fixes #52129
2 parents bb09c39 + e78fb9b commit ee8cc77

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
104104
// separately
105105
Def::Macro(did, MacroKind::Bang) => {
106106
record_extern_fqn(cx, did, clean::TypeKind::Macro);
107-
clean::MacroItem(build_macro(cx, did, name))
107+
if let Some(mac) = build_macro(cx, did, name) {
108+
clean::MacroItem(mac)
109+
} else {
110+
return None;
111+
}
108112
}
109113
_ => return None,
110114
};
@@ -466,12 +470,12 @@ fn build_static(cx: &DocContext, did: DefId, mutable: bool) -> clean::Static {
466470
}
467471
}
468472

469-
fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> clean::Macro {
473+
fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> Option<clean::Macro> {
470474
let imported_from = cx.tcx.original_crate_name(did.krate);
471475
let def = match cx.cstore.load_macro_untracked(did, cx.sess()) {
472476
LoadedMacro::MacroDef(macro_def) => macro_def,
473477
// FIXME(jseyfried): document proc macro re-exports
474-
LoadedMacro::ProcMacro(..) => panic!("attempting to document proc-macro re-export"),
478+
LoadedMacro::ProcMacro(..) => return None,
475479
};
476480

477481
let matchers: hir::HirVec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.node {
@@ -487,10 +491,10 @@ fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> clean::Macro {
487491
format!(" {} => {{ ... }};\n", span.to_src(cx))
488492
}).collect::<String>());
489493

490-
clean::Macro {
494+
Some(clean::Macro {
491495
source,
492496
imported_from: Some(imported_from).clean(cx),
493-
}
497+
})
494498
}
495499

496500
/// A trait's generics clause actually contains all of the predicates for all of

src/test/rustdoc/doc-proc-macro.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Issue #52129: ICE when trying to document the `quote` proc-macro from proc_macro
12+
13+
// As of this writing, we don't currently attempt to document proc-macros. However, we shouldn't
14+
// crash when we try.
15+
16+
extern crate proc_macro;
17+
18+
pub use proc_macro::*;

0 commit comments

Comments
 (0)