Skip to content

Commit 0a8ceaf

Browse files
committed
rustfmt clippy_lints/src/write.rs
1 parent 3262f92 commit 0a8ceaf

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

clippy_lints/src/write.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use crate::utils::{snippet, span_lint, span_lint_and_sugg};
12
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
23
use rustc::{declare_tool_lint, lint_array};
4+
use std::borrow::Cow;
35
use syntax::ast::*;
6+
use syntax::parse::{parser, token};
47
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};
88

99
/// **What it does:** This lint warns when you use `println!("")` to
1010
/// print a newline.
@@ -196,24 +196,34 @@ impl EarlyLintPass for Pass {
196196
span_lint(cx, PRINT_STDOUT, mac.span, "use of `print!`");
197197
if let Some(fmtstr) = check_tts(cx, &mac.node.tts, false).0 {
198198
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+
);
202206
}
203207
}
204208
} else if mac.node.path == "write" {
205209
if let Some(fmtstr) = check_tts(cx, &mac.node.tts, true).0 {
206210
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+
);
210218
}
211219
}
212220
} else if mac.node.path == "writeln" {
213221
let check_tts = check_tts(cx, &mac.node.tts, true);
214222
if let Some(fmtstr) = check_tts.0 {
215223
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"));
217227

218228
span_lint_and_sugg(
219229
cx,
@@ -231,13 +241,7 @@ impl EarlyLintPass for Pass {
231241

232242
fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -> (Option<String>, Option<Expr>) {
233243
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);
241245
let mut expr: Option<Expr> = None;
242246
if is_write {
243247
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) -
270274
args.push(arg);
271275
}
272276
}
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 };
278278
let mut idx = 0;
279279
loop {
280280
if !parser.eat(&token::Comma) {
@@ -299,9 +299,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -
299299
let mut seen = false;
300300
for arg in &args {
301301
match arg.position {
302-
| ArgumentImplicitlyIs(n)
303-
| ArgumentIs(n)
304-
=> if n == idx {
302+
ArgumentImplicitlyIs(n) | ArgumentIs(n) => if n == idx {
305303
all_simple &= arg.format == SIMPLE;
306304
seen = true;
307305
},
@@ -320,9 +318,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -
320318
let mut seen = false;
321319
for arg in &args {
322320
match arg.position {
323-
| ArgumentImplicitlyIs(_)
324-
| ArgumentIs(_)
325-
=> {},
321+
ArgumentImplicitlyIs(_) | ArgumentIs(_) => {},
326322
ArgumentNamed(name) => if *p == name {
327323
seen = true;
328324
all_simple &= arg.format == SIMPLE;

0 commit comments

Comments
 (0)