Skip to content

Commit

Permalink
Merge pull request rust-lang#3510 from topecongiro/issue3509
Browse files Browse the repository at this point in the history
Fix duplication of attributes on a match arm's body
  • Loading branch information
topecongiro authored Apr 17, 2019
2 parents 3dc625c + b57e0e2 commit 760ec07
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
15 changes: 15 additions & 0 deletions tests/source/attrib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
18 changes: 18 additions & 0 deletions tests/target/attrib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 760ec07

Please sign in to comment.