@@ -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
@@ -2774,10 +2776,15 @@ impl<'a> Parser<'a> {
2774
2776
self . expected_tokens . push ( TokenType :: Operator ) ;
2775
2777
while let Some ( op) = AssocOp :: from_token ( & self . token ) {
2776
2778
2777
- let lhs_span = if self . prev_token_kind == PrevTokenKind :: Interpolated {
2778
- self . prev_span
2779
- } else {
2780
- lhs. span
2779
+ // Adjust the span for interpolated LHS to point to the `$lhs` token and not to what
2780
+ // it refers to. Interpolated identifiers are unwrapped early and never show up here
2781
+ // as `PrevTokenKind::Interpolated` so if LHS is a single identifier we always process
2782
+ // it as "interpolated", it doesn't change the answer for non-interpolated idents.
2783
+ let lhs_span = match ( self . prev_token_kind , & lhs. node ) {
2784
+ ( PrevTokenKind :: Interpolated , _) => self . prev_span ,
2785
+ ( PrevTokenKind :: Ident , & ExprKind :: Path ( None , ref path) )
2786
+ if path. segments . len ( ) == 1 => self . prev_span ,
2787
+ _ => lhs. span ,
2781
2788
} ;
2782
2789
2783
2790
let cur_op_span = self . span ;
0 commit comments