Skip to content

Commit d810c30

Browse files
authored
Merge pull request #3935 from rchaser53/issue-3934
change last_pos when expr has attribute
2 parents de90f56 + 4cb8707 commit d810c30

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/closures.rs

Lines changed: 9 additions & 2 deletions
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

src/expr.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,17 @@ pub(crate) fn rewrite_block_with_visitor(
521521
let open_pos = snippet.find_uncommented("{")?;
522522
visitor.last_pos = block.span.lo() + BytePos(open_pos as u32)
523523
}
524-
(ast::BlockCheckMode::Default, None) => visitor.last_pos = block.span.lo(),
524+
(ast::BlockCheckMode::Default, None) => {
525+
visitor.last_pos = block.span.lo();
526+
if let Some(attrs) = attrs {
527+
if let Some(first) = attrs.first() {
528+
let first_lo_span = first.span.lo();
529+
if first_lo_span < visitor.last_pos {
530+
visitor.last_pos = first_lo_span;
531+
}
532+
}
533+
}
534+
}
525535
}
526536

527537
let inner_attrs = attrs.map(inner_attributes);

tests/target/issue-3934.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod repro {
2+
pub fn push() -> Result<(), ()> {
3+
self.api.map_api_result(|api| {
4+
#[allow(deprecated)]
5+
match api.apply_extrinsic_before_version_4_with_context()? {}
6+
})
7+
}
8+
}

0 commit comments

Comments
 (0)