Fixed error caused by combination of match_arm_blocks and control_brace_style
Fixes 5912 When `control_brace_style = "AlwaysNextLine"`, the code seems to always assume that `body_prefix` is `{`. This is however not the case when `match_arm_blocks = false`. This causes `block_sep` to introduce extra white space that causes the error. The fix was to check if `body_prefix` is empty before matching on `ControlBraceStyle::AlwaysNextLine`.
This commit is contained in:
parent
81fe905ca8
commit
041f113159
@ -451,8 +451,8 @@ fn rewrite_match_body(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let block_sep = match context.config.control_brace_style() {
|
let block_sep = match context.config.control_brace_style() {
|
||||||
ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix),
|
|
||||||
_ if body_prefix.is_empty() => "".to_owned(),
|
_ if body_prefix.is_empty() => "".to_owned(),
|
||||||
|
ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix),
|
||||||
_ if forbid_same_line || !arrow_comment.is_empty() => {
|
_ if forbid_same_line || !arrow_comment.is_empty() => {
|
||||||
format!("{}{}", alt_block_sep, body_prefix)
|
format!("{}{}", alt_block_sep, body_prefix)
|
||||||
}
|
}
|
||||||
|
@ -184,3 +184,19 @@ fn dont_emit_ICE() {
|
|||||||
assert!(!stderr.contains("thread 'main' panicked"));
|
assert!(!stderr.contains("thread 'main' panicked"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rustfmt_emits_error_when_control_brace_style_is_always_next_line() {
|
||||||
|
// See also https://github.com/rust-lang/rustfmt/issues/5912
|
||||||
|
let args = [
|
||||||
|
"--config=color=Never",
|
||||||
|
"--config",
|
||||||
|
"control_brace_style=AlwaysNextLine",
|
||||||
|
"--config",
|
||||||
|
"match_arm_blocks=false",
|
||||||
|
"tests/target/issue_5912.rs",
|
||||||
|
];
|
||||||
|
|
||||||
|
let (_stdout, stderr) = rustfmt(&args);
|
||||||
|
assert!(!stderr.contains("error[internal]: left behind trailing whitespace"))
|
||||||
|
}
|
||||||
|
15
tests/source/issue_5912.rs
Normal file
15
tests/source/issue_5912.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// rustfmt-match_arm_blocks: false
|
||||||
|
// rustfmt-control_brace_style: AlwaysNextLine
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
match 0 {
|
||||||
|
0 => {
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
}
|
||||||
|
_ => 2,
|
||||||
|
}
|
||||||
|
}
|
15
tests/target/issue_5912.rs
Normal file
15
tests/target/issue_5912.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// rustfmt-match_arm_blocks: false
|
||||||
|
// rustfmt-control_brace_style: AlwaysNextLine
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
match 0
|
||||||
|
{
|
||||||
|
0 =>
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||||
|
_ => 2,
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user