Skip to content

Commit a178031

Browse files
fix: inverted span on attrs within closure
1 parent a88f028 commit a178031

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: src/closures.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,15 @@ fn rewrite_closure_with_block(
155155
rules: ast::BlockCheckMode::Default,
156156
span: body.span,
157157
};
158-
let block =
159-
crate::expr::rewrite_block_with_visitor(context, "", &block, None, None, shape, false)?;
158+
let block = crate::expr::rewrite_block_with_visitor(
159+
context,
160+
"",
161+
&block,
162+
Some(&body.attrs),
163+
None,
164+
shape,
165+
false,
166+
)?;
160167
Some(format!("{} {}", prefix, block))
161168
}
162169

Diff for: src/expr.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,17 @@ pub(crate) fn rewrite_block_with_visitor(
525525
let open_pos = snippet.find_uncommented("{")?;
526526
visitor.last_pos = block.span.lo() + BytePos(open_pos as u32)
527527
}
528-
(ast::BlockCheckMode::Default, None) => visitor.last_pos = block.span.lo(),
528+
(ast::BlockCheckMode::Default, None) => {
529+
visitor.last_pos = block.span.lo();
530+
if let Some(attrs) = attrs {
531+
if let Some(first) = attrs.first() {
532+
let first_lo_span = first.span.lo();
533+
if first_lo_span < visitor.last_pos {
534+
visitor.last_pos = first_lo_span;
535+
}
536+
}
537+
}
538+
}
529539
}
530540

531541
let inner_attrs = attrs.map(inner_attributes);

0 commit comments

Comments
 (0)