@@ -150,13 +150,14 @@ fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
150
150
lhs
151
151
}
152
152
153
- #[ derive( Clone , PartialEq ) ]
153
+ #[ derive( Clone , Copy , PartialEq ) ]
154
154
enum PrevTokenKind {
155
155
DocComment ,
156
156
Comma ,
157
157
Plus ,
158
158
Interpolated ,
159
159
Eof ,
160
+ Ident ,
160
161
Other ,
161
162
}
162
163
@@ -1040,6 +1041,7 @@ impl<'a> Parser<'a> {
1040
1041
token:: BinOp ( token:: Plus ) => PrevTokenKind :: Plus ,
1041
1042
token:: Interpolated ( ..) => PrevTokenKind :: Interpolated ,
1042
1043
token:: Eof => PrevTokenKind :: Eof ,
1044
+ token:: Ident ( ..) => PrevTokenKind :: Ident ,
1043
1045
_ => PrevTokenKind :: Other ,
1044
1046
} ;
1045
1047
@@ -2777,10 +2779,15 @@ impl<'a> Parser<'a> {
2777
2779
self . expected_tokens . push ( TokenType :: Operator ) ;
2778
2780
while let Some ( op) = AssocOp :: from_token ( & self . token ) {
2779
2781
2780
- let lhs_span = if self . prev_token_kind == PrevTokenKind :: Interpolated {
2781
- self . prev_span
2782
- } else {
2783
- lhs. span
2782
+ // Adjust the span for interpolated LHS to point to the `$lhs` token and not to what
2783
+ // it refers to. Interpolated identifiers are unwrapped early and never show up here
2784
+ // as `PrevTokenKind::Interpolated` so if LHS is a single identifier we always process
2785
+ // it as "interpolated", it doesn't change the answer for non-interpolated idents.
2786
+ let lhs_span = match ( self . prev_token_kind , & lhs. node ) {
2787
+ ( PrevTokenKind :: Interpolated , _) => self . prev_span ,
2788
+ ( PrevTokenKind :: Ident , & ExprKind :: Path ( None , ref path) )
2789
+ if path. segments . len ( ) == 1 => self . prev_span ,
2790
+ _ => lhs. span ,
2784
2791
} ;
2785
2792
2786
2793
let cur_op_span = self . span ;
0 commit comments