Skip to content

Commit 9749df5

Browse files
committed
Auto merge of #38244 - estebank:escape-reason-docs, r=ollie27
rustdoc: escape the deprecated and unstable reason text Fix #38220. Instead of the [current output](https://doc.rust-lang.org/std/boxed/trait.FnBox.html): <img width="967" alt="incorrect unescaped unstable reason in docs" src="https://cloud.githubusercontent.com/assets/1606434/21021898/73121d42-bd2f-11e6-8076-8a5127dbc010.png"> display: <img width="979" alt="escaped unstable reason in docs" src="https://cloud.githubusercontent.com/assets/1606434/21021876/52eb0f88-bd2f-11e6-9088-58bdc7d92328.png">
2 parents 5c1472a + e766c46 commit 9749df5

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/liballoc/boxed.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -587,15 +587,15 @@ impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}
587587
/// ```
588588
#[rustc_paren_sugar]
589589
#[unstable(feature = "fnbox",
590-
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
590+
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
591591
pub trait FnBox<A> {
592592
type Output;
593593

594594
fn call_box(self: Box<Self>, args: A) -> Self::Output;
595595
}
596596

597597
#[unstable(feature = "fnbox",
598-
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
598+
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
599599
impl<A, F> FnBox<A> for F
600600
where F: FnOnce<A>
601601
{
@@ -607,7 +607,7 @@ impl<A, F> FnBox<A> for F
607607
}
608608

609609
#[unstable(feature = "fnbox",
610-
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
610+
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
611611
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
612612
type Output = R;
613613

@@ -617,7 +617,7 @@ impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
617617
}
618618

619619
#[unstable(feature = "fnbox",
620-
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
620+
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
621621
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + Send + 'a> {
622622
type Output = R;
623623

src/librustdoc/html/markdown.rs

+32-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub struct Markdown<'a>(pub &'a str);
4949
/// A unit struct like `Markdown`, that renders the markdown with a
5050
/// table of contents.
5151
pub struct MarkdownWithToc<'a>(pub &'a str);
52+
/// A unit struct like `Markdown`, that renders the markdown escaping HTML tags.
53+
pub struct MarkdownHtml<'a>(pub &'a str);
5254

5355
const DEF_OUNIT: libc::size_t = 64;
5456
const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 11;
@@ -58,6 +60,7 @@ const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
5860
const HOEDOWN_EXT_STRIKETHROUGH: libc::c_uint = 1 << 4;
5961
const HOEDOWN_EXT_SUPERSCRIPT: libc::c_uint = 1 << 8;
6062
const HOEDOWN_EXT_FOOTNOTES: libc::c_uint = 1 << 2;
63+
const HOEDOWN_HTML_ESCAPE: libc::c_uint = 1 << 1;
6164

6265
const HOEDOWN_EXTENSIONS: libc::c_uint =
6366
HOEDOWN_EXT_NO_INTRA_EMPHASIS | HOEDOWN_EXT_TABLES |
@@ -220,7 +223,11 @@ thread_local!(pub static PLAYGROUND: RefCell<Option<(Option<String>, String)>> =
220223
RefCell::new(None)
221224
});
222225

223-
pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
226+
227+
pub fn render(w: &mut fmt::Formatter,
228+
s: &str,
229+
print_toc: bool,
230+
html_flags: libc::c_uint) -> fmt::Result {
224231
extern fn block(ob: *mut hoedown_buffer, orig_text: *const hoedown_buffer,
225232
lang: *const hoedown_buffer, data: *const hoedown_renderer_data) {
226233
unsafe {
@@ -383,7 +390,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
383390

384391
unsafe {
385392
let ob = hoedown_buffer_new(DEF_OUNIT);
386-
let renderer = hoedown_html_renderer_new(0, 0);
393+
let renderer = hoedown_html_renderer_new(html_flags, 0);
387394
let mut opaque = MyOpaque {
388395
dfltblk: (*renderer).blockcode.unwrap(),
389396
toc_builder: if print_toc {Some(TocBuilder::new())} else {None}
@@ -553,14 +560,23 @@ impl<'a> fmt::Display for Markdown<'a> {
553560
let Markdown(md) = *self;
554561
// This is actually common enough to special-case
555562
if md.is_empty() { return Ok(()) }
556-
render(fmt, md, false)
563+
render(fmt, md, false, 0)
557564
}
558565
}
559566

560567
impl<'a> fmt::Display for MarkdownWithToc<'a> {
561568
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
562569
let MarkdownWithToc(md) = *self;
563-
render(fmt, md, true)
570+
render(fmt, md, true, 0)
571+
}
572+
}
573+
574+
impl<'a> fmt::Display for MarkdownHtml<'a> {
575+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
576+
let MarkdownHtml(md) = *self;
577+
// This is actually common enough to special-case
578+
if md.is_empty() { return Ok(()) }
579+
render(fmt, md, false, HOEDOWN_HTML_ESCAPE)
564580
}
565581
}
566582

@@ -613,7 +629,7 @@ pub fn plain_summary_line(md: &str) -> String {
613629

614630
#[cfg(test)]
615631
mod tests {
616-
use super::{LangString, Markdown};
632+
use super::{LangString, Markdown, MarkdownHtml};
617633
use super::plain_summary_line;
618634
use html::render::reset_ids;
619635

@@ -719,4 +735,15 @@ mod tests {
719735
t("# top header", "top header");
720736
t("## header", "header");
721737
}
738+
739+
#[test]
740+
fn test_markdown_html_escape() {
741+
fn t(input: &str, expect: &str) {
742+
let output = format!("{}", MarkdownHtml(input));
743+
assert_eq!(output, expect);
744+
}
745+
746+
t("`Struct<'a, T>`", "<p><code>Struct&lt;&#39;a, T&gt;</code></p>\n");
747+
t("Struct<'a, T>", "<p>Struct&lt;&#39;a, T&gt;</p>\n");
748+
}
722749
}

src/librustdoc/html/render.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
7171
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
7272
use html::format::fmt_impl_for_trait_page;
7373
use html::item_type::ItemType;
74-
use html::markdown::{self, Markdown};
74+
use html::markdown::{self, Markdown, MarkdownHtml};
7575
use html::{highlight, layout};
7676

7777
/// A pair of name and its optional document.
@@ -1866,7 +1866,7 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
18661866
} else {
18671867
String::new()
18681868
};
1869-
let text = format!("Deprecated{}{}", since, Markdown(&deprecated_reason));
1869+
let text = format!("Deprecated{}{}", since, MarkdownHtml(&deprecated_reason));
18701870
stability.push(format!("<div class='stab deprecated'>{}</div>", text))
18711871
};
18721872

@@ -1891,7 +1891,7 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
18911891
} else {
18921892
String::new()
18931893
};
1894-
let text = format!("Unstable{}{}", unstable_extra, Markdown(&unstable_reason));
1894+
let text = format!("Unstable{}{}", unstable_extra, MarkdownHtml(&unstable_reason));
18951895
stability.push(format!("<div class='stab unstable'>{}</div>", text))
18961896
};
18971897
} else if let Some(depr) = item.deprecation.as_ref() {
@@ -1906,7 +1906,7 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
19061906
String::new()
19071907
};
19081908

1909-
let text = format!("Deprecated{}{}", since, Markdown(&note));
1909+
let text = format!("Deprecated{}{}", since, MarkdownHtml(&note));
19101910
stability.push(format!("<div class='stab deprecated'>{}</div>", text))
19111911
}
19121912

0 commit comments

Comments
 (0)