Skip to content

Commit 80ec1b9

Browse files
committed
Auto merge of #33512 - birkenfeld:issue-25944, r=sanxiyn
rustdoc: remove artificial indentation of doctest code The indentation makes the examples look nicer when printed (when is this done?), but breaks tests using multi-line string literals. Fixes: #25944
2 parents 6dbb0e8 + 5606b42 commit 80ec1b9

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
@@ -341,7 +341,7 @@ pub fn maketest(s: &str, cratename: Option<&str>, dont_insert_main: bool,
341341
prog.push_str(&everything_else);
342342
} else {
343343
prog.push_str("fn main() {\n ");
344-
prog.push_str(&everything_else.replace("\n", "\n "));
344+
prog.push_str(&everything_else);
345345
prog = prog.trim().into();
346346
prog.push_str("\n}");
347347
}

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)