@@ -150,13 +150,14 @@ fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
150150 lhs
151151}
152152
153- #[ derive( Clone , PartialEq ) ]
153+ #[ derive( Clone , Copy , PartialEq ) ]
154154enum PrevTokenKind {
155155 DocComment ,
156156 Comma ,
157157 Plus ,
158158 Interpolated ,
159159 Eof ,
160+ Ident ,
160161 Other ,
161162}
162163
@@ -1040,6 +1041,7 @@ impl<'a> Parser<'a> {
10401041 token:: BinOp ( token:: Plus ) => PrevTokenKind :: Plus ,
10411042 token:: Interpolated ( ..) => PrevTokenKind :: Interpolated ,
10421043 token:: Eof => PrevTokenKind :: Eof ,
1044+ token:: Ident ( ..) => PrevTokenKind :: Ident ,
10431045 _ => PrevTokenKind :: Other ,
10441046 } ;
10451047
@@ -2774,10 +2776,15 @@ impl<'a> Parser<'a> {
27742776 self . expected_tokens . push ( TokenType :: Operator ) ;
27752777 while let Some ( op) = AssocOp :: from_token ( & self . token ) {
27762778
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 ,
27812788 } ;
27822789
27832790 let cur_op_span = self . span ;
0 commit comments