From d03d9a45efd6995533e2cd79e458cbfeb8408e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Campinas?= Date: Thu, 29 Nov 2018 20:39:07 +0100 Subject: [PATCH] end expressions like return/continue/break with a semicolon Close #3213 --- src/config/license.rs | 2 +- src/matches.rs | 9 +++++++-- tests/source/issue-3213.rs | 7 +++++++ tests/source/match.rs | 2 +- tests/target/issue-3213.rs | 11 +++++++++++ tests/target/match.rs | 2 +- 6 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 tests/source/issue-3213.rs create mode 100644 tests/target/issue-3213.rs diff --git a/src/config/license.rs b/src/config/license.rs index 630399319c1b5..b732482939364 100644 --- a/src/config/license.rs +++ b/src/config/license.rs @@ -137,7 +137,7 @@ impl TemplateParser { return Err(LicenseError::Parse(format!( "incomplete escape sequence on l. {}", parser.linum - ))) + ))); } _ => (), } diff --git a/src/matches.rs b/src/matches.rs index fc7d4cca0200a..56d2cc5c59816 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -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()`. @@ -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(",")) }; diff --git a/tests/source/issue-3213.rs b/tests/source/issue-3213.rs new file mode 100644 index 0000000000000..a00ec4d36619c --- /dev/null +++ b/tests/source/issue-3213.rs @@ -0,0 +1,7 @@ +fn foo() { + match 0 { + 0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, + 1 => AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, + _ => "", + }; +} diff --git a/tests/source/match.rs b/tests/source/match.rs index 116f5f718b9c4..b226d60b7c688 100644 --- a/tests/source/match.rs +++ b/tests/source/match.rs @@ -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())); }, } } diff --git a/tests/target/issue-3213.rs b/tests/target/issue-3213.rs new file mode 100644 index 0000000000000..bd2ee48138a64 --- /dev/null +++ b/tests/target/issue-3213.rs @@ -0,0 +1,11 @@ +fn foo() { + match 0 { + 0 => { + return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + } + 1 => { + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + } + _ => "", + }; +} diff --git a/tests/target/match.rs b/tests/target/match.rs index 31c09550aaf34..f45574ee46c94 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -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())); } } }