@@ -195,7 +195,69 @@ impl Item {
195195 }
196196
197197 crate fn links ( & self , cache : & Cache ) -> Vec < RenderedLink > {
198- self . attrs . links ( self . def_id . krate , cache)
198+ use crate :: html:: format:: href;
199+ use crate :: html:: render:: CURRENT_DEPTH ;
200+
201+ cache
202+ . intra_doc_links
203+ . get ( & self . def_id )
204+ . map_or ( & [ ] [ ..] , |v| v. as_slice ( ) )
205+ . iter ( )
206+ . filter_map ( |ItemLink { link : s, link_text, did, fragment } | {
207+ match * did {
208+ Some ( did) => {
209+ if let Some ( ( mut href, ..) ) = href ( did, cache) {
210+ if let Some ( ref fragment) = * fragment {
211+ href. push ( '#' ) ;
212+ href. push_str ( fragment) ;
213+ }
214+ Some ( RenderedLink {
215+ original_text : s. clone ( ) ,
216+ new_text : link_text. clone ( ) ,
217+ href,
218+ } )
219+ } else {
220+ None
221+ }
222+ }
223+ None => {
224+ if let Some ( ref fragment) = * fragment {
225+ let url = match cache. extern_locations . get ( & self . def_id . krate ) {
226+ Some ( & ( _, _, ExternalLocation :: Local ) ) => {
227+ let depth = CURRENT_DEPTH . with ( |l| l. get ( ) ) ;
228+ "../" . repeat ( depth)
229+ }
230+ Some ( & ( _, _, ExternalLocation :: Remote ( ref s) ) ) => s. to_string ( ) ,
231+ Some ( & ( _, _, ExternalLocation :: Unknown ) ) | None => String :: from (
232+ // NOTE: intentionally doesn't pass crate name to avoid having
233+ // different primitive links between crates
234+ if UnstableFeatures :: from_environment ( None ) . is_nightly_build ( ) {
235+ "https://doc.rust-lang.org/nightly"
236+ } else {
237+ "https://doc.rust-lang.org"
238+ } ,
239+ ) ,
240+ } ;
241+ // This is a primitive so the url is done "by hand".
242+ let tail = fragment. find ( '#' ) . unwrap_or_else ( || fragment. len ( ) ) ;
243+ Some ( RenderedLink {
244+ original_text : s. clone ( ) ,
245+ new_text : link_text. clone ( ) ,
246+ href : format ! (
247+ "{}{}std/primitive.{}.html{}" ,
248+ url,
249+ if !url. ends_with( '/' ) { "/" } else { "" } ,
250+ & fragment[ ..tail] ,
251+ & fragment[ tail..]
252+ ) ,
253+ } )
254+ } else {
255+ panic ! ( "This isn't a primitive?!" ) ;
256+ }
257+ }
258+ }
259+ } )
260+ . collect ( )
199261 }
200262
201263 crate fn is_crate ( & self ) -> bool {
@@ -572,15 +634,13 @@ crate struct Attributes {
572634 crate other_attrs : Vec < ast:: Attribute > ,
573635 crate cfg : Option < Arc < Cfg > > ,
574636 crate span : Option < rustc_span:: Span > ,
575- /// map from Rust paths to resolved defs and potential URL fragments
576- crate links : Vec < ItemLink > ,
577637 crate inner_docs : bool ,
578638}
579639
580640#[ derive( Clone , Debug , Default , PartialEq , Eq , Hash ) ]
581641/// A link that has not yet been rendered.
582642///
583- /// This link will be turned into a rendered link by [`Attributes ::links`]
643+ /// This link will be turned into a rendered link by [`Item ::links`].
584644crate struct ItemLink {
585645 /// The original link written in the markdown
586646 pub ( crate ) link : String ,
@@ -806,7 +866,6 @@ impl Attributes {
806866 other_attrs,
807867 cfg : if cfg == Cfg :: True { None } else { Some ( Arc :: new ( cfg) ) } ,
808868 span : sp,
809- links : vec ! [ ] ,
810869 inner_docs,
811870 }
812871 }
@@ -850,72 +909,6 @@ impl Attributes {
850909 if self . doc_strings . is_empty ( ) { None } else { Some ( self . doc_strings . iter ( ) . collect ( ) ) }
851910 }
852911
853- /// Gets links as a vector
854- ///
855- /// Cache must be populated before call
856- crate fn links ( & self , krate : CrateNum , cache : & Cache ) -> Vec < RenderedLink > {
857- use crate :: html:: format:: href;
858- use crate :: html:: render:: CURRENT_DEPTH ;
859-
860- self . links
861- . iter ( )
862- . filter_map ( |ItemLink { link : s, link_text, did, fragment } | {
863- match * did {
864- Some ( did) => {
865- if let Some ( ( mut href, ..) ) = href ( did, cache) {
866- if let Some ( ref fragment) = * fragment {
867- href. push ( '#' ) ;
868- href. push_str ( fragment) ;
869- }
870- Some ( RenderedLink {
871- original_text : s. clone ( ) ,
872- new_text : link_text. clone ( ) ,
873- href,
874- } )
875- } else {
876- None
877- }
878- }
879- None => {
880- if let Some ( ref fragment) = * fragment {
881- let url = match cache. extern_locations . get ( & krate) {
882- Some ( & ( _, _, ExternalLocation :: Local ) ) => {
883- let depth = CURRENT_DEPTH . with ( |l| l. get ( ) ) ;
884- "../" . repeat ( depth)
885- }
886- Some ( & ( _, _, ExternalLocation :: Remote ( ref s) ) ) => s. to_string ( ) ,
887- Some ( & ( _, _, ExternalLocation :: Unknown ) ) | None => String :: from (
888- // NOTE: intentionally doesn't pass crate name to avoid having
889- // different primitive links between crates
890- if UnstableFeatures :: from_environment ( None ) . is_nightly_build ( ) {
891- "https://doc.rust-lang.org/nightly"
892- } else {
893- "https://doc.rust-lang.org"
894- } ,
895- ) ,
896- } ;
897- // This is a primitive so the url is done "by hand".
898- let tail = fragment. find ( '#' ) . unwrap_or_else ( || fragment. len ( ) ) ;
899- Some ( RenderedLink {
900- original_text : s. clone ( ) ,
901- new_text : link_text. clone ( ) ,
902- href : format ! (
903- "{}{}std/primitive.{}.html{}" ,
904- url,
905- if !url. ends_with( '/' ) { "/" } else { "" } ,
906- & fragment[ ..tail] ,
907- & fragment[ tail..]
908- ) ,
909- } )
910- } else {
911- panic ! ( "This isn't a primitive?!" ) ;
912- }
913- }
914- }
915- } )
916- . collect ( )
917- }
918-
919912 crate fn get_doc_aliases ( & self ) -> Box < [ String ] > {
920913 let mut aliases = FxHashSet :: default ( ) ;
921914
@@ -942,7 +935,6 @@ impl PartialEq for Attributes {
942935 self . doc_strings == rhs. doc_strings
943936 && self . cfg == rhs. cfg
944937 && self . span == rhs. span
945- && self . links == rhs. links
946938 && self
947939 . other_attrs
948940 . iter ( )
@@ -958,7 +950,6 @@ impl Hash for Attributes {
958950 self . doc_strings . hash ( hasher) ;
959951 self . cfg . hash ( hasher) ;
960952 self . span . hash ( hasher) ;
961- self . links . hash ( hasher) ;
962953 for attr in & self . other_attrs {
963954 attr. id . hash ( hasher) ;
964955 }
0 commit comments