Skip to content

Commit

Permalink
end expressions like return/continue/break with a semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
scampi committed Nov 29, 2018
1 parent 4f233a5 commit d03d9a4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/config/license.rs
Expand Up @@ -137,7 +137,7 @@ impl TemplateParser {
return Err(LicenseError::Parse(format!(
"incomplete escape sequence on l. {}",
parser.linum
)))
)));
}
_ => (),
}
Expand Down
9 changes: 7 additions & 2 deletions src/matches.rs
Expand Up @@ -29,7 +29,7 @@ use source_map::SpanUtils;
use spanned::Spanned;
use utils::{
contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp,
ptr_vec_to_ref_vec, trimmed_last_line_width,
ptr_vec_to_ref_vec, semicolon_for_expr, trimmed_last_line_width,
};

/// A simple wrapper type against `ast::Arm`. Used inside `write_list()`.
Expand Down Expand Up @@ -413,7 +413,12 @@ fn rewrite_match_body(
} else {
""
};
("{", format!("{}}}{}", indent_str, comma))
let semicolon = if semicolon_for_expr(context, body) {
";"
} else {
""
};
("{", format!("{}{}}}{}", semicolon, indent_str, comma))
} else {
("", String::from(","))
};
Expand Down
7 changes: 7 additions & 0 deletions tests/source/issue-3213.rs
@@ -0,0 +1,7 @@
fn foo() {
match 0 {
0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
1 => AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
_ => "",
};
}
2 changes: 1 addition & 1 deletion tests/source/match.rs
Expand Up @@ -545,7 +545,7 @@ fn issue_3005() {
{
return NoCalcLength::parse_dimension(context, value, unit)
.map(LengthOrPercentage::Length)
.map_err(|()| location.new_unexpected_token_error(token.clone()))
.map_err(|()| location.new_unexpected_token_error(token.clone()));
},
}
}
11 changes: 11 additions & 0 deletions tests/target/issue-3213.rs
@@ -0,0 +1,11 @@
fn foo() {
match 0 {
0 => {
return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
}
1 => {
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
}
_ => "",
};
}
2 changes: 1 addition & 1 deletion tests/target/match.rs
Expand Up @@ -572,7 +572,7 @@ fn issue_3005() {
} if num_context.is_ok(context.parsing_mode, value) => {
return NoCalcLength::parse_dimension(context, value, unit)
.map(LengthOrPercentage::Length)
.map_err(|()| location.new_unexpected_token_error(token.clone()))
.map_err(|()| location.new_unexpected_token_error(token.clone()));
}
}
}

0 comments on commit d03d9a4

Please sign in to comment.