diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-01-07 13:46:07 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-07 13:46:07 +0900 |
| commit | c07204b1d1eb9144c8be560a8f5d7f9aed0a5b79 (patch) | |
| tree | 1beee7ab161d7f31572d27e9e78f0905653284df /src/librustdoc/html | |
| parent | 9ef3b2ca2a9d37657ea1b5de056dd7324dca0632 (diff) | |
| parent | e2305d0055805effb9d6200f995ad825aa0c56e1 (diff) | |
| download | rust-c07204b1d1eb9144c8be560a8f5d7f9aed0a5b79.tar.gz rust-c07204b1d1eb9144c8be560a8f5d7f9aed0a5b79.zip | |
Rollup merge of #67908 - ollie27:rustdoc_const_html_escape, r=GuillaumeGomez
rustdoc: HTML escape const values r? @GuillaumeGomez
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/format.rs | 17 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 4 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 2580bbf982b..6434dccdfc7 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -15,6 +15,7 @@ use rustc_hir::def_id::DefId; use rustc_target::spec::abi::Abi; use crate::clean::{self, PrimitiveType}; +use crate::html::escape::Escape; use crate::html::item_type::ItemType; use crate::html::render::{self, cache, CURRENT_DEPTH}; @@ -314,8 +315,14 @@ impl clean::Lifetime { } impl clean::Constant { - crate fn print(&self) -> &str { - &self.expr + crate fn print(&self) -> impl fmt::Display + '_ { + display_fn(move |f| { + if f.alternate() { + f.write_str(&self.expr) + } else { + write!(f, "{}", Escape(&self.expr)) + } + }) } } @@ -689,7 +696,11 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) -> clean::Array(ref t, ref n) => { primitive_link(f, PrimitiveType::Array, "[")?; fmt::Display::fmt(&t.print(), f)?; - primitive_link(f, PrimitiveType::Array, &format!("; {}]", n)) + if f.alternate() { + primitive_link(f, PrimitiveType::Array, &format!("; {}]", n)) + } else { + primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n))) + } } clean::Never => primitive_link(f, PrimitiveType::Never, "!"), clean::RawPointer(m, ref t) => { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 025257b801f..a01e2f79394 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2280,7 +2280,7 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons ); if c.value.is_some() || c.is_literal { - write!(w, " = {expr};", expr = c.expr); + write!(w, " = {expr};", expr = Escape(&c.expr)); } else { write!(w, ";"); } @@ -2293,7 +2293,7 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons if value_lowercase != expr_lowercase && value_lowercase.trim_end_matches("i32") != expr_lowercase { - write!(w, " // {value}", value = value); + write!(w, " // {value}", value = Escape(value)); } } } |
