Skip to content

Commit

Permalink
Remove static and const initialization from documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Aug 26, 2018
1 parent a00706a commit 8614179
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
21 changes: 4 additions & 17 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2579,27 +2579,15 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
stability
}

struct Initializer<'a>(&'a str);

impl<'a> fmt::Display for Initializer<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Initializer(s) = *self;
if s.is_empty() { return Ok(()); }
write!(f, "<code> = </code>")?;
write!(f, "<code>{}</code>", Escape(s))
}
}

fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
c: &clean::Constant) -> fmt::Result {
write!(w, "<pre class='rust const'>")?;
render_attributes(w, it)?;
write!(w, "{vis}const \
{name}: {typ}{init}</pre>",
{name}: {typ}</pre>",
vis = VisSpace(&it.visibility),
name = it.name.as_ref().unwrap(),
typ = c.type_,
init = Initializer(&c.expr))?;
typ = c.type_)?;
document(w, cx, it)
}

Expand All @@ -2608,12 +2596,11 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "<pre class='rust static'>")?;
render_attributes(w, it)?;
write!(w, "{vis}static {mutability}\
{name}: {typ}{init}</pre>",
{name}: {typ}</pre>",
vis = VisSpace(&it.visibility),
mutability = MutableSpace(s.mutability),
name = it.name.as_ref().unwrap(),
typ = s.type_,
init = Initializer(&s.expr))?;
typ = s.type_)?;
document(w, cx, it)
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/escape-rust-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
// Test that we HTML-escape Rust expressions, where HTML special chars
// can occur, and we know it's definitely not markup.

// @has escape_rust_expr/constant.CONST_S.html '//pre[@class="rust const"]' '"<script>"'
// @!has escape_rust_expr/constant.CONST_S.html '//pre[@class="rust const"]' '"<script>"'
pub const CONST_S: &'static str = "<script>";
4 changes: 2 additions & 2 deletions src/test/rustdoc/issue-33302.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ macro_rules! make {
pub struct S;

// @has issue_33302/constant.CST.html \
// '//pre[@class="rust const"]' 'pub const CST: i32 = 4 * 4'
// '//pre[@class="rust const"]' 'pub const CST: i32'
pub const CST: i32 = ($n * $n);
// @has issue_33302/static.ST.html \
// '//pre[@class="rust static"]' 'pub static ST: i32 = 4 * 4'
// '//pre[@class="rust static"]' 'pub static ST: i32'
pub static ST: i32 = ($n * $n);

pub trait T<X> {
Expand Down

0 comments on commit 8614179

Please sign in to comment.