@@ -892,6 +892,24 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
892
892
. emit ( ) ;
893
893
}
894
894
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
+
895
913
enum PathKind {
896
914
/// can be either value or type, not a macro
897
915
Unknown ,
@@ -945,22 +963,6 @@ impl Clean<Attributes> for [ast::Attribute] {
945
963
continue ;
946
964
}
947
965
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
-
964
966
let macro_resolve = || {
965
967
use syntax:: ext:: base:: MacroKind ;
966
968
use syntax:: ext:: hygiene:: Mark ;
@@ -989,7 +991,7 @@ impl Clean<Attributes> for [ast::Attribute] {
989
991
990
992
match kind {
991
993
PathKind :: Value => {
992
- if let Ok ( path) = resolve ( true ) {
994
+ if let Ok ( path) = resolve ( cx , path_str , true ) {
993
995
path. def
994
996
} else {
995
997
// this could just be a normal link or a broken link
@@ -999,7 +1001,7 @@ impl Clean<Attributes> for [ast::Attribute] {
999
1001
}
1000
1002
}
1001
1003
PathKind :: Type => {
1002
- if let Ok ( path) = resolve ( false ) {
1004
+ if let Ok ( path) = resolve ( cx , path_str , false ) {
1003
1005
path. def
1004
1006
} else {
1005
1007
// this could just be a normal link
@@ -1009,14 +1011,14 @@ impl Clean<Attributes> for [ast::Attribute] {
1009
1011
PathKind :: Unknown => {
1010
1012
// try everything!
1011
1013
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 ) {
1013
1015
let ( type_kind, article, type_disambig)
1014
1016
= type_ns_kind ( type_path. def , path_str) ;
1015
1017
ambiguity_error ( cx, & attrs, path_str,
1016
1018
article, type_kind, & type_disambig,
1017
1019
"a" , "macro" , & format ! ( "macro@{}" , path_str) ) ;
1018
1020
continue ;
1019
- } else if let Ok ( value_path) = resolve ( true ) {
1021
+ } else if let Ok ( value_path) = resolve ( cx , path_str , true ) {
1020
1022
let ( value_kind, value_disambig)
1021
1023
= value_ns_kind ( value_path. def , path_str)
1022
1024
. expect ( "struct and mod cases should have been \
@@ -1026,12 +1028,12 @@ impl Clean<Attributes> for [ast::Attribute] {
1026
1028
"a" , "macro" , & format ! ( "macro@{}" , path_str) ) ;
1027
1029
}
1028
1030
macro_def
1029
- } else if let Ok ( type_path) = resolve ( false ) {
1031
+ } else if let Ok ( type_path) = resolve ( cx , path_str , false ) {
1030
1032
// It is imperative we search for not-a-value first
1031
1033
// Otherwise we will find struct ctors for when we are looking
1032
1034
// for structs, and the link won't work.
1033
1035
// 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 ) {
1035
1037
let kind = value_ns_kind ( value_path. def , path_str) ;
1036
1038
if let Some ( ( value_kind, value_disambig) ) = kind {
1037
1039
let ( type_kind, article, type_disambig)
@@ -1043,7 +1045,7 @@ impl Clean<Attributes> for [ast::Attribute] {
1043
1045
}
1044
1046
}
1045
1047
type_path. def
1046
- } else if let Ok ( value_path) = resolve ( true ) {
1048
+ } else if let Ok ( value_path) = resolve ( cx , path_str , true ) {
1047
1049
value_path. def
1048
1050
} else {
1049
1051
// this could just be a normal link
0 commit comments