Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d1c7afe

Browse files
authored
Merge pull request rust-lang#3250 from scampi/issue3229
version-gate the trailing semicolon change of return statements inside a match arm
2 parents d078595 + b101233 commit d1c7afe

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
error_on_line_overflow = true
22
error_on_unformatted = true
3+
version = "Two"
34
edition = "2018"

src/matches.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::source_map::{BytePos, Span};
1717
use syntax::{ast, ptr};
1818

1919
use comment::{combine_strs_with_missing_comments, rewrite_comment};
20-
use config::{Config, ControlBraceStyle, IndentStyle};
20+
use config::{Config, ControlBraceStyle, IndentStyle, Version};
2121
use expr::{
2222
format_expr, is_empty_block, is_simple_block, is_unsafe_block, prefer_next_line, rewrite_cond,
2323
rewrite_multiple_patterns, ExprType, RhsTactics,
@@ -413,11 +413,12 @@ fn rewrite_match_body(
413413
} else {
414414
""
415415
};
416-
let semicolon = if semicolon_for_expr(context, body) {
417-
";"
418-
} else {
419-
""
420-
};
416+
let semicolon =
417+
if context.config.version() == Version::Two && semicolon_for_expr(context, body) {
418+
";"
419+
} else {
420+
""
421+
};
421422
("{", format!("{}{}}}{}", semicolon, indent_str, comma))
422423
} else {
423424
("", String::from(","))

tests/source/issue-3213.rs renamed to tests/source/issue-3213/version_one.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// rustfmt-version: One
2+
13
fn foo() {
24
match 0 {
35
0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-version: Two
2+
3+
fn foo() {
4+
match 0 {
5+
0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
6+
1 => AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
7+
_ => "",
8+
};
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// rustfmt-version: One
2+
3+
fn foo() {
4+
match 0 {
5+
0 => {
6+
return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
7+
}
8+
1 => {
9+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
10+
}
11+
_ => "",
12+
};
13+
}

tests/target/issue-3213.rs renamed to tests/target/issue-3213/version_two.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// rustfmt-version: Two
2+
13
fn foo() {
24
match 0 {
35
0 => {

0 commit comments

Comments
 (0)