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() {
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) {}
+}