1
- use proc_macro:: { LineColumn , Span } ;
2
- use proc_macro2:: { Delimiter , Ident , Spacing , TokenStream , TokenTree } ;
1
+ use proc_macro:: Span ;
2
+ use proc_macro2:: { Delimiter , Ident , Spacing , TokenStream , TokenTree , LineColumn } ;
3
3
use quote:: quote_spanned;
4
4
use std:: collections:: BTreeMap ;
5
5
use std:: fmt:: Write ;
@@ -52,7 +52,9 @@ impl EmbedPython {
52
52
53
53
while let Some ( token) = tokens. next ( ) {
54
54
let span = token. span ( ) . unwrap ( ) ;
55
- self . add_whitespace ( span, span. start ( ) ) ?;
55
+ let start_span = span. start ( ) ;
56
+ let lc = LineColumn { line : start_span. line ( ) , column : start_span. column ( ) } ;
57
+ self . add_whitespace ( span, lc) ?;
56
58
57
59
match & token {
58
60
TokenTree :: Group ( x) => {
@@ -65,9 +67,10 @@ impl EmbedPython {
65
67
self . python . push_str ( start) ;
66
68
self . loc . column += start. len ( ) ;
67
69
self . add ( x. stream ( ) ) ?;
68
- let mut end_loc = token. span ( ) . unwrap ( ) . end ( ) ;
69
- end_loc. column = end_loc. column . saturating_sub ( end. len ( ) ) ;
70
- self . add_whitespace ( span, end_loc) ?;
70
+ let end_loc = token. span ( ) . unwrap ( ) . end ( ) ;
71
+ let end_col = end_loc. column ( ) . saturating_sub ( end. len ( ) ) ;
72
+ let elc = LineColumn { line : end_loc. line ( ) , column : end_col } ;
73
+ self . add_whitespace ( span, elc) ?;
71
74
self . python . push_str ( end) ;
72
75
self . loc . column += end. len ( ) ;
73
76
}
@@ -106,7 +109,8 @@ impl EmbedPython {
106
109
}
107
110
TokenTree :: Ident ( x) => {
108
111
write ! ( & mut self . python, "{}" , x) . unwrap ( ) ;
109
- self . loc = token. span ( ) . unwrap ( ) . end ( ) ;
112
+ let end_span = token. span ( ) . unwrap ( ) . end ( ) ;
113
+ self . loc = LineColumn { line : end_span. line ( ) , column : end_span. column ( ) } ;
110
114
}
111
115
TokenTree :: Literal ( x) => {
112
116
let s = x. to_string ( ) ;
@@ -119,7 +123,8 @@ impl EmbedPython {
119
123
self . python . pop ( ) ;
120
124
}
121
125
self . python += & s;
122
- self . loc = token. span ( ) . unwrap ( ) . end ( ) ;
126
+ let end_span = token. span ( ) . unwrap ( ) . end ( ) ;
127
+ self . loc = LineColumn { line : end_span. line ( ) , column : end_span. column ( ) } ;
123
128
}
124
129
}
125
130
}
0 commit comments