|
1 | 1 | use clean::AttributesExt;
|
2 | 2 |
|
| 3 | +use rustc_data_structures::captures::Captures; |
3 | 4 | use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
4 | 5 | use rustc_hir as hir;
|
5 | 6 | use rustc_hir::def::CtorKind;
|
@@ -28,8 +29,8 @@ use crate::formats::item_type::ItemType;
|
28 | 29 | use crate::formats::{AssocItemRender, Impl, RenderMode};
|
29 | 30 | use crate::html::escape::Escape;
|
30 | 31 | use crate::html::format::{
|
31 |
| - join_with_double_colon, print_abi_with_space, print_constness_with_space, print_where_clause, |
32 |
| - visibility_print_with_space, Buffer, Ending, PrintWithSpace, |
| 32 | + display_fn, join_with_double_colon, print_abi_with_space, print_constness_with_space, |
| 33 | + print_where_clause, visibility_print_with_space, Buffer, Ending, PrintWithSpace, |
33 | 34 | };
|
34 | 35 | use crate::html::layout::Page;
|
35 | 36 | use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
|
@@ -367,7 +368,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
|
367 | 368 | ..myitem.clone()
|
368 | 369 | };
|
369 | 370 |
|
370 |
| - let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx())); |
| 371 | + let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx()).to_string()); |
371 | 372 | stab_tags
|
372 | 373 | } else {
|
373 | 374 | None
|
@@ -461,42 +462,62 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
|
461 | 462 |
|
462 | 463 | /// Render the stability, deprecation and portability tags that are displayed in the item's summary
|
463 | 464 | /// at the module level.
|
464 |
| -fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) -> String { |
465 |
| - let mut tags = String::new(); |
466 |
| - |
467 |
| - fn tag_html(class: &str, title: &str, contents: &str) -> String { |
468 |
| - format!(r#"<span class="stab {}" title="{}">{}</span>"#, class, Escape(title), contents) |
469 |
| - } |
470 |
| - |
471 |
| - // The trailing space after each tag is to space it properly against the rest of the docs. |
472 |
| - if let Some(depr) = &item.deprecation(tcx) { |
473 |
| - let message = if stability::deprecation_in_effect(depr) { |
474 |
| - "Deprecated" |
475 |
| - } else { |
476 |
| - "Deprecation planned" |
477 |
| - }; |
478 |
| - tags += &tag_html("deprecated", "", message); |
479 |
| - } |
| 465 | +fn extra_info_tags<'a, 'tcx: 'a>( |
| 466 | + item: &'a clean::Item, |
| 467 | + parent: &'a clean::Item, |
| 468 | + tcx: TyCtxt<'tcx>, |
| 469 | +) -> impl fmt::Display + 'a + Captures<'tcx> { |
| 470 | + display_fn(move |f| { |
| 471 | + fn tag_html<'a>( |
| 472 | + class: &'a str, |
| 473 | + title: &'a str, |
| 474 | + contents: &'a str, |
| 475 | + ) -> impl fmt::Display + 'a { |
| 476 | + display_fn(move |f| { |
| 477 | + write!( |
| 478 | + f, |
| 479 | + r#"<span class="stab {}" title="{}">{}</span>"#, |
| 480 | + class, |
| 481 | + Escape(title), |
| 482 | + contents |
| 483 | + ) |
| 484 | + }) |
| 485 | + } |
480 | 486 |
|
481 |
| - // The "rustc_private" crates are permanently unstable so it makes no sense |
482 |
| - // to render "unstable" everywhere. |
483 |
| - if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private) |
484 |
| - == Some(true) |
485 |
| - { |
486 |
| - tags += &tag_html("unstable", "", "Experimental"); |
487 |
| - } |
| 487 | + // The trailing space after each tag is to space it properly against the rest of the docs. |
| 488 | + if let Some(depr) = &item.deprecation(tcx) { |
| 489 | + let message = if stability::deprecation_in_effect(depr) { |
| 490 | + "Deprecated" |
| 491 | + } else { |
| 492 | + "Deprecation planned" |
| 493 | + }; |
| 494 | + write!(f, "{}", tag_html("deprecated", "", message))?; |
| 495 | + } |
488 | 496 |
|
489 |
| - let cfg = match (&item.cfg, parent.cfg.as_ref()) { |
490 |
| - (Some(cfg), Some(parent_cfg)) => cfg.simplify_with(parent_cfg), |
491 |
| - (cfg, _) => cfg.as_deref().cloned(), |
492 |
| - }; |
| 497 | + // The "rustc_private" crates are permanently unstable so it makes no sense |
| 498 | + // to render "unstable" everywhere. |
| 499 | + if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private) |
| 500 | + == Some(true) |
| 501 | + { |
| 502 | + write!(f, "{}", tag_html("unstable", "", "Experimental"))?; |
| 503 | + } |
493 | 504 |
|
494 |
| - debug!("Portability name={:?} {:?} - {:?} = {:?}", item.name, item.cfg, parent.cfg, cfg); |
495 |
| - if let Some(ref cfg) = cfg { |
496 |
| - tags += &tag_html("portability", &cfg.render_long_plain(), &cfg.render_short_html()); |
497 |
| - } |
| 505 | + let cfg = match (&item.cfg, parent.cfg.as_ref()) { |
| 506 | + (Some(cfg), Some(parent_cfg)) => cfg.simplify_with(parent_cfg), |
| 507 | + (cfg, _) => cfg.as_deref().cloned(), |
| 508 | + }; |
498 | 509 |
|
499 |
| - tags |
| 510 | + debug!("Portability name={:?} {:?} - {:?} = {:?}", item.name, item.cfg, parent.cfg, cfg); |
| 511 | + if let Some(ref cfg) = cfg { |
| 512 | + write!( |
| 513 | + f, |
| 514 | + "{}", |
| 515 | + tag_html("portability", &cfg.render_long_plain(), &cfg.render_short_html()) |
| 516 | + ) |
| 517 | + } else { |
| 518 | + Ok(()) |
| 519 | + } |
| 520 | + }) |
500 | 521 | }
|
501 | 522 |
|
502 | 523 | fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
|
|
0 commit comments