Skip to content

Commit 5762fa4

Browse files
committed
Allow macros to be resolved with ambiguous idents too
1 parent 869dd91 commit 5762fa4

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,32 @@ impl Clean<Attributes> for [ast::Attribute] {
904904
}
905905
};
906906

907+
let macro_resolve = || {
908+
use syntax::ext::base::MacroKind;
909+
use syntax::ext::hygiene::Mark;
910+
let segment = ast::PathSegment {
911+
identifier: ast::Ident::from_str(path_str),
912+
span: DUMMY_SP,
913+
parameters: None,
914+
};
915+
let path = ast::Path {
916+
span: DUMMY_SP,
917+
segments: vec![segment],
918+
};
919+
920+
let mut resolver = cx.resolver.borrow_mut();
921+
let mark = Mark::root();
922+
let res = resolver
923+
.resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
924+
if let Ok(def) = res {
925+
Some(def)
926+
} else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
927+
Some(*def)
928+
} else {
929+
None
930+
}
931+
};
932+
907933
match kind {
908934
PathKind::Value => {
909935
if let Ok(path) = resolve(true) {
@@ -974,34 +1000,18 @@ impl Clean<Attributes> for [ast::Attribute] {
9741000
path.def
9751001
} else if let Ok(path) = resolve(true) {
9761002
path.def
1003+
} else if let Some(def) = macro_resolve() {
1004+
def
9771005
} else {
9781006
// this could just be a normal link
9791007
continue;
9801008
}
9811009
}
9821010
PathKind::Macro => {
983-
use syntax::ext::base::MacroKind;
984-
use syntax::ext::hygiene::Mark;
985-
let segment = ast::PathSegment {
986-
identifier: ast::Ident::from_str(path_str),
987-
span: DUMMY_SP,
988-
parameters: None,
989-
};
990-
let path = ast::Path {
991-
span: DUMMY_SP,
992-
segments: vec![segment],
993-
};
994-
995-
let mut resolver = cx.resolver.borrow_mut();
996-
let mark = Mark::root();
997-
let res = resolver
998-
.resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
999-
if let Ok(def) = res {
1011+
if let Some(def) = macro_resolve() {
10001012
def
1001-
} else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
1002-
*def
10031013
} else {
1004-
continue;
1014+
continue
10051015
}
10061016
}
10071017
}

0 commit comments

Comments
 (0)