@@ -23,8 +23,9 @@ use syntax::abi::Abi;
23
23
use syntax:: ast;
24
24
use syntax:: attr;
25
25
use syntax:: codemap:: Spanned ;
26
+ use syntax:: feature_gate:: UnstableFeatures ;
26
27
use syntax:: ptr:: P ;
27
- use syntax:: symbol:: keywords;
28
+ use syntax:: symbol:: { keywords, Symbol } ;
28
29
use syntax_pos:: { self , DUMMY_SP , Pos , FileName } ;
29
30
30
31
use rustc:: middle:: const_val:: ConstVal ;
@@ -33,6 +34,7 @@ use rustc::middle::resolve_lifetime as rl;
33
34
use rustc:: middle:: lang_items;
34
35
use rustc:: hir:: def:: { Def , CtorKind } ;
35
36
use rustc:: hir:: def_id:: { CrateNum , DefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
37
+ use rustc:: hir:: lowering:: Resolver ;
36
38
use rustc:: ty:: subst:: Substs ;
37
39
use rustc:: ty:: { self , Ty , AdtKind } ;
38
40
use rustc:: middle:: stability;
@@ -43,7 +45,7 @@ use rustc::hir;
43
45
44
46
use rustc_const_math:: ConstInt ;
45
47
use std:: default:: Default ;
46
- use std:: { mem, slice, vec} ;
48
+ use std:: { mem, slice, vec, iter } ;
47
49
use std:: iter:: FromIterator ;
48
50
use std:: rc:: Rc ;
49
51
use std:: sync:: Arc ;
@@ -53,6 +55,7 @@ use core::DocContext;
53
55
use doctree;
54
56
use visit_ast;
55
57
use html:: item_type:: ItemType ;
58
+ use html:: markdown:: markdown_links;
56
59
57
60
pub mod inline;
58
61
pub mod cfg;
@@ -633,6 +636,7 @@ pub struct Attributes {
633
636
pub other_attrs : Vec < ast:: Attribute > ,
634
637
pub cfg : Option < Rc < Cfg > > ,
635
638
pub span : Option < syntax_pos:: Span > ,
639
+ pub links : Vec < ( String , DefId ) > ,
636
640
}
637
641
638
642
impl Attributes {
@@ -762,11 +766,13 @@ impl Attributes {
762
766
Some ( attr. clone ( ) )
763
767
} )
764
768
} ) . collect ( ) ;
769
+
765
770
Attributes {
766
771
doc_strings,
767
772
other_attrs,
768
773
cfg : if cfg == Cfg :: True { None } else { Some ( Rc :: new ( cfg) ) } ,
769
774
span : sp,
775
+ links : vec ! [ ] ,
770
776
}
771
777
}
772
778
@@ -795,7 +801,38 @@ impl AttributesExt for Attributes {
795
801
796
802
impl Clean < Attributes > for [ ast:: Attribute ] {
797
803
fn clean ( & self , cx : & DocContext ) -> Attributes {
798
- Attributes :: from_ast ( cx. sess ( ) . diagnostic ( ) , self )
804
+ let mut attrs = Attributes :: from_ast ( cx. sess ( ) . diagnostic ( ) , self ) ;
805
+
806
+ if UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) {
807
+ let dox = attrs. collapsed_doc_value ( ) . unwrap_or_else ( String :: new) ;
808
+ for link in markdown_links ( & dox, cx. render_type ) {
809
+ if !link. starts_with ( "::" ) {
810
+ // FIXME (misdreavus): can only support absolute paths because of limitations
811
+ // in Resolver. this may, with a lot of effort, figure out how to resolve paths
812
+ // within scopes, but the one use of `resolve_hir_path` i found in the HIR
813
+ // lowering code itself used an absolute path. we're brushing up against some
814
+ // structural limitations in the compiler already, but this may be a design one
815
+ // as well >_>
816
+ continue ;
817
+ }
818
+
819
+ let mut path = hir:: Path {
820
+ span : DUMMY_SP ,
821
+ def : Def :: Err ,
822
+ segments : iter:: once ( keywords:: CrateRoot . name ( ) ) . chain ( {
823
+ link. split ( "::" ) . skip ( 1 ) . map ( Symbol :: intern)
824
+ } ) . map ( hir:: PathSegment :: from_name) . collect ( ) ,
825
+ } ;
826
+
827
+ cx. resolver . borrow_mut ( ) . resolve_hir_path ( & mut path, false ) ;
828
+
829
+ if path. def != Def :: Err {
830
+ attrs. links . push ( ( link, path. def . def_id ( ) ) ) ;
831
+ }
832
+ }
833
+ }
834
+
835
+ attrs
799
836
}
800
837
}
801
838
0 commit comments