@@ -64,14 +64,20 @@ pub(crate) struct Link<'a> {
64
64
name : Cow < ' a , str > ,
65
65
/// The id of an anchor within the page (without a `#` prefix)
66
66
href : Cow < ' a , str > ,
67
+ /// Whether the item is deprecated
68
+ is_deprecated : bool ,
67
69
}
68
70
69
71
impl < ' a > Link < ' a > {
70
- pub fn new ( href : impl Into < Cow < ' a , str > > , name : impl Into < Cow < ' a , str > > ) -> Self {
71
- Self { href : href. into ( ) , name : name. into ( ) }
72
+ pub fn new (
73
+ href : impl Into < Cow < ' a , str > > ,
74
+ name : impl Into < Cow < ' a , str > > ,
75
+ deprecated : bool ,
76
+ ) -> Self {
77
+ Self { href : href. into ( ) , name : name. into ( ) , is_deprecated : deprecated }
72
78
}
73
79
pub fn empty ( ) -> Link < ' static > {
74
- Link :: new ( "" , "" )
80
+ Link :: new ( "" , "" , false )
75
81
}
76
82
}
77
83
@@ -124,12 +130,14 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf
124
130
sidebar. render_into ( buffer) . unwrap ( ) ;
125
131
}
126
132
127
- fn get_struct_fields_name < ' a > ( fields : & ' a [ clean:: Item ] ) -> Vec < Link < ' a > > {
133
+ fn get_struct_fields_name < ' a > ( fields : & ' a [ clean:: Item ] , tcx : TyCtxt < ' _ > ) -> Vec < Link < ' a > > {
128
134
let mut fields = fields
129
135
. iter ( )
130
136
. filter ( |f| matches ! ( * f. kind, clean:: StructFieldItem ( ..) ) )
131
137
. filter_map ( |f| {
132
- f. name . as_ref ( ) . map ( |name| Link :: new ( format ! ( "structfield.{name}" ) , name. as_str ( ) ) )
138
+ f. name . as_ref ( ) . map ( |name| {
139
+ Link :: new ( format ! ( "structfield.{name}" ) , name. as_str ( ) , f. is_deprecated ( tcx) )
140
+ } )
133
141
} )
134
142
. collect :: < Vec < Link < ' a > > > ( ) ;
135
143
fields. sort ( ) ;
@@ -141,15 +149,15 @@ fn sidebar_struct<'a>(
141
149
it : & ' a clean:: Item ,
142
150
s : & ' a clean:: Struct ,
143
151
) -> Vec < LinkBlock < ' a > > {
144
- let fields = get_struct_fields_name ( & s. fields ) ;
152
+ let fields = get_struct_fields_name ( & s. fields , cx . tcx ( ) ) ;
145
153
let field_name = match s. ctor_kind {
146
154
Some ( CtorKind :: Fn ) => Some ( "Tuple Fields" ) ,
147
155
None => Some ( "Fields" ) ,
148
156
_ => None ,
149
157
} ;
150
158
let mut items = vec ! [ ] ;
151
159
if let Some ( name) = field_name {
152
- items. push ( LinkBlock :: new ( Link :: new ( "fields" , name) , fields) ) ;
160
+ items. push ( LinkBlock :: new ( Link :: new ( "fields" , name, false ) , fields) ) ;
153
161
}
154
162
sidebar_assoc_items ( cx, it, & mut items) ;
155
163
items
@@ -164,35 +172,39 @@ fn sidebar_trait<'a>(
164
172
items : & ' a [ clean:: Item ] ,
165
173
filt : impl Fn ( & clean:: Item ) -> bool ,
166
174
ty : & str ,
175
+ tcx : TyCtxt < ' _ > ,
167
176
) -> Vec < Link < ' a > > {
168
177
let mut res = items
169
178
. iter ( )
170
179
. filter_map ( |m : & clean:: Item | match m. name {
171
- Some ( ref name) if filt ( m) => Some ( Link :: new ( format ! ( "{ty}.{name}" ) , name. as_str ( ) ) ) ,
180
+ Some ( ref name) if filt ( m) => {
181
+ Some ( Link :: new ( format ! ( "{ty}.{name}" ) , name. as_str ( ) , m. is_deprecated ( tcx) ) )
182
+ }
172
183
_ => None ,
173
184
} )
174
185
. collect :: < Vec < Link < ' a > > > ( ) ;
175
186
res. sort ( ) ;
176
187
res
177
188
}
178
189
179
- let req_assoc = filter_items ( & t. items , |m| m. is_ty_associated_type ( ) , "associatedtype" ) ;
180
- let prov_assoc = filter_items ( & t. items , |m| m. is_associated_type ( ) , "associatedtype" ) ;
190
+ let tcx = cx. tcx ( ) ;
191
+
192
+ let req_assoc = filter_items ( & t. items , |m| m. is_ty_associated_type ( ) , "associatedtype" , tcx) ;
193
+ let prov_assoc = filter_items ( & t. items , |m| m. is_associated_type ( ) , "associatedtype" , tcx) ;
181
194
let req_assoc_const =
182
- filter_items ( & t. items , |m| m. is_ty_associated_const ( ) , "associatedconstant" ) ;
195
+ filter_items ( & t. items , |m| m. is_ty_associated_const ( ) , "associatedconstant" , tcx ) ;
183
196
let prov_assoc_const =
184
- filter_items ( & t. items , |m| m. is_associated_const ( ) , "associatedconstant" ) ;
185
- let req_method = filter_items ( & t. items , |m| m. is_ty_method ( ) , "tymethod" ) ;
186
- let prov_method = filter_items ( & t. items , |m| m. is_method ( ) , "method" ) ;
197
+ filter_items ( & t. items , |m| m. is_associated_const ( ) , "associatedconstant" , tcx ) ;
198
+ let req_method = filter_items ( & t. items , |m| m. is_ty_method ( ) , "tymethod" , tcx ) ;
199
+ let prov_method = filter_items ( & t. items , |m| m. is_method ( ) , "method" , tcx ) ;
187
200
let mut foreign_impls = vec ! [ ] ;
188
201
if let Some ( implementors) = cx. cache ( ) . implementors . get ( & it. item_id . expect_def_id ( ) ) {
189
- foreign_impls. extend (
190
- implementors
191
- . iter ( )
192
- . filter ( |i| !i. is_on_local_type ( cx) )
193
- . filter_map ( |i| super :: extract_for_impl_name ( & i. impl_item , cx) )
194
- . map ( |( name, id) | Link :: new ( id, name) ) ,
195
- ) ;
202
+ foreign_impls. extend ( implementors. iter ( ) . filter ( |i| !i. is_on_local_type ( cx) ) . filter_map (
203
+ |i| {
204
+ super :: extract_for_impl_name ( & i. impl_item , cx)
205
+ . map ( |( name, id) | Link :: new ( id, name, i. impl_item . is_deprecated ( tcx) ) )
206
+ } ,
207
+ ) ) ;
196
208
foreign_impls. sort ( ) ;
197
209
}
198
210
@@ -206,12 +218,16 @@ fn sidebar_trait<'a>(
206
218
( "foreign-impls" , "Implementations on Foreign Types" , foreign_impls) ,
207
219
]
208
220
. into_iter ( )
209
- . map ( |( id, title, items) | LinkBlock :: new ( Link :: new ( id, title) , items) )
221
+ . map ( |( id, title, items) | LinkBlock :: new ( Link :: new ( id, title, false ) , items) )
210
222
. collect ( ) ;
211
223
sidebar_assoc_items ( cx, it, & mut blocks) ;
212
- blocks. push ( LinkBlock :: forced ( Link :: new ( "implementors" , "Implementors" ) ) ) ;
224
+ blocks. push ( LinkBlock :: forced ( Link :: new ( "implementors" , "Implementors" , false ) ) ) ;
213
225
if t. is_auto ( cx. tcx ( ) ) {
214
- blocks. push ( LinkBlock :: forced ( Link :: new ( "synthetic-implementors" , "Auto Implementors" ) ) ) ;
226
+ blocks. push ( LinkBlock :: forced ( Link :: new (
227
+ "synthetic-implementors" ,
228
+ "Auto Implementors" ,
229
+ false ,
230
+ ) ) ) ;
215
231
}
216
232
blocks
217
233
}
@@ -241,8 +257,8 @@ fn sidebar_union<'a>(
241
257
it : & ' a clean:: Item ,
242
258
u : & ' a clean:: Union ,
243
259
) -> Vec < LinkBlock < ' a > > {
244
- let fields = get_struct_fields_name ( & u. fields ) ;
245
- let mut items = vec ! [ LinkBlock :: new( Link :: new( "fields" , "Fields" ) , fields) ] ;
260
+ let fields = get_struct_fields_name ( & u. fields , cx . tcx ( ) ) ;
261
+ let mut items = vec ! [ LinkBlock :: new( Link :: new( "fields" , "Fields" , false ) , fields) ] ;
246
262
sidebar_assoc_items ( cx, it, & mut items) ;
247
263
items
248
264
}
@@ -253,6 +269,7 @@ fn sidebar_assoc_items<'a>(
253
269
it : & ' a clean:: Item ,
254
270
links : & mut Vec < LinkBlock < ' a > > ,
255
271
) {
272
+ let tcx = cx. tcx ( ) ;
256
273
let did = it. item_id . expect_def_id ( ) ;
257
274
let cache = cx. cache ( ) ;
258
275
@@ -267,7 +284,7 @@ fn sidebar_assoc_items<'a>(
267
284
assoc_consts. extend (
268
285
v. iter ( )
269
286
. filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
270
- . flat_map ( |i| get_associated_constants ( i. inner_impl ( ) , used_links_bor) ) ,
287
+ . flat_map ( |i| get_associated_constants ( i. inner_impl ( ) , used_links_bor, tcx ) ) ,
271
288
) ;
272
289
// We want links' order to be reproducible so we don't use unstable sort.
273
290
assoc_consts. sort ( ) ;
@@ -311,8 +328,11 @@ fn sidebar_assoc_items<'a>(
311
328
} ;
312
329
313
330
let mut blocks = vec ! [
314
- LinkBlock :: new( Link :: new( "implementations" , "Associated Constants" ) , assoc_consts) ,
315
- LinkBlock :: new( Link :: new( "implementations" , "Methods" ) , methods) ,
331
+ LinkBlock :: new(
332
+ Link :: new( "implementations" , "Associated Constants" , false ) ,
333
+ assoc_consts,
334
+ ) ,
335
+ LinkBlock :: new( Link :: new( "implementations" , "Methods" , false ) , methods) ,
316
336
] ;
317
337
blocks. append ( & mut deref_methods) ;
318
338
blocks. extend ( [ concrete, synthetic, blanket] ) ;
@@ -329,13 +349,16 @@ fn sidebar_deref_methods<'a>(
329
349
used_links : & mut FxHashSet < String > ,
330
350
) {
331
351
let c = cx. cache ( ) ;
352
+ let tcx = cx. tcx ( ) ;
332
353
333
354
debug ! ( "found Deref: {:?}" , impl_) ;
334
- if let Some ( ( target, real_target) ) =
355
+ if let Some ( ( target, real_target, target_is_deprecated ) ) =
335
356
impl_. inner_impl ( ) . items . iter ( ) . find_map ( |item| match * item. kind {
336
357
clean:: AssocTypeItem ( box ref t, _) => Some ( match * t {
337
- clean:: Typedef { item_type : Some ( ref type_) , .. } => ( type_, & t. type_ ) ,
338
- _ => ( & t. type_ , & t. type_ ) ,
358
+ clean:: Typedef { item_type : Some ( ref type_) , .. } => {
359
+ ( type_, & t. type_ , item. is_deprecated ( tcx) )
360
+ }
361
+ _ => ( & t. type_ , & t. type_ , item. is_deprecated ( tcx) ) ,
339
362
} ) ,
340
363
_ => None ,
341
364
} )
@@ -349,7 +372,7 @@ fn sidebar_deref_methods<'a>(
349
372
// Avoid infinite cycles
350
373
return ;
351
374
}
352
- let deref_mut = v. iter ( ) . any ( |i| i. trait_did ( ) == cx . tcx ( ) . lang_items ( ) . deref_mut_trait ( ) ) ;
375
+ let deref_mut = v. iter ( ) . any ( |i| i. trait_did ( ) == tcx. lang_items ( ) . deref_mut_trait ( ) ) ;
353
376
let inner_impl = target
354
377
. def_id ( c)
355
378
. or_else ( || {
@@ -361,7 +384,7 @@ fn sidebar_deref_methods<'a>(
361
384
let mut ret = impls
362
385
. iter ( )
363
386
. filter ( |i| i. inner_impl ( ) . trait_ . is_none ( ) )
364
- . flat_map ( |i| get_methods ( i. inner_impl ( ) , true , used_links, deref_mut, cx . tcx ( ) ) )
387
+ . flat_map ( |i| get_methods ( i. inner_impl ( ) , true , used_links, deref_mut, tcx) )
365
388
. collect :: < Vec < _ > > ( ) ;
366
389
if !ret. is_empty ( ) {
367
390
let id = if let Some ( target_def_id) = real_target. def_id ( c) {
@@ -381,7 +404,7 @@ fn sidebar_deref_methods<'a>(
381
404
) ;
382
405
// We want links' order to be reproducible so we don't use unstable sort.
383
406
ret. sort ( ) ;
384
- out. push ( LinkBlock :: new ( Link :: new ( id, title) , ret) ) ;
407
+ out. push ( LinkBlock :: new ( Link :: new ( id, title, target_is_deprecated ) , ret) ) ;
385
408
}
386
409
}
387
410
@@ -392,7 +415,7 @@ fn sidebar_deref_methods<'a>(
392
415
i. inner_impl ( )
393
416
. trait_
394
417
. as_ref ( )
395
- . map ( |t| Some ( t. def_id ( ) ) == cx . tcx ( ) . lang_items ( ) . deref_trait ( ) )
418
+ . map ( |t| Some ( t. def_id ( ) ) == tcx. lang_items ( ) . deref_trait ( ) )
396
419
. unwrap_or ( false )
397
420
} )
398
421
{
@@ -413,14 +436,18 @@ fn sidebar_enum<'a>(
413
436
it : & ' a clean:: Item ,
414
437
e : & ' a clean:: Enum ,
415
438
) -> Vec < LinkBlock < ' a > > {
439
+ let tcx = cx. tcx ( ) ;
416
440
let mut variants = e
417
441
. variants ( )
418
- . filter_map ( |v| v. name )
419
- . map ( |name| Link :: new ( format ! ( "variant.{name}" ) , name. to_string ( ) ) )
442
+ . filter_map ( |v| {
443
+ v. name . map ( |name| {
444
+ Link :: new ( format ! ( "variant.{name}" ) , name. to_string ( ) , v. is_deprecated ( tcx) )
445
+ } )
446
+ } )
420
447
. collect :: < Vec < _ > > ( ) ;
421
448
variants. sort_unstable ( ) ;
422
449
423
- let mut items = vec ! [ LinkBlock :: new( Link :: new( "variants" , "Variants" ) , variants) ] ;
450
+ let mut items = vec ! [ LinkBlock :: new( Link :: new( "variants" , "Variants" , false ) , variants) ] ;
424
451
sidebar_assoc_items ( cx, it, & mut items) ;
425
452
items
426
453
}
@@ -432,7 +459,7 @@ pub(crate) fn sidebar_module_like(
432
459
. iter ( )
433
460
. copied ( )
434
461
. filter ( |sec| item_sections_in_use. contains ( sec) )
435
- . map ( |sec| Link :: new ( sec. id ( ) , sec. name ( ) ) )
462
+ . map ( |sec| Link :: new ( sec. id ( ) , sec. name ( ) , false ) )
436
463
. collect ( ) ;
437
464
LinkBlock :: new ( Link :: empty ( ) , item_sections)
438
465
}
@@ -470,6 +497,7 @@ fn sidebar_render_assoc_items(
470
497
synthetic : Vec < & Impl > ,
471
498
blanket_impl : Vec < & Impl > ,
472
499
) -> [ LinkBlock < ' static > ; 3 ] {
500
+ let tcx = cx. tcx ( ) ;
473
501
let format_impls = |impls : Vec < & Impl > , id_map : & mut IdMap | {
474
502
let mut links = FxHashSet :: default ( ) ;
475
503
@@ -484,7 +512,11 @@ fn sidebar_render_assoc_items(
484
512
ty:: ImplPolarity :: Positive | ty:: ImplPolarity :: Reservation => "" ,
485
513
ty:: ImplPolarity :: Negative => "!" ,
486
514
} ;
487
- let generated = Link :: new ( encoded, format ! ( "{prefix}{:#}" , trait_. print( cx) ) ) ;
515
+ let generated = Link :: new (
516
+ encoded,
517
+ format ! ( "{prefix}{:#}" , trait_. print( cx) ) ,
518
+ it. impl_item . is_deprecated ( tcx) ,
519
+ ) ;
488
520
if links. insert ( generated. clone ( ) ) { Some ( generated) } else { None }
489
521
} )
490
522
. collect :: < Vec < Link < ' static > > > ( ) ;
@@ -496,12 +528,18 @@ fn sidebar_render_assoc_items(
496
528
let synthetic = format_impls ( synthetic, id_map) ;
497
529
let blanket = format_impls ( blanket_impl, id_map) ;
498
530
[
499
- LinkBlock :: new ( Link :: new ( "trait-implementations" , "Trait Implementations" ) , concrete) ,
500
531
LinkBlock :: new (
501
- Link :: new ( "synthetic-implementations" , "Auto Trait Implementations" ) ,
532
+ Link :: new ( "trait-implementations" , "Trait Implementations" , false ) ,
533
+ concrete,
534
+ ) ,
535
+ LinkBlock :: new (
536
+ Link :: new ( "synthetic-implementations" , "Auto Trait Implementations" , false ) ,
502
537
synthetic,
503
538
) ,
504
- LinkBlock :: new ( Link :: new ( "blanket-implementations" , "Blanket Implementations" ) , blanket) ,
539
+ LinkBlock :: new (
540
+ Link :: new ( "blanket-implementations" , "Blanket Implementations" , false ) ,
541
+ blanket,
542
+ ) ,
505
543
]
506
544
}
507
545
@@ -531,6 +569,7 @@ fn get_methods<'a>(
531
569
Some ( Link :: new (
532
570
get_next_url ( used_links, format ! ( "{}.{}" , ItemType :: Method , name) ) ,
533
571
name. as_str ( ) ,
572
+ item. is_deprecated ( tcx) ,
534
573
) )
535
574
} else {
536
575
None
@@ -544,13 +583,15 @@ fn get_methods<'a>(
544
583
fn get_associated_constants < ' a > (
545
584
i : & ' a clean:: Impl ,
546
585
used_links : & mut FxHashSet < String > ,
586
+ tcx : TyCtxt < ' _ > ,
547
587
) -> Vec < Link < ' a > > {
548
588
i. items
549
589
. iter ( )
550
590
. filter_map ( |item| match item. name {
551
591
Some ( ref name) if !name. is_empty ( ) && item. is_associated_const ( ) => Some ( Link :: new (
552
592
get_next_url ( used_links, format ! ( "{}.{}" , ItemType :: AssocConst , name) ) ,
553
593
name. as_str ( ) ,
594
+ item. is_deprecated ( tcx) ,
554
595
) ) ,
555
596
_ => None ,
556
597
} )
0 commit comments