Forbid adding or removing a block from match arms inside macro calls (#3756)

This commit is contained in:
Seiichi Uchida 2019-08-28 20:50:41 +09:00 committed by GitHub
parent a09ca681de
commit deb329a6bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 17 deletions

View File

@ -278,6 +278,7 @@ fn block_can_be_flattened<'a>(
match expr.node {
ast::ExprKind::Block(ref block, _)
if !is_unsafe_block(block)
&& !context.inside_macro()
&& is_simple_block(block, Some(&expr.attrs), context.source_map) =>
{
Some(&*block)
@ -394,7 +395,8 @@ fn rewrite_match_body(
}
let indent_str = shape.indent.to_string_with_newline(context.config);
let (body_prefix, body_suffix) = if context.config.match_arm_blocks() {
let (body_prefix, body_suffix) =
if context.config.match_arm_blocks() && !context.inside_macro() {
let comma = if context.config.match_block_trailing_comma() {
","
} else {
@ -468,7 +470,9 @@ fn rewrite_match_body(
next_line_body_shape.width,
);
match (orig_body, next_line_body) {
(Some(ref orig_str), Some(ref next_line_str)) if orig_str == next_line_str => {
(Some(ref orig_str), Some(ref next_line_str))
if orig_str == next_line_str || context.inside_macro() =>
{
combine_orig_body(orig_str)
}
(Some(ref orig_str), Some(ref next_line_str))

View File

@ -473,5 +473,14 @@ pub fn fold_abi<V: Fold + ?Sized>(_visitor: &mut V, _i: Abi) -> Abi {
// #3463
x ! {()}
// #3746
f!(match a {
4 =>
&[
(3, false), // Missing
(4, true) // I-frame
] [..],
});
// #3583
foo!(|x = y|);

View File

@ -1050,5 +1050,13 @@ pub fn fold_abi<V: Fold + ?Sized>(_visitor: &mut V, _i: Abi) -> Abi {
// #3463
x! {()}
// #3746
f!(match a {
4 => &[
(3, false), // Missing
(4, true) // I-frame
][..],
});
// #3583
foo!(|x = y|);