Skip to content

Commit 4ced272

Browse files
committed
Move macro_resolve() into a function
1 parent 7739bb2 commit 4ced272

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

src/librustdoc/clean/mod.rs

+29-27
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,33 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<hir::Path, (
910910
}
911911
}
912912

913+
/// Resolve a string as a macro
914+
fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
915+
use syntax::ext::base::MacroKind;
916+
use syntax::ext::hygiene::Mark;
917+
let segment = ast::PathSegment {
918+
identifier: ast::Ident::from_str(path_str),
919+
span: DUMMY_SP,
920+
parameters: None,
921+
};
922+
let path = ast::Path {
923+
span: DUMMY_SP,
924+
segments: vec![segment],
925+
};
926+
927+
let mut resolver = cx.resolver.borrow_mut();
928+
let mark = Mark::root();
929+
let res = resolver
930+
.resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
931+
if let Ok(def) = res {
932+
Some(def)
933+
} else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
934+
Some(*def)
935+
} else {
936+
None
937+
}
938+
}
939+
913940
enum PathKind {
914941
/// can be either value or type, not a macro
915942
Unknown,
@@ -963,31 +990,6 @@ impl Clean<Attributes> for [ast::Attribute] {
963990
continue;
964991
}
965992

966-
let macro_resolve = || {
967-
use syntax::ext::base::MacroKind;
968-
use syntax::ext::hygiene::Mark;
969-
let segment = ast::PathSegment {
970-
identifier: ast::Ident::from_str(path_str),
971-
span: DUMMY_SP,
972-
parameters: None,
973-
};
974-
let path = ast::Path {
975-
span: DUMMY_SP,
976-
segments: vec![segment],
977-
};
978-
979-
let mut resolver = cx.resolver.borrow_mut();
980-
let mark = Mark::root();
981-
let res = resolver
982-
.resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
983-
if let Ok(def) = res {
984-
Some(def)
985-
} else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
986-
Some(*def)
987-
} else {
988-
None
989-
}
990-
};
991993

992994
match kind {
993995
PathKind::Value => {
@@ -1010,7 +1012,7 @@ impl Clean<Attributes> for [ast::Attribute] {
10101012
}
10111013
PathKind::Unknown => {
10121014
// try everything!
1013-
if let Some(macro_def) = macro_resolve() {
1015+
if let Some(macro_def) = macro_resolve(cx, path_str) {
10141016
if let Ok(type_path) = resolve(cx, path_str, false) {
10151017
let (type_kind, article, type_disambig)
10161018
= type_ns_kind(type_path.def, path_str);
@@ -1053,7 +1055,7 @@ impl Clean<Attributes> for [ast::Attribute] {
10531055
}
10541056
}
10551057
PathKind::Macro => {
1056-
if let Some(def) = macro_resolve() {
1058+
if let Some(def) = macro_resolve(cx, path_str) {
10571059
def
10581060
} else {
10591061
continue

0 commit comments

Comments
 (0)