@@ -46,6 +46,7 @@ use std::rc::Rc;
46
46
use std:: str;
47
47
use std:: string:: ToString ;
48
48
49
+ use askama:: Template ;
49
50
use rustc_ast_pretty:: pprust;
50
51
use rustc_attr:: { ConstStability , Deprecation , StabilityLevel } ;
51
52
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
@@ -418,7 +419,7 @@ fn document(
418
419
if let Some ( ref name) = item. name {
419
420
info ! ( "Documenting {}" , name) ;
420
421
}
421
- document_item_info ( w , cx, item, parent) ;
422
+ document_item_info ( cx, item, parent) . render_into ( w ) . unwrap ( ) ;
422
423
if parent. is_none ( ) {
423
424
document_full_collapsible ( w, item, cx, heading_offset) ;
424
425
} else {
@@ -460,7 +461,7 @@ fn document_short(
460
461
parent : & clean:: Item ,
461
462
show_def_docs : bool ,
462
463
) {
463
- document_item_info ( w , cx, item, Some ( parent) ) ;
464
+ document_item_info ( cx, item, Some ( parent) ) . render_into ( w ) . unwrap ( ) ;
464
465
if !show_def_docs {
465
466
return ;
466
467
}
@@ -532,25 +533,23 @@ fn document_full_inner(
532
533
}
533
534
}
534
535
536
+ #[ derive( Template ) ]
537
+ #[ template( path = "item_info.html" ) ]
538
+ struct ItemInfo {
539
+ items : Vec < ShortItemInfo > ,
540
+ }
535
541
/// Add extra information about an item such as:
536
542
///
537
543
/// * Stability
538
544
/// * Deprecated
539
545
/// * Required features (through the `doc_cfg` feature)
540
546
fn document_item_info (
541
- w : & mut Buffer ,
542
547
cx : & mut Context < ' _ > ,
543
548
item : & clean:: Item ,
544
549
parent : Option < & clean:: Item > ,
545
- ) {
546
- let item_infos = short_item_info ( item, cx, parent) ;
547
- if !item_infos. is_empty ( ) {
548
- w. write_str ( "<span class=\" item-info\" >" ) ;
549
- for info in item_infos {
550
- w. write_str ( & info) ;
551
- }
552
- w. write_str ( "</span>" ) ;
553
- }
550
+ ) -> ItemInfo {
551
+ let items = short_item_info ( item, cx, parent) ;
552
+ ItemInfo { items }
554
553
}
555
554
556
555
fn portability ( item : & clean:: Item , parent : Option < & clean:: Item > ) -> Option < String > {
@@ -568,7 +567,25 @@ fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option<Strin
568
567
cfg
569
568
) ;
570
569
571
- Some ( format ! ( "<div class=\" stab portability\" >{}</div>" , cfg?. render_long_html( ) ) )
570
+ Some ( cfg?. render_long_html ( ) )
571
+ }
572
+
573
+ #[ derive( Template ) ]
574
+ #[ template( path = "short_item_info.html" ) ]
575
+ enum ShortItemInfo {
576
+ /// A message describing the deprecation of this item
577
+ Deprecation {
578
+ message : String ,
579
+ } ,
580
+ /// The feature corresponding to an unstable item, and optionally
581
+ /// a tracking issue URL and number.
582
+ Unstable {
583
+ feature : String ,
584
+ tracking : Option < ( String , u32 ) > ,
585
+ } ,
586
+ Portability {
587
+ message : String ,
588
+ } ,
572
589
}
573
590
574
591
/// Render the stability, deprecation and portability information that is displayed at the top of
@@ -577,7 +594,7 @@ fn short_item_info(
577
594
item : & clean:: Item ,
578
595
cx : & mut Context < ' _ > ,
579
596
parent : Option < & clean:: Item > ,
580
- ) -> Vec < String > {
597
+ ) -> Vec < ShortItemInfo > {
581
598
let mut extra_info = vec ! [ ] ;
582
599
583
600
if let Some ( depr @ Deprecation { note, since, is_since_rustc_version : _, suggestion : _ } ) =
@@ -603,15 +620,10 @@ fn short_item_info(
603
620
if let Some ( note) = note {
604
621
let note = note. as_str ( ) ;
605
622
let html = MarkdownItemInfo ( note, & mut cx. id_map ) ;
606
- message. push_str ( & format ! ( ": {}" , html. into_string( ) ) ) ;
623
+ message. push_str ( ": " ) ;
624
+ message. push_str ( & html. into_string ( ) ) ;
607
625
}
608
- extra_info. push ( format ! (
609
- "<div class=\" stab deprecated\" >\
610
- <span class=\" emoji\" >👎</span>\
611
- <span>{}</span>\
612
- </div>",
613
- message,
614
- ) ) ;
626
+ extra_info. push ( ShortItemInfo :: Deprecation { message } ) ;
615
627
}
616
628
617
629
// Render unstable items. But don't render "rustc_private" crates (internal compiler crates).
@@ -622,26 +634,17 @@ fn short_item_info(
622
634
. filter ( |stab| stab. feature != sym:: rustc_private)
623
635
. map ( |stab| ( stab. level , stab. feature ) )
624
636
{
625
- let mut message = "<span class=\" emoji\" >🔬</span>\
626
- <span>This is a nightly-only experimental API."
627
- . to_owned ( ) ;
628
-
629
- let mut feature = format ! ( "<code>{}</code>" , Escape ( feature. as_str( ) ) ) ;
630
- if let ( Some ( url) , Some ( issue) ) = ( & cx. shared . issue_tracker_base_url , issue) {
631
- feature. push_str ( & format ! (
632
- " <a href=\" {url}{issue}\" >#{issue}</a>" ,
633
- url = url,
634
- issue = issue
635
- ) ) ;
636
- }
637
-
638
- message. push_str ( & format ! ( " ({})</span>" , feature) ) ;
639
-
640
- extra_info. push ( format ! ( "<div class=\" stab unstable\" >{}</div>" , message) ) ;
637
+ let tracking = if let ( Some ( url) , Some ( issue) ) = ( & cx. shared . issue_tracker_base_url , issue)
638
+ {
639
+ Some ( ( url. clone ( ) , issue. get ( ) ) )
640
+ } else {
641
+ None
642
+ } ;
643
+ extra_info. push ( ShortItemInfo :: Unstable { feature : feature. to_string ( ) , tracking } ) ;
641
644
}
642
645
643
- if let Some ( portability ) = portability ( item, parent) {
644
- extra_info. push ( portability ) ;
646
+ if let Some ( message ) = portability ( item, parent) {
647
+ extra_info. push ( ShortItemInfo :: Portability { message } ) ;
645
648
}
646
649
647
650
extra_info
@@ -1473,7 +1476,9 @@ fn render_impl(
1473
1476
// We need the stability of the item from the trait
1474
1477
// because impls can't have a stability.
1475
1478
if item. doc_value ( ) . is_some ( ) {
1476
- document_item_info ( & mut info_buffer, cx, it, Some ( parent) ) ;
1479
+ document_item_info ( cx, it, Some ( parent) )
1480
+ . render_into ( & mut info_buffer)
1481
+ . unwrap ( ) ;
1477
1482
document_full ( & mut doc_buffer, item, cx, HeadingOffset :: H5 ) ;
1478
1483
short_documented = false ;
1479
1484
} else {
@@ -1490,7 +1495,9 @@ fn render_impl(
1490
1495
}
1491
1496
}
1492
1497
} else {
1493
- document_item_info ( & mut info_buffer, cx, item, Some ( parent) ) ;
1498
+ document_item_info ( cx, item, Some ( parent) )
1499
+ . render_into ( & mut info_buffer)
1500
+ . unwrap ( ) ;
1494
1501
if rendering_params. show_def_docs {
1495
1502
document_full ( & mut doc_buffer, item, cx, HeadingOffset :: H5 ) ;
1496
1503
short_documented = false ;
@@ -1863,7 +1870,11 @@ pub(crate) fn render_impl_summary(
1863
1870
let is_trait = inner_impl. trait_ . is_some ( ) ;
1864
1871
if is_trait {
1865
1872
if let Some ( portability) = portability ( & i. impl_item , Some ( parent) ) {
1866
- write ! ( w, "<span class=\" item-info\" >{}</span>" , portability) ;
1873
+ write ! (
1874
+ w,
1875
+ "<span class=\" item-info\" ><div class=\" stab portability\" >{}</div></span>" ,
1876
+ portability
1877
+ ) ;
1867
1878
}
1868
1879
}
1869
1880
0 commit comments