about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-01-19 17:19:01 +0530
committerManish Goregaokar <manishsmail@gmail.com>2018-01-22 15:24:31 +0530
commit5762fa4b5a22276626414d94b38b0e7886396089 (patch)
treed9594d35dd780e76f7f01f3054462e17f34d6caa
parent869dd91d443b10e11d20d93beb9c06cb0fd7ec42 (diff)
downloadrust-5762fa4b5a22276626414d94b38b0e7886396089.tar.gz
rust-5762fa4b5a22276626414d94b38b0e7886396089.zip
Allow macros to be resolved with ambiguous idents too
-rw-r--r--src/librustdoc/clean/mod.rs50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 1734071f849..b42696b0985 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -904,6 +904,32 @@ impl Clean<Attributes> for [ast::Attribute] {
                         }
                     };
 
+                    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 => {
                             if let Ok(path) = resolve(true) {
@@ -974,34 +1000,18 @@ impl Clean<Attributes> for [ast::Attribute] {
                                 path.def
                             } else if let Ok(path) = resolve(true) {
                                 path.def
+                            } else if let Some(def) = macro_resolve() {
+                                def
                             } else {
                                 // this could just be a normal link
                                 continue;
                             }
                         }
                         PathKind::Macro => {
-                            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 {
+                            if let Some(def) = macro_resolve() {
                                 def
-                            } else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
-                                *def
                             } else {
-                                continue;
+                                continue
                             }
                         }
                     }