Skip to content

Commit 757c440

Browse files
authored
Rollup merge of rust-lang#58116 - topecongiro:wrong-span-assignment, r=petrochenkov
Include the span of attributes of the lhs to the span of the assignment expression This PR adds the span of attributes of the lhs to the span of the assignment expression. Currently with the following code, `#[attr]` is not included to the span of the assignment (`foo = true`). ```rust #[attr] foo = true; ``` The rational behind this change is that as libsyntax user I expect the span of the parent node includes every span of child nodes. cc rust-lang/rustfmt#3313, rust-lang#15701.
2 parents 3f731d5 + 9851a29 commit 757c440

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libsyntax/parse/parser.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3455,6 +3455,14 @@ impl<'a> Parser<'a> {
34553455
}),
34563456
}?;
34573457

3458+
// Make sure that the span of the parent node is larger than the span of lhs and rhs,
3459+
// including the attributes.
3460+
let lhs_span = lhs
3461+
.attrs
3462+
.iter()
3463+
.filter(|a| a.style == AttrStyle::Outer)
3464+
.next()
3465+
.map_or(lhs_span, |a| a.span);
34583466
let span = lhs_span.to(rhs.span);
34593467
lhs = match op {
34603468
AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide |

0 commit comments

Comments
 (0)