From abfbd1bd719bd1440132ead24ec64c0acd293f41 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Tue, 13 Oct 2020 16:11:51 -0500 Subject: [PATCH 1/2] Avoid extraneous space between visibility kw and ident for statics Today, given a static like `static mut FOO: usize = 1`, rustdoc would emit `static mut FOO: usize = 1`, as it emits both the mutability kw with a space and reserves a space after the mutability kw. This patch fixes that misformatting. This patch also adds some tests for emit of other statics, as I could not find an existing test devoted to statics. --- src/librustdoc/html/render/mod.rs | 2 +- src/test/rustdoc/static.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/static.rs diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 76334f0213d15..97d0a4d4e7dcd 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2289,7 +2289,7 @@ fn item_static(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Static render_attributes(w, it, false); write!( w, - "{vis}static {mutability} {name}: {typ}", + "{vis}static {mutability}{name}: {typ}", vis = it.visibility.print_with_space(), mutability = s.mutability.print_with_space(), name = it.name.as_ref().unwrap(), diff --git a/src/test/rustdoc/static.rs b/src/test/rustdoc/static.rs new file mode 100644 index 0000000000000..aa48644918d9a --- /dev/null +++ b/src/test/rustdoc/static.rs @@ -0,0 +1,12 @@ +// compile-flags: --document-private-items + +#![crate_type = "lib"] + +// @has static/static.FOO.html '//pre[@class="static"]' 'static FOO: usize' +static FOO: usize = 1; + +// @has static/static.BAR.html '//pre[@class="static"]' 'pub static BAR: usize' +pub static BAR: usize = 1; + +// @has static/static.BAZ.html '//pre[@class="static"]' 'pub static mut BAZ: usize' +pub static mut BAZ: usize = 1; From e60072f5c65c619263d137daf9afab9c6cb94c8e Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Tue, 13 Oct 2020 16:47:53 -0500 Subject: [PATCH 2/2] fixup! Avoid extraneous space between visibility kw and ident for statics --- src/test/rustdoc/static.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/rustdoc/static.rs b/src/test/rustdoc/static.rs index aa48644918d9a..90dafd8b3480d 100644 --- a/src/test/rustdoc/static.rs +++ b/src/test/rustdoc/static.rs @@ -2,11 +2,11 @@ #![crate_type = "lib"] -// @has static/static.FOO.html '//pre[@class="static"]' 'static FOO: usize' +// @has static/static.FOO.html '//pre' 'static FOO: usize' static FOO: usize = 1; -// @has static/static.BAR.html '//pre[@class="static"]' 'pub static BAR: usize' +// @has static/static.BAR.html '//pre' 'pub static BAR: usize' pub static BAR: usize = 1; -// @has static/static.BAZ.html '//pre[@class="static"]' 'pub static mut BAZ: usize' +// @has static/static.BAZ.html '//pre' 'pub static mut BAZ: usize' pub static mut BAZ: usize = 1;