@@ -40,6 +40,7 @@ use crate::core::DocContext;
40
40
use crate :: formats:: cache:: Cache ;
41
41
use crate :: formats:: item_type:: ItemType ;
42
42
use crate :: html:: render:: cache:: ExternalLocation ;
43
+ use crate :: passes:: collect_intra_doc_links:: EarlyIntraDocLink ;
43
44
44
45
use self :: FnRetTy :: * ;
45
46
use self :: ItemKind :: * ;
@@ -192,8 +193,74 @@ impl Item {
192
193
self . attrs . collapsed_doc_value ( )
193
194
}
194
195
196
+ crate fn resolved_links < ' c > ( & self , cache : & ' c Cache ) -> impl Iterator < Item = & ' c ItemLink > {
197
+ cache. intra_doc_links . get ( & self . def_id ) . map_or ( & [ ] [ ..] , |v| v. as_slice ( ) ) . iter ( ) . map (
198
+ |early_link| match early_link {
199
+ EarlyIntraDocLink :: Resolved ( item_link) => item_link,
200
+ } ,
201
+ )
202
+ }
203
+
195
204
crate fn links ( & self , cache : & Cache ) -> Vec < RenderedLink > {
196
- self . attrs . links ( self . def_id . krate , cache)
205
+ use crate :: html:: format:: href;
206
+ use crate :: html:: render:: CURRENT_DEPTH ;
207
+
208
+ self . resolved_links ( cache)
209
+ . filter_map ( |ItemLink { link : s, link_text, did, fragment } | {
210
+ match * did {
211
+ Some ( did) => {
212
+ if let Some ( ( mut href, ..) ) = href ( did, cache) {
213
+ if let Some ( ref fragment) = * fragment {
214
+ href. push ( '#' ) ;
215
+ href. push_str ( fragment) ;
216
+ }
217
+ Some ( RenderedLink {
218
+ original_text : s. clone ( ) ,
219
+ new_text : link_text. clone ( ) ,
220
+ href,
221
+ } )
222
+ } else {
223
+ None
224
+ }
225
+ }
226
+ None => {
227
+ if let Some ( ref fragment) = * fragment {
228
+ let url = match cache. extern_locations . get ( & self . def_id . krate ) {
229
+ Some ( & ( _, _, ExternalLocation :: Local ) ) => {
230
+ let depth = CURRENT_DEPTH . with ( |l| l. get ( ) ) ;
231
+ "../" . repeat ( depth)
232
+ }
233
+ Some ( & ( _, _, ExternalLocation :: Remote ( ref s) ) ) => s. to_string ( ) ,
234
+ Some ( & ( _, _, ExternalLocation :: Unknown ) ) | None => String :: from (
235
+ // NOTE: intentionally doesn't pass crate name to avoid having
236
+ // different primitive links between crates
237
+ if UnstableFeatures :: from_environment ( None ) . is_nightly_build ( ) {
238
+ "https://doc.rust-lang.org/nightly"
239
+ } else {
240
+ "https://doc.rust-lang.org"
241
+ } ,
242
+ ) ,
243
+ } ;
244
+ // This is a primitive so the url is done "by hand".
245
+ let tail = fragment. find ( '#' ) . unwrap_or_else ( || fragment. len ( ) ) ;
246
+ Some ( RenderedLink {
247
+ original_text : s. clone ( ) ,
248
+ new_text : link_text. clone ( ) ,
249
+ href : format ! (
250
+ "{}{}std/primitive.{}.html{}" ,
251
+ url,
252
+ if !url. ends_with( '/' ) { "/" } else { "" } ,
253
+ & fragment[ ..tail] ,
254
+ & fragment[ tail..]
255
+ ) ,
256
+ } )
257
+ } else {
258
+ panic ! ( "This isn't a primitive?!" ) ;
259
+ }
260
+ }
261
+ }
262
+ } )
263
+ . collect ( )
197
264
}
198
265
199
266
crate fn is_crate ( & self ) -> bool {
@@ -570,8 +637,6 @@ crate struct Attributes {
570
637
crate other_attrs : Vec < ast:: Attribute > ,
571
638
crate cfg : Option < Arc < Cfg > > ,
572
639
crate span : Option < rustc_span:: Span > ,
573
- /// map from Rust paths to resolved defs and potential URL fragments
574
- crate links : Vec < ItemLink > ,
575
640
crate inner_docs : bool ,
576
641
}
577
642
@@ -804,7 +869,6 @@ impl Attributes {
804
869
other_attrs,
805
870
cfg : if cfg == Cfg :: True { None } else { Some ( Arc :: new ( cfg) ) } ,
806
871
span : sp,
807
- links : vec ! [ ] ,
808
872
inner_docs,
809
873
}
810
874
}
@@ -848,72 +912,6 @@ impl Attributes {
848
912
if self . doc_strings . is_empty ( ) { None } else { Some ( self . doc_strings . iter ( ) . collect ( ) ) }
849
913
}
850
914
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
-
917
915
crate fn get_doc_aliases ( & self ) -> FxHashSet < String > {
918
916
let mut aliases = FxHashSet :: default ( ) ;
919
917
@@ -940,7 +938,6 @@ impl PartialEq for Attributes {
940
938
self . doc_strings == rhs. doc_strings
941
939
&& self . cfg == rhs. cfg
942
940
&& self . span == rhs. span
943
- && self . links == rhs. links
944
941
&& self
945
942
. other_attrs
946
943
. iter ( )
@@ -956,7 +953,6 @@ impl Hash for Attributes {
956
953
self . doc_strings . hash ( hasher) ;
957
954
self . cfg . hash ( hasher) ;
958
955
self . span . hash ( hasher) ;
959
- self . links . hash ( hasher) ;
960
956
for attr in & self . other_attrs {
961
957
attr. id . hash ( hasher) ;
962
958
}
0 commit comments