Skip to content

Commit 5606b42

Browse files
committed
rustdoc: remove artificial indentation of doctest code
This makes the examples look nicer when printed (when is this done?), but breaks tests using multi-line string literals. Fixes: #25944
1 parent 50909f2 commit 5606b42

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/doc/book/strings.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ include the newline and the leading spaces:
3232
let s = "foo
3333
bar";
3434

35-
assert_eq!("foo\n bar", s);
35+
assert_eq!("foo\n bar", s);
3636
```
3737

3838
The second, with a `\`, trims the spaces and the newline:

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ pub fn maketest(s: &str, cratename: Option<&str>, dont_insert_main: bool,
340340
prog.push_str(&everything_else);
341341
} else {
342342
prog.push_str("fn main() {\n ");
343-
prog.push_str(&everything_else.replace("\n", "\n "));
343+
prog.push_str(&everything_else);
344344
prog = prog.trim().into();
345345
prog.push_str("\n}");
346346
}

src/test/rustdoc/issue-25944.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:--test
12+
13+
/// ```
14+
/// let a = r#"
15+
/// foo
16+
/// bar"#;
17+
/// let b = "\nfoo\nbar";
18+
/// assert_eq!(a, b);
19+
/// ```
20+
pub fn main() {
21+
}

0 commit comments

Comments
 (0)