Skip to content

Commit e576c8c

Browse files
authored
Rollup merge of rust-lang#57846 - QuietMisdreavus:proc-macro-links, r=GuillaumeGomez
rustdoc: fix ICE from loading proc-macro stubs Fixes rust-lang#55399 When trying to resolve a macro, rustdoc first tries to load it from the resolver to see whether it's a Macros 2.0 macro, so it can return that Def before looking for any other kind of macro. However, this becomes a problem when you try to load proc-macros: since you can't use a proc-macro inside its own crate, this lookup also fails when attempting to link to it. However, we have a hint that this lookup will fail: Macros which are actually `ProcMacroStub`s will fail the lookup, so we can use that information to skip loading the macro. Rustdoc will then happily check `resolve.all_macros`, which will return a usable Def that we can link to.
2 parents bea8321 + b876694 commit e576c8c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,12 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
431431
let parent_scope = resolver.dummy_parent_scope();
432432
if let Ok(def) = resolver.resolve_macro_to_def_inner(&path, MacroKind::Bang,
433433
&parent_scope, false, false) {
434-
if let SyntaxExtension::DeclMacro { .. } = *resolver.get_macro(def) {
435-
return Some(def);
434+
if let Def::Macro(_, MacroKind::ProcMacroStub) = def {
435+
// skip proc-macro stubs, they'll cause `get_macro` to crash
436+
} else {
437+
if let SyntaxExtension::DeclMacro { .. } = *resolver.get_macro(def) {
438+
return Some(def);
439+
}
436440
}
437441
}
438442
if let Some(def) = resolver.all_macros.get(&Symbol::intern(path_str)) {

src/test/rustdoc/proc-macro.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#![crate_type="proc-macro"]
55
#![crate_name="some_macros"]
66

7+
// @has some_macros/index.html
8+
// @has - '//a/[@href="attr.some_proc_attr.html"]' 'some_proc_attr'
9+
10+
//! include a link to [some_proc_attr] to make sure it works.
11+
712
extern crate proc_macro;
813

914
use proc_macro::TokenStream;

0 commit comments

Comments
 (0)