Merge pull request #3510 from topecongiro/issue3509

Fix duplication of attributes on a match arm's body
This commit is contained in:
Seiichi Uchida 2019-04-17 11:39:44 -07:00 committed by GitHub
commit 760ec07978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View File

@ -263,7 +263,7 @@ fn rewrite_match_arm(
false,
)?;
let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span.lo());
let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span().lo());
rewrite_match_body(
context,
&arm.body,
@ -364,7 +364,8 @@ fn rewrite_match_body(
shape.indent
};
let forbid_same_line = has_guard && pats_str.contains('\n') && !is_empty_block;
let forbid_same_line =
(has_guard && pats_str.contains('\n') && !is_empty_block) || !body.attrs.is_empty();
// Look for comments between `=>` and the start of the body.
let arrow_comment = {

View File

@ -217,3 +217,18 @@ fn stmt_expr_attributes() {
#[must_use]
foo = false ;
}
// #3509
fn issue3509() {
match MyEnum {
MyEnum::Option1 if cfg!(target_os = "windows") =>
#[cfg(target_os = "windows")]{
1
}
}
match MyEnum {
MyEnum::Option1 if cfg!(target_os = "windows") =>
#[cfg(target_os = "windows")]
1,
}
}

View File

@ -252,3 +252,21 @@ fn stmt_expr_attributes() {
#[must_use]
foo = false;
}
// #3509
fn issue3509() {
match MyEnum {
MyEnum::Option1 if cfg!(target_os = "windows") =>
#[cfg(target_os = "windows")]
{
1
}
}
match MyEnum {
MyEnum::Option1 if cfg!(target_os = "windows") =>
{
#[cfg(target_os = "windows")]
1
}
}
}