Skip to content

Commit 7739bb2

Browse files
committed
Move resolve() into a function
1 parent fbd2d16 commit 7739bb2

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,24 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
892892
.emit();
893893
}
894894

895+
/// Resolve a given string as a path, along with whether or not it is
896+
/// in the value namespace
897+
fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<hir::Path, ()> {
898+
// In case we're in a module, try to resolve the relative
899+
// path
900+
if let Some(id) = cx.mod_ids.borrow().last() {
901+
cx.resolver.borrow_mut()
902+
.with_scope(*id, |resolver| {
903+
resolver.resolve_str_path_error(DUMMY_SP,
904+
&path_str, is_val)
905+
})
906+
} else {
907+
// FIXME(Manishearth) this branch doesn't seem to ever be hit, really
908+
cx.resolver.borrow_mut()
909+
.resolve_str_path_error(DUMMY_SP, &path_str, is_val)
910+
}
911+
}
912+
895913
enum PathKind {
896914
/// can be either value or type, not a macro
897915
Unknown,
@@ -945,22 +963,6 @@ impl Clean<Attributes> for [ast::Attribute] {
945963
continue;
946964
}
947965

948-
let resolve = |is_val| {
949-
// In case we're in a module, try to resolve the relative
950-
// path
951-
if let Some(id) = cx.mod_ids.borrow().last() {
952-
cx.resolver.borrow_mut()
953-
.with_scope(*id, |resolver| {
954-
resolver.resolve_str_path_error(DUMMY_SP,
955-
&path_str, is_val)
956-
})
957-
} else {
958-
// FIXME(Manishearth) this branch doesn't seem to ever be hit, really
959-
cx.resolver.borrow_mut()
960-
.resolve_str_path_error(DUMMY_SP, &path_str, is_val)
961-
}
962-
};
963-
964966
let macro_resolve = || {
965967
use syntax::ext::base::MacroKind;
966968
use syntax::ext::hygiene::Mark;
@@ -989,7 +991,7 @@ impl Clean<Attributes> for [ast::Attribute] {
989991

990992
match kind {
991993
PathKind::Value => {
992-
if let Ok(path) = resolve(true) {
994+
if let Ok(path) = resolve(cx, path_str, true) {
993995
path.def
994996
} else {
995997
// this could just be a normal link or a broken link
@@ -999,7 +1001,7 @@ impl Clean<Attributes> for [ast::Attribute] {
9991001
}
10001002
}
10011003
PathKind::Type => {
1002-
if let Ok(path) = resolve(false) {
1004+
if let Ok(path) = resolve(cx, path_str, false) {
10031005
path.def
10041006
} else {
10051007
// this could just be a normal link
@@ -1009,14 +1011,14 @@ impl Clean<Attributes> for [ast::Attribute] {
10091011
PathKind::Unknown => {
10101012
// try everything!
10111013
if let Some(macro_def) = macro_resolve() {
1012-
if let Ok(type_path) = resolve(false) {
1014+
if let Ok(type_path) = resolve(cx, path_str, false) {
10131015
let (type_kind, article, type_disambig)
10141016
= type_ns_kind(type_path.def, path_str);
10151017
ambiguity_error(cx, &attrs, path_str,
10161018
article, type_kind, &type_disambig,
10171019
"a", "macro", &format!("macro@{}", path_str));
10181020
continue;
1019-
} else if let Ok(value_path) = resolve(true) {
1021+
} else if let Ok(value_path) = resolve(cx, path_str, true) {
10201022
let (value_kind, value_disambig)
10211023
= value_ns_kind(value_path.def, path_str)
10221024
.expect("struct and mod cases should have been \
@@ -1026,12 +1028,12 @@ impl Clean<Attributes> for [ast::Attribute] {
10261028
"a", "macro", &format!("macro@{}", path_str));
10271029
}
10281030
macro_def
1029-
} else if let Ok(type_path) = resolve(false) {
1031+
} else if let Ok(type_path) = resolve(cx, path_str, false) {
10301032
// It is imperative we search for not-a-value first
10311033
// Otherwise we will find struct ctors for when we are looking
10321034
// for structs, and the link won't work.
10331035
// if there is something in both namespaces
1034-
if let Ok(value_path) = resolve(true) {
1036+
if let Ok(value_path) = resolve(cx, path_str, true) {
10351037
let kind = value_ns_kind(value_path.def, path_str);
10361038
if let Some((value_kind, value_disambig)) = kind {
10371039
let (type_kind, article, type_disambig)
@@ -1043,7 +1045,7 @@ impl Clean<Attributes> for [ast::Attribute] {
10431045
}
10441046
}
10451047
type_path.def
1046-
} else if let Ok(value_path) = resolve(true) {
1048+
} else if let Ok(value_path) = resolve(cx, path_str, true) {
10471049
value_path.def
10481050
} else {
10491051
// this could just be a normal link

0 commit comments

Comments
 (0)