From d442a372621f70bd63f42917becf184387cfe3d4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 25 Jan 2022 17:09:18 +0100 Subject: [PATCH 1/2] Fix invalid extra dot after version if no source --- src/librustdoc/html/render/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 32e4a82918421..0b6faa4b13ed2 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1676,11 +1676,12 @@ fn render_rightside( containing_item.stable_since(tcx), const_stable_since, ); - if has_stability { + let mut tmp_buf = Buffer::empty_from(w); + write_srclink(cx, item, &mut tmp_buf); + if has_stability && !tmp_buf.is_empty() { w.write_str(" · "); } - - write_srclink(cx, item, w); + w.push_buffer(tmp_buf); w.write_str(""); } From 066fcb6fd55010b01d9b63b74336e5e38fc6940f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 25 Jan 2022 17:20:59 +0100 Subject: [PATCH 2/2] Add test when there is no source code link after version --- .../version-separator-without-source.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/rustdoc/version-separator-without-source.rs diff --git a/src/test/rustdoc/version-separator-without-source.rs b/src/test/rustdoc/version-separator-without-source.rs new file mode 100644 index 0000000000000..bffe5030a84fd --- /dev/null +++ b/src/test/rustdoc/version-separator-without-source.rs @@ -0,0 +1,23 @@ +#![doc(html_no_source)] +#![feature(staged_api)] +#![stable(feature = "bar", since = "1.0")] +#![crate_name = "foo"] + +// @has foo/fn.foo.html +// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · ' +// @!has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · ' +#[stable(feature = "bar", since = "1.0")] +pub fn foo() {} + +// @has foo/struct.Bar.html +// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · ' +// @!has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · ' +#[stable(feature = "bar", since = "1.0")] +pub struct Bar; + +impl Bar { + // @has - '//div[@id="method.bar"]/*[@class="rightside"]' '2.0' + // @!has - '//div[@id="method.bar"]/*[@class="rightside"]' '2.0 ·' + #[stable(feature = "foobar", since = "2.0")] + pub fn bar() {} +}