From fdb1d6e4e5d93da9e06aba9d27c687c4f60b76f8 Mon Sep 17 00:00:00 2001 From: binarycat Date: Fri, 12 Dec 2025 14:38:01 -0600 Subject: [PATCH] rustdoc: don't give depreciation notes special handling in future edition --- src/librustdoc/html/markdown.rs | 26 ++++++++++++++++++---- src/librustdoc/html/markdown/tests.rs | 25 ++++++++++++++++++--- src/librustdoc/html/render/mod.rs | 3 ++- src/librustdoc/html/static/css/rustdoc.css | 5 ++++- tests/rustdoc/deprecated.rs | 8 +++++++ 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index a4d377432c914..04a18e16edb93 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -111,7 +111,11 @@ pub(crate) struct MarkdownWithToc<'a> { } /// A tuple struct like `Markdown` that renders the markdown escaping HTML tags /// and includes no paragraph tags. -pub(crate) struct MarkdownItemInfo<'a>(pub(crate) &'a str, pub(crate) &'a mut IdMap); +pub(crate) struct MarkdownItemInfo<'a>( + pub(crate) &'a str, + pub(crate) &'a mut IdMap, + pub(crate) Edition, +); /// A tuple struct like `Markdown` that renders only the first paragraph. pub(crate) struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [RenderedLink]); @@ -1461,7 +1465,8 @@ impl MarkdownWithToc<'_> { impl MarkdownItemInfo<'_> { pub(crate) fn write_into(self, mut f: impl fmt::Write) -> fmt::Result { - let MarkdownItemInfo(md, ids) = self; + let MarkdownItemInfo(md, ids, edition) = self; + let legacy_wrap = edition != Edition::EditionFuture; // This is actually common enough to special-case if md.is_empty() { @@ -1479,10 +1484,23 @@ impl MarkdownItemInfo<'_> { let p = HeadingLinks::new(p, None, ids, HeadingOffset::H1); let p = footnotes::Footnotes::new(p, existing_footnotes); let p = TableWrapper::new(p.map(|(ev, _)| ev)); + // in legacy wrap mode, strip

elements to avoid them inserting newlines let p = p.filter(|event| { - !matches!(event, Event::Start(Tag::Paragraph) | Event::End(TagEnd::Paragraph)) + !legacy_wrap + || !matches!( + event, + Event::Start(Tag::Paragraph) | Event::End(TagEnd::Paragraph) + ) }); - html::write_html_fmt(&mut f, p) + if legacy_wrap { + f.write_str("")?; + } + html::write_html_fmt(&mut f, p)?; + if legacy_wrap { + f.write_str("")?; + } + + Ok(()) }) } } diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 61fd428746332..f80ee7730b2db 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -467,12 +467,31 @@ fn test_plain_text_summary() { } #[test] -fn test_markdown_html_escape() { +fn test_markdown_html_escape_legacy() { fn t(input: &str, expect: &str) { let mut idmap = IdMap::new(); let mut output = String::new(); - MarkdownItemInfo(input, &mut idmap).write_into(&mut output).unwrap(); - assert_eq!(output, expect, "original: {}", input); + MarkdownItemInfo(input, &mut idmap, Edition::Edition2015).write_into(&mut output).unwrap(); + assert_eq!( + output, + format!("{}", expect), + "original: {}", + input + ); + } + + t("`Struct<'a, T>`", "Struct<'a, T>"); + t("Struct<'a, T>", "Struct<’a, T>"); + t("Struct
", "Struct<br>"); +} + +#[test] +fn test_markdown_html_escape_new() { + fn t(input: &str, expect: &str) { + let mut idmap = IdMap::new(); + let mut output = String::new(); + MarkdownItemInfo(input, &mut idmap, Edition::Edition2015).write_into(&mut output).unwrap(); + assert_eq!(output, format!("

{}

", expect), "original: {}", input); } t("`Struct<'a, T>`", "Struct<'a, T>"); diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 8740b5935973c..659a84427ff82 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -855,6 +855,7 @@ fn short_item_info( parent: Option<&clean::Item>, ) -> Vec { let mut extra_info = vec![]; + let edition = item.span(cx.tcx()).expect("unable to get edition of span").inner().edition(); if let Some(depr @ Deprecation { note, since, suggestion: _ }) = item.deprecation(cx.tcx()) { // We display deprecation messages for #[deprecated], but only display @@ -877,7 +878,7 @@ fn short_item_info( if let Some(note) = note { let note = note.as_str(); let mut id_map = cx.id_map.borrow_mut(); - let html = MarkdownItemInfo(note, &mut id_map); + let html = MarkdownItemInfo(note, &mut id_map, edition); message.push_str(": "); html.write_into(&mut message).unwrap(); } diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 7f47856948493..ba61a263003a8 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1577,7 +1577,6 @@ so that we can apply CSS-filters to change the arrow color in themes */ color: var(--main-color); background-color: var(--stab-background-color); width: fit-content; - white-space: pre-wrap; border-radius: 3px; display: inline; vertical-align: baseline; @@ -1588,6 +1587,10 @@ so that we can apply CSS-filters to change the arrow color in themes */ color: var(--stab-code-color); } +.stab span.legacy-wrap { + white-space: pre-wrap; +} + .stab .emoji, .item-info .stab::before { font-size: 1.25rem; } diff --git a/tests/rustdoc/deprecated.rs b/tests/rustdoc/deprecated.rs index a84657a3df5aa..d70eeb8320f91 100644 --- a/tests/rustdoc/deprecated.rs +++ b/tests/rustdoc/deprecated.rs @@ -1,3 +1,6 @@ +//@ compile-flags: -Zunstable-options +//@ edition: future + //@ has deprecated/index.html '//dt/span[@class="stab deprecated"]' 'Deprecated' //@ has - '//dd' 'Deprecated docs' @@ -30,3 +33,8 @@ pub struct W; // 'Deprecated: shorthand reason: code$' #[deprecated = "shorthand reason: `code`"] pub struct X; + +//@ matches deprecated/struct.Y.html '//*[@class="stab deprecated"]//p[1]' 'multiple' +//@ matches deprecated/struct.Y.html '//*[@class="stab deprecated"]//p[2]' 'paragraphs' +#[deprecated = "multiple\n\nparagraphs"] +pub struct Y;