Skip to content

Commit d03d9a4

Browse files
committed
end expressions like return/continue/break with a semicolon
Close rust-lang#3213
1 parent 4f233a5 commit d03d9a4

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

src/config/license.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl TemplateParser {
137137
return Err(LicenseError::Parse(format!(
138138
"incomplete escape sequence on l. {}",
139139
parser.linum
140-
)))
140+
)));
141141
}
142142
_ => (),
143143
}

src/matches.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use source_map::SpanUtils;
2929
use spanned::Spanned;
3030
use utils::{
3131
contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp,
32-
ptr_vec_to_ref_vec, trimmed_last_line_width,
32+
ptr_vec_to_ref_vec, semicolon_for_expr, trimmed_last_line_width,
3333
};
3434

3535
/// A simple wrapper type against `ast::Arm`. Used inside `write_list()`.
@@ -413,7 +413,12 @@ fn rewrite_match_body(
413413
} else {
414414
""
415415
};
416-
("{", format!("{}}}{}", indent_str, comma))
416+
let semicolon = if semicolon_for_expr(context, body) {
417+
";"
418+
} else {
419+
""
420+
};
421+
("{", format!("{}{}}}{}", semicolon, indent_str, comma))
417422
} else {
418423
("", String::from(","))
419424
};

tests/source/issue-3213.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn foo() {
2+
match 0 {
3+
0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
4+
1 => AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
5+
_ => "",
6+
};
7+
}

tests/source/match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ fn issue_3005() {
545545
{
546546
return NoCalcLength::parse_dimension(context, value, unit)
547547
.map(LengthOrPercentage::Length)
548-
.map_err(|()| location.new_unexpected_token_error(token.clone()))
548+
.map_err(|()| location.new_unexpected_token_error(token.clone()));
549549
},
550550
}
551551
}

tests/target/issue-3213.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn foo() {
2+
match 0 {
3+
0 => {
4+
return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
5+
}
6+
1 => {
7+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
8+
}
9+
_ => "",
10+
};
11+
}

tests/target/match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ fn issue_3005() {
572572
} if num_context.is_ok(context.parsing_mode, value) => {
573573
return NoCalcLength::parse_dimension(context, value, unit)
574574
.map(LengthOrPercentage::Length)
575-
.map_err(|()| location.new_unexpected_token_error(token.clone()))
575+
.map_err(|()| location.new_unexpected_token_error(token.clone()));
576576
}
577577
}
578578
}

0 commit comments

Comments
 (0)