Skip to content

Commit 760ec07

Browse files
authored
Merge pull request #3510 from topecongiro/issue3509
Fix duplication of attributes on a match arm's body
2 parents 3dc625c + b57e0e2 commit 760ec07

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/matches.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn rewrite_match_arm(
263263
false,
264264
)?;
265265

266-
let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span.lo());
266+
let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span().lo());
267267
rewrite_match_body(
268268
context,
269269
&arm.body,
@@ -364,7 +364,8 @@ fn rewrite_match_body(
364364
shape.indent
365365
};
366366

367-
let forbid_same_line = has_guard && pats_str.contains('\n') && !is_empty_block;
367+
let forbid_same_line =
368+
(has_guard && pats_str.contains('\n') && !is_empty_block) || !body.attrs.is_empty();
368369

369370
// Look for comments between `=>` and the start of the body.
370371
let arrow_comment = {

tests/source/attrib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,18 @@ fn stmt_expr_attributes() {
217217
#[must_use]
218218
foo = false ;
219219
}
220+
221+
// #3509
222+
fn issue3509() {
223+
match MyEnum {
224+
MyEnum::Option1 if cfg!(target_os = "windows") =>
225+
#[cfg(target_os = "windows")]{
226+
1
227+
}
228+
}
229+
match MyEnum {
230+
MyEnum::Option1 if cfg!(target_os = "windows") =>
231+
#[cfg(target_os = "windows")]
232+
1,
233+
}
234+
}

tests/target/attrib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,21 @@ fn stmt_expr_attributes() {
252252
#[must_use]
253253
foo = false;
254254
}
255+
256+
// #3509
257+
fn issue3509() {
258+
match MyEnum {
259+
MyEnum::Option1 if cfg!(target_os = "windows") =>
260+
#[cfg(target_os = "windows")]
261+
{
262+
1
263+
}
264+
}
265+
match MyEnum {
266+
MyEnum::Option1 if cfg!(target_os = "windows") =>
267+
{
268+
#[cfg(target_os = "windows")]
269+
1
270+
}
271+
}
272+
}

0 commit comments

Comments
 (0)