1
- use rustc_span:: { BytePos , Pos , Span } ;
1
+ use rustc_span:: { BytePos , Span } ;
2
2
3
3
use crate :: config:: { file_lines:: FileLines , FileName } ;
4
4
@@ -140,28 +140,15 @@ impl<'a> FmtVisitor<'a> {
140
140
where
141
141
F : Fn ( & mut FmtVisitor < ' _ > , & str , & str ) ,
142
142
{
143
- // Get a snippet from the file start to the span's hi without allocating.
144
- // We need it to determine what precedes the current comment. If the comment
145
- // follows code on the same line, we won't touch it.
146
- let big_span_lo = self . snippet_provider . start_pos ( ) ;
147
- let big_snippet = self . snippet_provider . entire_snippet ( ) ;
148
- let big_diff = ( span. lo ( ) - big_span_lo) . to_usize ( ) ;
149
-
150
143
let snippet = self . snippet ( span) ;
151
144
152
145
debug ! ( "write_snippet `{}`" , snippet) ;
153
146
154
- self . write_snippet_inner ( big_snippet , snippet, big_diff , span, process_last_snippet) ;
147
+ self . write_snippet_inner ( snippet, span, process_last_snippet) ;
155
148
}
156
149
157
- fn write_snippet_inner < F > (
158
- & mut self ,
159
- big_snippet : & str ,
160
- snippet : & str ,
161
- big_diff : usize ,
162
- span : Span ,
163
- process_last_snippet : F ,
164
- ) where
150
+ fn write_snippet_inner < F > ( & mut self , snippet : & str , span : Span , process_last_snippet : F )
151
+ where
165
152
F : Fn ( & mut FmtVisitor < ' _ > , & str , & str ) ,
166
153
{
167
154
// Trim whitespace from the right hand side of each line.
@@ -200,13 +187,7 @@ impl<'a> FmtVisitor<'a> {
200
187
let newline_count = lf_count + crlf_count;
201
188
if CodeCharKind :: Comment == kind && within_file_lines_range {
202
189
// 1: comment.
203
- self . process_comment (
204
- & mut status,
205
- snippet,
206
- & big_snippet[ ..( offset + big_diff) ] ,
207
- offset,
208
- subslice,
209
- ) ;
190
+ self . process_comment ( & mut status, snippet, offset, subslice) ;
210
191
} else if subslice. trim ( ) . is_empty ( ) && newline_count > 0 && within_file_lines_range {
211
192
// 2: blank lines.
212
193
self . push_vertical_spaces ( newline_count) ;
@@ -233,11 +214,11 @@ impl<'a> FmtVisitor<'a> {
233
214
& mut self ,
234
215
status : & mut SnippetStatus ,
235
216
snippet : & str ,
236
- big_snippet : & str ,
237
217
offset : usize ,
238
218
subslice : & str ,
239
219
) {
240
- let last_char = big_snippet
220
+ let last_char = self
221
+ . buffer
241
222
. chars ( )
242
223
. rev ( )
243
224
. find ( |rev_c| ![ ' ' , '\t' ] . contains ( rev_c) ) ;
0 commit comments