From d04d8694db9f82ff7aee381ba4dcb2e815dd90f0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 27 Jan 2021 14:19:18 +0100 Subject: [PATCH 1/2] Fix multine attributes string in display --- src/librustdoc/html/render/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index ef45c98e40629..7993fa748474e 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -3332,6 +3332,16 @@ fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) { None } }) + // This whole `map` is to correctly print the "cut" strings in attributes arguments like: + // + // #[x = "string with \ + // backline"] + .map(|a| { + a.split("\\\n").fold(String::new(), |mut acc, a| { + acc.push_str(a.trim_start()); + acc + }) + }) .join("\n"); if !attrs.is_empty() { From 9b6567daf4c4d273a32c5181bde0cd18865a1ccb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 27 Jan 2021 14:19:44 +0100 Subject: [PATCH 2/2] Add test to enforce display for attribute strings --- src/test/rustdoc/attributes-backline.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/test/rustdoc/attributes-backline.rs diff --git a/src/test/rustdoc/attributes-backline.rs b/src/test/rustdoc/attributes-backline.rs new file mode 100644 index 0000000000000..61ca9963aafe4 --- /dev/null +++ b/src/test/rustdoc/attributes-backline.rs @@ -0,0 +1,14 @@ +#![crate_name = "foo"] + +// @has 'foo/struct.Fly.html' +// @has - '//h4[@id="method.drosophilae"]//span[@class="docblock attributes"]' '' +// @has - '//h4[@id="method.drosophilae"]//span[@class="docblock attributes"]' \ +// 'Just a sentence with a backline in the middle' +// @!has - '//h4[@id="method.drosophilae"]//span[@class="doblock attributes"]' '\\' +pub struct Fly; + +impl Fly { + #[must_use = "Just a sentence with a backline in \ + the middle"] + pub fn drosophilae(&self) {} +}