diff options
| author | kennytm <kennytm@gmail.com> | 2019-02-06 00:29:02 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-06 00:29:02 +0900 |
| commit | 757c4407db9d33f0a8bf03a53bbfc5df55154ae3 (patch) | |
| tree | 46111f76de8ce4a8848299dd1e5b511cf7d627c1 /src/libsyntax | |
| parent | 3f731d56b61838c3782b026b173521f9a08e0cbd (diff) | |
| parent | 9851a296885cc745eccbc33858915d08e839eadc (diff) | |
| download | rust-757c4407db9d33f0a8bf03a53bbfc5df55154ae3.tar.gz rust-757c4407db9d33f0a8bf03a53bbfc5df55154ae3.zip | |
Rollup merge of #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 https://github.com/rust-lang/rustfmt/issues/3313, https://github.com/rust-lang/rust/issues/15701.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 514b2952c50..1c02a80df46 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3455,6 +3455,14 @@ impl<'a> Parser<'a> { }), }?; + // Make sure that the span of the parent node is larger than the span of lhs and rhs, + // including the attributes. + let lhs_span = lhs + .attrs + .iter() + .filter(|a| a.style == AttrStyle::Outer) + .next() + .map_or(lhs_span, |a| a.span); let span = lhs_span.to(rhs.span); lhs = match op { AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | |
