Skip to content

Commit 639bece

Browse files
Fix formatting generation for rustdoc code examples
1 parent 2c50f4e commit 639bece

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/librustdoc/test.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,14 @@ pub fn maketest(s: &str, cratename: Option<&str>, dont_insert_main: bool,
359359
if dont_insert_main || s.contains("fn main") {
360360
prog.push_str(&everything_else);
361361
} else {
362-
prog.push_str("fn main() {\n ");
363-
prog.push_str(&everything_else);
362+
prog.push_str("fn main() {\n");
363+
for line in everything_else.split("\n") {
364+
if line.len() > 0 {
365+
prog.push_str(&format!(" {}\n", line));
366+
} else {
367+
prog.push_str("\n");
368+
}
369+
}
364370
prog = prog.trim().into();
365371
prog.push_str("\n}");
366372
}

src/test/rustdoc/issue-25944.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
/// ```
1414
/// let a = r#"
1515
/// foo
16+
///
1617
/// bar"#;
17-
/// let b = "\nfoo\nbar";
18+
/// let b = "\n foo\n\n bar";
1819
/// assert_eq!(a, b);
1920
/// ```
2021
pub fn main() {

0 commit comments

Comments
 (0)