Skip to content

Commit c8290a5

Browse files
authored
ensure parse errors aren't emitted when formatting doc comments (#6232)
This adds a test case to validate behavior when using `format_code_in_doc_comments=true`
1 parent eed7e23 commit c8290a5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tests/rustfmt/main.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fs::remove_file;
55
use std::path::Path;
66
use std::process::Command;
77

8-
use rustfmt_config_proc_macro::rustfmt_only_ci_test;
8+
use rustfmt_config_proc_macro::{nightly_only_test, rustfmt_only_ci_test};
99

1010
/// Run the rustfmt executable and return its output.
1111
fn rustfmt(args: &[&str]) -> (String, String) {
@@ -207,3 +207,15 @@ fn rustfmt_emits_error_when_control_brace_style_is_always_next_line() {
207207
let (_stdout, stderr) = rustfmt(&args);
208208
assert!(!stderr.contains("error[internal]: left behind trailing whitespace"))
209209
}
210+
211+
#[nightly_only_test]
212+
#[test]
213+
fn rustfmt_generates_no_error_if_failed_format_code_in_doc_comments() {
214+
// See also https://github.com/rust-lang/rustfmt/issues/6109
215+
216+
let file = "tests/target/issue-6109.rs";
217+
let args = ["--config", "format_code_in_doc_comments=true", file];
218+
let (stdout, stderr) = rustfmt(&args);
219+
assert!(stderr.is_empty());
220+
assert!(stdout.is_empty());
221+
}

tests/target/issue-6109.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Some doc comment with code snippet:
2+
///```
3+
/// '\u{1F}
4+
/// ```
5+
pub struct Code {}
6+
7+
fn main() {}

0 commit comments

Comments
 (0)