@@ -34,7 +34,6 @@ use rustc::middle::resolve_lifetime as rl;
34
34
use rustc:: middle:: lang_items;
35
35
use rustc:: hir:: def:: { Def , CtorKind } ;
36
36
use rustc:: hir:: def_id:: { CrateNum , DefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
37
- use rustc:: hir:: lowering:: Resolver ;
38
37
use rustc:: ty:: subst:: Substs ;
39
38
use rustc:: ty:: { self , Ty , AdtKind } ;
40
39
use rustc:: middle:: stability;
@@ -828,25 +827,25 @@ impl Clean<Attributes> for [ast::Attribute] {
828
827
let dox = attrs. collapsed_doc_value ( ) . unwrap_or_else ( String :: new) ;
829
828
for link in markdown_links ( & dox, cx. render_type ) {
830
829
let path = {
831
- let is_value: bool ;
830
+ let is_value;
832
831
let path_str = if let Some ( prefix) =
833
832
[ "struct" , "enum" , "type" , "trait" , "union" ] . iter ( )
834
833
. find ( |p| link. starts_with ( * * p) ) {
835
- is_value = false ;
834
+ is_value = Some ( false ) ;
836
835
link. trim_left_matches ( prefix) . trim ( )
837
836
} else if let Some ( prefix) =
838
837
[ "const" , "static" ] . iter ( )
839
838
. find ( |p| link. starts_with ( * * p) ) {
840
- is_value = true ;
839
+ is_value = Some ( true ) ;
841
840
link. trim_left_matches ( prefix) . trim ( )
842
841
} else if link. ends_with ( "()" ) {
843
- is_value = true ;
842
+ is_value = Some ( true ) ;
844
843
link. trim_right_matches ( "()" ) . trim ( )
845
844
} else if link. ends_with ( "!" ) {
846
845
// FIXME (misdreavus): macros are resolved with different machinery
847
846
continue ;
848
847
} else {
849
- is_value = false ;
848
+ is_value = None ;
850
849
link. trim ( )
851
850
} ;
852
851
@@ -864,12 +863,34 @@ impl Clean<Attributes> for [ast::Attribute] {
864
863
// but it can't because that would break object safety. This can still be
865
864
// fixed.
866
865
let components = path_str. split ( "::" ) . skip ( 1 ) . collect :: < Vec < _ > > ( ) ;
867
- cx. resolver . borrow_mut ( ) . resolve_str_path ( DUMMY_SP , None , & components, is_value)
866
+ let resolve = |is_val| cx. resolver . borrow_mut ( ) . resolve_str_path_error ( DUMMY_SP , None , & components, is_val) ;
867
+
868
+ if let Some ( is_value) = is_value {
869
+ if let Ok ( path) = resolve ( is_value) {
870
+ path
871
+ } else {
872
+ // this could just be a normal link or a broken link
873
+ // we could potentially check if something is
874
+ // "intra-doc-link-like" and warn in that case
875
+ continue ;
876
+ }
877
+ } else {
878
+ // try both!
879
+ // It is imperative we search for not-a-value first
880
+ // Otherwise we will find struct ctors for when we are looking
881
+ // for structs, etc, and the link won't work.
882
+ if let Ok ( path) = resolve ( false ) {
883
+ path
884
+ } else if let Ok ( path) = resolve ( true ) {
885
+ path
886
+ } else {
887
+ // this could just be a normal link
888
+ continue ;
889
+ }
890
+ }
868
891
} ;
869
892
870
- if path. def != Def :: Err {
871
- attrs. links . push ( ( link, path. def . def_id ( ) ) ) ;
872
- }
893
+ attrs. links . push ( ( link, path. def . def_id ( ) ) ) ;
873
894
}
874
895
875
896
cx. sess ( ) . abort_if_errors ( ) ;
0 commit comments