diff options
| author | bors <bors@rust-lang.org> | 2018-07-15 08:30:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-15 08:30:36 +0000 |
| commit | ee8cc77b32e5480c92b0259347f32f9a4bef6f92 (patch) | |
| tree | e8b1959783538c6881328f4af13c727bc827d5f5 /src | |
| parent | bb09c39f4454577c9346fcce24db0f53ca49dce7 (diff) | |
| parent | e78fb9bad0e9137c75147c4469806fe0e61154c2 (diff) | |
| download | rust-ee8cc77b32e5480c92b0259347f32f9a4bef6f92.tar.gz rust-ee8cc77b32e5480c92b0259347f32f9a4bef6f92.zip | |
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 https://github.com/rust-lang/rust/issues/52129
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 14 | ||||
| -rw-r--r-- | src/test/rustdoc/doc-proc-macro.rs | 18 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index fa0e5a88f80..0117e4fde84 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -104,7 +104,11 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa // separately Def::Macro(did, MacroKind::Bang) => { record_extern_fqn(cx, did, clean::TypeKind::Macro); - clean::MacroItem(build_macro(cx, did, name)) + if let Some(mac) = build_macro(cx, did, name) { + clean::MacroItem(mac) + } else { + return None; + } } _ => return None, }; @@ -466,12 +470,12 @@ fn build_static(cx: &DocContext, did: DefId, mutable: bool) -> clean::Static { } } -fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> clean::Macro { +fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> Option<clean::Macro> { let imported_from = cx.tcx.original_crate_name(did.krate); let def = match cx.cstore.load_macro_untracked(did, cx.sess()) { LoadedMacro::MacroDef(macro_def) => macro_def, // FIXME(jseyfried): document proc macro re-exports - LoadedMacro::ProcMacro(..) => panic!("attempting to document proc-macro re-export"), + LoadedMacro::ProcMacro(..) => return None, }; 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 { format!(" {} => {{ ... }};\n", span.to_src(cx)) }).collect::<String>()); - clean::Macro { + Some(clean::Macro { source, imported_from: Some(imported_from).clean(cx), - } + }) } /// A trait's generics clause actually contains all of the predicates for all of diff --git a/src/test/rustdoc/doc-proc-macro.rs b/src/test/rustdoc/doc-proc-macro.rs new file mode 100644 index 00000000000..b3b403a7b86 --- /dev/null +++ b/src/test/rustdoc/doc-proc-macro.rs @@ -0,0 +1,18 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Issue #52129: ICE when trying to document the `quote` proc-macro from proc_macro + +// As of this writing, we don't currently attempt to document proc-macros. However, we shouldn't +// crash when we try. + +extern crate proc_macro; + +pub use proc_macro::*; |
