1
+ use crate :: utils:: { snippet, span_lint, span_lint_and_sugg} ;
1
2
use rustc:: lint:: { EarlyContext , EarlyLintPass , LintArray , LintPass } ;
2
3
use rustc:: { declare_tool_lint, lint_array} ;
4
+ use std:: borrow:: Cow ;
3
5
use syntax:: ast:: * ;
6
+ use syntax:: parse:: { parser, token} ;
4
7
use syntax:: tokenstream:: { ThinTokenStream , TokenStream } ;
5
- use syntax:: parse:: { token, parser} ;
6
- use std:: borrow:: Cow ;
7
- use crate :: utils:: { span_lint, span_lint_and_sugg, snippet} ;
8
8
9
9
/// **What it does:** This lint warns when you use `println!("")` to
10
10
/// print a newline.
@@ -196,24 +196,34 @@ impl EarlyLintPass for Pass {
196
196
span_lint ( cx, PRINT_STDOUT , mac. span , "use of `print!`" ) ;
197
197
if let Some ( fmtstr) = check_tts ( cx, & mac. node . tts , false ) . 0 {
198
198
if fmtstr. ends_with ( "\\ n" ) && !fmtstr. ends_with ( "\\ n\\ n" ) {
199
- span_lint ( cx, PRINT_WITH_NEWLINE , mac. span ,
200
- "using `print!()` with a format string that ends in a \
201
- single newline, consider using `println!()` instead") ;
199
+ span_lint (
200
+ cx,
201
+ PRINT_WITH_NEWLINE ,
202
+ mac. span ,
203
+ "using `print!()` with a format string that ends in a \
204
+ single newline, consider using `println!()` instead",
205
+ ) ;
202
206
}
203
207
}
204
208
} else if mac. node . path == "write" {
205
209
if let Some ( fmtstr) = check_tts ( cx, & mac. node . tts , true ) . 0 {
206
210
if fmtstr. ends_with ( "\\ n" ) && !fmtstr. ends_with ( "\\ n\\ n" ) {
207
- span_lint ( cx, WRITE_WITH_NEWLINE , mac. span ,
208
- "using `write!()` with a format string that ends in a \
209
- single newline, consider using `writeln!()` instead") ;
211
+ span_lint (
212
+ cx,
213
+ WRITE_WITH_NEWLINE ,
214
+ mac. span ,
215
+ "using `write!()` with a format string that ends in a \
216
+ single newline, consider using `writeln!()` instead",
217
+ ) ;
210
218
}
211
219
}
212
220
} else if mac. node . path == "writeln" {
213
221
let check_tts = check_tts ( cx, & mac. node . tts , true ) ;
214
222
if let Some ( fmtstr) = check_tts. 0 {
215
223
if fmtstr == "" {
216
- let suggestion = check_tts. 1 . map_or ( Cow :: Borrowed ( "v" ) , |expr| snippet ( cx, expr. span , "v" ) ) ;
224
+ let suggestion = check_tts
225
+ . 1
226
+ . map_or ( Cow :: Borrowed ( "v" ) , |expr| snippet ( cx, expr. span , "v" ) ) ;
217
227
218
228
span_lint_and_sugg (
219
229
cx,
@@ -231,13 +241,7 @@ impl EarlyLintPass for Pass {
231
241
232
242
fn check_tts < ' a > ( cx : & EarlyContext < ' a > , tts : & ThinTokenStream , is_write : bool ) -> ( Option < String > , Option < Expr > ) {
233
243
let tts = TokenStream :: from ( tts. clone ( ) ) ;
234
- let mut parser = parser:: Parser :: new (
235
- & cx. sess . parse_sess ,
236
- tts,
237
- None ,
238
- false ,
239
- false ,
240
- ) ;
244
+ let mut parser = parser:: Parser :: new ( & cx. sess . parse_sess , tts, None , false , false ) ;
241
245
let mut expr: Option < Expr > = None ;
242
246
if is_write {
243
247
expr = match parser. parse_expr ( ) . map_err ( |mut err| err. cancel ( ) ) {
@@ -270,11 +274,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -
270
274
args. push ( arg) ;
271
275
}
272
276
}
273
- let lint = if is_write {
274
- WRITE_LITERAL
275
- } else {
276
- PRINT_LITERAL
277
- } ;
277
+ let lint = if is_write { WRITE_LITERAL } else { PRINT_LITERAL } ;
278
278
let mut idx = 0 ;
279
279
loop {
280
280
if !parser. eat ( & token:: Comma ) {
@@ -299,9 +299,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -
299
299
let mut seen = false ;
300
300
for arg in & args {
301
301
match arg. position {
302
- | ArgumentImplicitlyIs ( n)
303
- | ArgumentIs ( n)
304
- => if n == idx {
302
+ ArgumentImplicitlyIs ( n) | ArgumentIs ( n) => if n == idx {
305
303
all_simple &= arg. format == SIMPLE ;
306
304
seen = true ;
307
305
} ,
@@ -320,9 +318,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -
320
318
let mut seen = false ;
321
319
for arg in & args {
322
320
match arg. position {
323
- | ArgumentImplicitlyIs ( _)
324
- | ArgumentIs ( _)
325
- => { } ,
321
+ ArgumentImplicitlyIs ( _) | ArgumentIs ( _) => { } ,
326
322
ArgumentNamed ( name) => if * p == name {
327
323
seen = true ;
328
324
all_simple &= arg. format == SIMPLE ;
0 commit comments