Skip to content

Commit

Permalink
version-gate the trailing semicolon change of return statements insid…
Browse files Browse the repository at this point in the history
…e a match arm
  • Loading branch information
scampi committed Dec 14, 2018
1 parent 66c98db commit b73a602
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/matches.rs
Expand Up @@ -17,7 +17,7 @@ use syntax::source_map::{BytePos, Span};
use syntax::{ast, ptr};

use comment::{combine_strs_with_missing_comments, rewrite_comment};
use config::{Config, ControlBraceStyle, IndentStyle};
use config::{Config, ControlBraceStyle, IndentStyle, Version};
use expr::{
format_expr, is_empty_block, is_simple_block, is_unsafe_block, prefer_next_line, rewrite_cond,
rewrite_multiple_patterns, ExprType, RhsTactics,
Expand Down Expand Up @@ -413,11 +413,12 @@ fn rewrite_match_body(
} else {
""
};
let semicolon = if semicolon_for_expr(context, body) {
";"
} else {
""
};
let semicolon =
if context.config.version() == Version::Two && semicolon_for_expr(context, body) {
";"
} else {
""
};
("{", format!("{}{}}}{}", semicolon, indent_str, comma))
} else {
("", String::from(","))
Expand Down
@@ -1,3 +1,5 @@
// rustfmt-version: One

fn foo() {
match 0 {
0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
Expand Down
9 changes: 9 additions & 0 deletions tests/source/issue-3213/version_two.rs
@@ -0,0 +1,9 @@
// rustfmt-version: Two

fn foo() {
match 0 {
0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
1 => AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
_ => "",
};
}
13 changes: 13 additions & 0 deletions tests/target/issue-3213/version_one.rs
@@ -0,0 +1,13 @@
// rustfmt-version: One

fn foo() {
match 0 {
0 => {
return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
}
1 => {
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
}
_ => "",
};
}
@@ -1,3 +1,5 @@
// rustfmt-version: Two

fn foo() {
match 0 {
0 => {
Expand Down

0 comments on commit b73a602

Please sign in to comment.