@@ -193,7 +193,69 @@ impl Item {
193193 }
194194
195195 crate fn links ( & self , cache : & Cache ) -> Vec < RenderedLink > {
196- self . attrs . links ( self . def_id . krate , cache)
196+ use crate :: html:: format:: href;
197+ use crate :: html:: render:: CURRENT_DEPTH ;
198+
199+ cache
200+ . intra_doc_links
201+ . get ( & self . def_id )
202+ . map_or ( & [ ] [ ..] , |v| v. as_slice ( ) )
203+ . iter ( )
204+ . filter_map ( |ItemLink { link : s, link_text, did, fragment } | {
205+ match * did {
206+ Some ( did) => {
207+ if let Some ( ( mut href, ..) ) = href ( did, cache) {
208+ if let Some ( ref fragment) = * fragment {
209+ href. push ( '#' ) ;
210+ href. push_str ( fragment) ;
211+ }
212+ Some ( RenderedLink {
213+ original_text : s. clone ( ) ,
214+ new_text : link_text. clone ( ) ,
215+ href,
216+ } )
217+ } else {
218+ None
219+ }
220+ }
221+ None => {
222+ if let Some ( ref fragment) = * fragment {
223+ let url = match cache. extern_locations . get ( & self . def_id . krate ) {
224+ Some ( & ( _, _, ExternalLocation :: Local ) ) => {
225+ let depth = CURRENT_DEPTH . with ( |l| l. get ( ) ) ;
226+ "../" . repeat ( depth)
227+ }
228+ Some ( & ( _, _, ExternalLocation :: Remote ( ref s) ) ) => s. to_string ( ) ,
229+ Some ( & ( _, _, ExternalLocation :: Unknown ) ) | None => String :: from (
230+ // NOTE: intentionally doesn't pass crate name to avoid having
231+ // different primitive links between crates
232+ if UnstableFeatures :: from_environment ( None ) . is_nightly_build ( ) {
233+ "https://doc.rust-lang.org/nightly"
234+ } else {
235+ "https://doc.rust-lang.org"
236+ } ,
237+ ) ,
238+ } ;
239+ // This is a primitive so the url is done "by hand".
240+ let tail = fragment. find ( '#' ) . unwrap_or_else ( || fragment. len ( ) ) ;
241+ Some ( RenderedLink {
242+ original_text : s. clone ( ) ,
243+ new_text : link_text. clone ( ) ,
244+ href : format ! (
245+ "{}{}std/primitive.{}.html{}" ,
246+ url,
247+ if !url. ends_with( '/' ) { "/" } else { "" } ,
248+ & fragment[ ..tail] ,
249+ & fragment[ tail..]
250+ ) ,
251+ } )
252+ } else {
253+ panic ! ( "This isn't a primitive?!" ) ;
254+ }
255+ }
256+ }
257+ } )
258+ . collect ( )
197259 }
198260
199261 crate fn is_crate ( & self ) -> bool {
@@ -570,15 +632,13 @@ crate struct Attributes {
570632 crate other_attrs : Vec < ast:: Attribute > ,
571633 crate cfg : Option < Arc < Cfg > > ,
572634 crate span : Option < rustc_span:: Span > ,
573- /// map from Rust paths to resolved defs and potential URL fragments
574- crate links : Vec < ItemLink > ,
575635 crate inner_docs : bool ,
576636}
577637
578638#[ derive( Clone , Debug , Default , PartialEq , Eq , Hash ) ]
579639/// A link that has not yet been rendered.
580640///
581- /// This link will be turned into a rendered link by [`Attributes ::links`]
641+ /// This link will be turned into a rendered link by [`Item ::links`].
582642crate struct ItemLink {
583643 /// The original link written in the markdown
584644 pub ( crate ) link : String ,
@@ -804,7 +864,6 @@ impl Attributes {
804864 other_attrs,
805865 cfg : if cfg == Cfg :: True { None } else { Some ( Arc :: new ( cfg) ) } ,
806866 span : sp,
807- links : vec ! [ ] ,
808867 inner_docs,
809868 }
810869 }
@@ -848,72 +907,6 @@ impl Attributes {
848907 if self . doc_strings . is_empty ( ) { None } else { Some ( self . doc_strings . iter ( ) . collect ( ) ) }
849908 }
850909
851- /// Gets links as a vector
852- ///
853- /// Cache must be populated before call
854- crate fn links ( & self , krate : CrateNum , cache : & Cache ) -> Vec < RenderedLink > {
855- use crate :: html:: format:: href;
856- use crate :: html:: render:: CURRENT_DEPTH ;
857-
858- self . links
859- . iter ( )
860- . filter_map ( |ItemLink { link : s, link_text, did, fragment } | {
861- match * did {
862- Some ( did) => {
863- if let Some ( ( mut href, ..) ) = href ( did, cache) {
864- if let Some ( ref fragment) = * fragment {
865- href. push ( '#' ) ;
866- href. push_str ( fragment) ;
867- }
868- Some ( RenderedLink {
869- original_text : s. clone ( ) ,
870- new_text : link_text. clone ( ) ,
871- href,
872- } )
873- } else {
874- None
875- }
876- }
877- None => {
878- if let Some ( ref fragment) = * fragment {
879- let url = match cache. extern_locations . get ( & krate) {
880- Some ( & ( _, _, ExternalLocation :: Local ) ) => {
881- let depth = CURRENT_DEPTH . with ( |l| l. get ( ) ) ;
882- "../" . repeat ( depth)
883- }
884- Some ( & ( _, _, ExternalLocation :: Remote ( ref s) ) ) => s. to_string ( ) ,
885- Some ( & ( _, _, ExternalLocation :: Unknown ) ) | None => String :: from (
886- // NOTE: intentionally doesn't pass crate name to avoid having
887- // different primitive links between crates
888- if UnstableFeatures :: from_environment ( None ) . is_nightly_build ( ) {
889- "https://doc.rust-lang.org/nightly"
890- } else {
891- "https://doc.rust-lang.org"
892- } ,
893- ) ,
894- } ;
895- // This is a primitive so the url is done "by hand".
896- let tail = fragment. find ( '#' ) . unwrap_or_else ( || fragment. len ( ) ) ;
897- Some ( RenderedLink {
898- original_text : s. clone ( ) ,
899- new_text : link_text. clone ( ) ,
900- href : format ! (
901- "{}{}std/primitive.{}.html{}" ,
902- url,
903- if !url. ends_with( '/' ) { "/" } else { "" } ,
904- & fragment[ ..tail] ,
905- & fragment[ tail..]
906- ) ,
907- } )
908- } else {
909- panic ! ( "This isn't a primitive?!" ) ;
910- }
911- }
912- }
913- } )
914- . collect ( )
915- }
916-
917910 crate fn get_doc_aliases ( & self ) -> Box < [ String ] > {
918911 let mut aliases = FxHashSet :: default ( ) ;
919912
@@ -940,7 +933,6 @@ impl PartialEq for Attributes {
940933 self . doc_strings == rhs. doc_strings
941934 && self . cfg == rhs. cfg
942935 && self . span == rhs. span
943- && self . links == rhs. links
944936 && self
945937 . other_attrs
946938 . iter ( )
@@ -956,7 +948,6 @@ impl Hash for Attributes {
956948 self . doc_strings . hash ( hasher) ;
957949 self . cfg . hash ( hasher) ;
958950 self . span . hash ( hasher) ;
959- self . links . hash ( hasher) ;
960951 for attr in & self . other_attrs {
961952 attr. id . hash ( hasher) ;
962953 }
0 commit comments