about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-01-19 18:13:50 +0530
committerManish Goregaokar <manishsmail@gmail.com>2018-01-22 15:24:32 +0530
commit4ced272780321c597df740dd904fac59b0bff608 (patch)
tree2753d921a0071b58bcf03a5a26606040d4fc9f1a /src
parent7739bb2d3520fbbd2ae26efc9fd1bf4657a35d9b (diff)
Move macro_resolve() into a function
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/mod.rs56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 66b7cd0cff9..fb1d21d6527 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -910,6 +910,33 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<hir::Path, (
     }
 }
 
+/// Resolve a string as a macro
+fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
+    use syntax::ext::base::MacroKind;
+    use syntax::ext::hygiene::Mark;
+    let segment = ast::PathSegment {
+        identifier: ast::Ident::from_str(path_str),
+        span: DUMMY_SP,
+        parameters: None,
+    };
+    let path = ast::Path {
+        span: DUMMY_SP,
+        segments: vec![segment],
+    };
+
+    let mut resolver = cx.resolver.borrow_mut();
+    let mark = Mark::root();
+    let res = resolver
+        .resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
+    if let Ok(def) = res {
+        Some(def)
+    } else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
+        Some(*def)
+    } else {
+        None
+    }
+}
+
 enum PathKind {
     /// can be either value or type, not a macro
     Unknown,
@@ -963,31 +990,6 @@ impl Clean<Attributes> for [ast::Attribute] {
                         continue;
                     }
 
-                    let macro_resolve = || {
-                            use syntax::ext::base::MacroKind;
-                            use syntax::ext::hygiene::Mark;
-                            let segment = ast::PathSegment {
-                                identifier: ast::Ident::from_str(path_str),
-                                span: DUMMY_SP,
-                                parameters: None,
-                            };
-                            let path = ast::Path {
-                                span: DUMMY_SP,
-                                segments: vec![segment],
-                            };
-
-                            let mut resolver = cx.resolver.borrow_mut();
-                            let mark = Mark::root();
-                            let res = resolver
-                                .resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
-                            if let Ok(def) = res {
-                                Some(def)
-                            } else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
-                                Some(*def)
-                            } else {
-                                None
-                            }
-                    };
 
                     match kind {
                         PathKind::Value => {
@@ -1010,7 +1012,7 @@ impl Clean<Attributes> for [ast::Attribute] {
                         }
                         PathKind::Unknown => {
                             // try everything!
-                            if let Some(macro_def) = macro_resolve() {
+                            if let Some(macro_def) = macro_resolve(cx, path_str) {
                                 if let Ok(type_path) = resolve(cx, path_str, false) {
                                     let (type_kind, article, type_disambig)
                                         = type_ns_kind(type_path.def, path_str);
@@ -1053,7 +1055,7 @@ impl Clean<Attributes> for [ast::Attribute] {
                             }
                         }
                         PathKind::Macro => {
-                            if let Some(def) = macro_resolve() {
+                            if let Some(def) = macro_resolve(cx, path_str) {
                                 def
                             } else {
                                 continue