From 888076b698fb8212c135f361eaa12843d6959cf1 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Thu, 12 Oct 2017 03:18:43 -0300 Subject: [PATCH 1/8] Add suggest_print lint --- clippy_lints/src/lib.rs | 3 + clippy_lints/src/suggest_print.rs | 102 ++++++++++++++++++++++++++++++ tests/ui/suggest_print.rs | 46 ++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 clippy_lints/src/suggest_print.rs create mode 100644 tests/ui/suggest_print.rs diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 0f27a74ac8e3..2e481151d297 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -145,6 +145,7 @@ pub mod serde_api; pub mod shadow; pub mod should_assert_eq; pub mod strings; +pub mod suggest_print; pub mod swap; pub mod temporary_assignment; pub mod transmute; @@ -326,6 +327,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount); reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold)); reg.register_late_lint_pass(box should_assert_eq::ShouldAssertEq); + reg.register_late_lint_pass(box suggest_print::Pass); reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue); reg.register_early_lint_pass(box literal_digit_grouping::LiteralDigitGrouping); reg.register_late_lint_pass(box use_self::UseSelf); @@ -540,6 +542,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { serde_api::SERDE_API_MISUSE, should_assert_eq::SHOULD_ASSERT_EQ, strings::STRING_LIT_AS_BYTES, + suggest_print::SUGGEST_PRINT, swap::ALMOST_SWAPPED, swap::MANUAL_SWAP, temporary_assignment::TEMPORARY_ASSIGNMENT, diff --git a/clippy_lints/src/suggest_print.rs b/clippy_lints/src/suggest_print.rs new file mode 100644 index 000000000000..0ef7f1fe56f0 --- /dev/null +++ b/clippy_lints/src/suggest_print.rs @@ -0,0 +1,102 @@ +use rustc::hir::*; +use rustc::lint::*; +use utils::{is_expn_of, match_def_path, resolve_node, span_lint}; +use utils::opt_def_id; + +/// **What it does:** Checks for usage of `write!()` / `writeln()!` which can be +/// replaced with `(e)print!()` / `(e)println!()` +/// +/// **Why is this bad?** Using `(e)println! is clearer and more concise +/// +/// **Known problems:** None. +/// +/// **Example:** +/// ```rust +/// // this would be clearer as `eprintln!("foo: {:?}", bar);` +/// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap(); +/// ``` +declare_lint! { + pub SUGGEST_PRINT, + Warn, + "using `write!()` family of functions instead of `print!()` family of \ + functions" +} + +#[derive(Copy, Clone, Debug)] +pub struct Pass; + +impl LintPass for Pass { + fn get_lints(&self) -> LintArray { + lint_array!( + SUGGEST_PRINT + ) + } +} + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { + fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { + if_let_chain! {[ + // match call to unwrap + let ExprMethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.node, + unwrap_fun.name == "unwrap", + // match call to write_fmt + unwrap_args.len() > 0, + let ExprMethodCall(ref write_fun, _, ref write_args) = + unwrap_args[0].node, + write_fun.name == "write_fmt", + // match calls to std::io::stdout() / std::io::stderr () + write_args.len() > 0, + let ExprCall(ref dest_fun, _) = write_args[0].node, + let ExprPath(ref qpath) = dest_fun.node, + let Some(dest_fun_id) = + opt_def_id(resolve_node(cx, qpath, dest_fun.hir_id)), + let Some(dest_name) = if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stdout"]) { + Some("stdout") + } else if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stderr"]) { + Some("stderr") + } else { + None + }, + ], { + let dest_expr = &write_args[0]; + let (span, calling_macro) = + if let Some(span) = is_expn_of(dest_expr.span, "write") { + (span, Some("write")) + } else if let Some(span) = is_expn_of(dest_expr.span, "writeln") { + (span, Some("writeln")) + } else { + (dest_expr.span, None) + }; + let prefix = if dest_name == "stderr" { + "e" + } else { + "" + }; + if let Some(macro_name) = calling_macro { + span_lint( + cx, + SUGGEST_PRINT, + span, + &format!( + "use of `{}!({}, ...).unwrap()`. Consider using `{}{}!` instead", + macro_name, + dest_name, + prefix, + macro_name.replace("write", "print") + ) + ); + } else { + span_lint( + cx, + SUGGEST_PRINT, + span, + &format!( + "use of `{}.write_fmt(...).unwrap()`. Consider using `{}print!` instead", + dest_name, + prefix, + ) + ); + } + }} + } +} diff --git a/tests/ui/suggest_print.rs b/tests/ui/suggest_print.rs new file mode 100644 index 000000000000..0466d6c0b609 --- /dev/null +++ b/tests/ui/suggest_print.rs @@ -0,0 +1,46 @@ +#![warn(suggest_print)] + + +fn stdout() -> String { + String::new() +} + +fn stderr() -> String { + String::new() +} + +fn main() { + // these should warn + { + use std::io::Write; + write!(std::io::stdout(), "test").unwrap(); + write!(std::io::stderr(), "test").unwrap(); + writeln!(std::io::stdout(), "test").unwrap(); + writeln!(std::io::stderr(), "test").unwrap(); + std::io::stdout().write_fmt(format_args!("test")).unwrap(); + std::io::stderr().write_fmt(format_args!("test")).unwrap(); + } + // these should not warn, different destination + { + use std::fmt::Write; + let mut s = String::new(); + write!(s, "test").unwrap(); + write!(s, "test").unwrap(); + writeln!(s, "test").unwrap(); + writeln!(s, "test").unwrap(); + s.write_fmt(format_args!("test")).unwrap(); + s.write_fmt(format_args!("test")).unwrap(); + write!(stdout(), "test").unwrap(); + write!(stderr(), "test").unwrap(); + writeln!(stdout(), "test").unwrap(); + writeln!(stderr(), "test").unwrap(); + stdout().write_fmt(format_args!("test")).unwrap(); + stderr().write_fmt(format_args!("test")).unwrap(); + } + // these should not warn, no unwrap + { + use std::io::Write; + std::io::stdout().write_fmt(format_args!("test")).expect("no stdout"); + std::io::stderr().write_fmt(format_args!("test")).expect("no stderr"); + } +} From 10893805185d102c038beb196b030edf7797c114 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Thu, 12 Oct 2017 05:33:00 -0300 Subject: [PATCH 2/8] Add expected output --- tests/ui/suggest_print.stderr | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/ui/suggest_print.stderr diff --git a/tests/ui/suggest_print.stderr b/tests/ui/suggest_print.stderr new file mode 100644 index 000000000000..f83f6cf7ad35 --- /dev/null +++ b/tests/ui/suggest_print.stderr @@ -0,0 +1,38 @@ +error: use of `stdout.write_fmt(...).unwrap()`. Consider using `print!` instead + --> $DIR/suggest_print.rs:16:16 + | +16 | write!(std::io::stdout(), "test").unwrap(); + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D suggest-print` implied by `-D warnings` + +error: use of `stderr.write_fmt(...).unwrap()`. Consider using `eprint!` instead + --> $DIR/suggest_print.rs:17:16 + | +17 | write!(std::io::stderr(), "test").unwrap(); + | ^^^^^^^^^^^^^^^^^ + +error: use of `stdout.write_fmt(...).unwrap()`. Consider using `print!` instead + --> $DIR/suggest_print.rs:18:18 + | +18 | writeln!(std::io::stdout(), "test").unwrap(); + | ^^^^^^^^^^^^^^^^^ + +error: use of `stderr.write_fmt(...).unwrap()`. Consider using `eprint!` instead + --> $DIR/suggest_print.rs:19:18 + | +19 | writeln!(std::io::stderr(), "test").unwrap(); + | ^^^^^^^^^^^^^^^^^ + +error: use of `stdout.write_fmt(...).unwrap()`. Consider using `print!` instead + --> $DIR/suggest_print.rs:20:9 + | +20 | std::io::stdout().write_fmt(format_args!("test")).unwrap(); + | ^^^^^^^^^^^^^^^^^ + +error: use of `stderr.write_fmt(...).unwrap()`. Consider using `eprint!` instead + --> $DIR/suggest_print.rs:21:9 + | +21 | std::io::stderr().write_fmt(format_args!("test")).unwrap(); + | ^^^^^^^^^^^^^^^^^ + From 4105593eeeeb2ce0a7d6fb338fe71ea10c68f965 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Thu, 12 Oct 2017 05:35:13 -0300 Subject: [PATCH 3/8] Run rustfmt --- clippy_lints/src/suggest_print.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/suggest_print.rs b/clippy_lints/src/suggest_print.rs index 0ef7f1fe56f0..1bc58297476f 100644 --- a/clippy_lints/src/suggest_print.rs +++ b/clippy_lints/src/suggest_print.rs @@ -27,9 +27,7 @@ pub struct Pass; impl LintPass for Pass { fn get_lints(&self) -> LintArray { - lint_array!( - SUGGEST_PRINT - ) + lint_array!(SUGGEST_PRINT) } } @@ -50,9 +48,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let ExprPath(ref qpath) = dest_fun.node, let Some(dest_fun_id) = opt_def_id(resolve_node(cx, qpath, dest_fun.hir_id)), - let Some(dest_name) = if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stdout"]) { + let Some(dest_name) = if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stdio", "stdout"]) { Some("stdout") - } else if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stderr"]) { + } else if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stdio", "stderr"]) { Some("stderr") } else { None From e31a0941e20851933eb80b14da8d2a11b6f614b1 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Thu, 12 Oct 2017 05:53:20 -0300 Subject: [PATCH 4/8] Fix output for write macros --- clippy_lints/src/suggest_print.rs | 23 +++++++++++----------- tests/ui/suggest_print.stderr | 32 +++++++++++++++---------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/clippy_lints/src/suggest_print.rs b/clippy_lints/src/suggest_print.rs index 1bc58297476f..bf202b20057f 100644 --- a/clippy_lints/src/suggest_print.rs +++ b/clippy_lints/src/suggest_print.rs @@ -56,14 +56,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { None }, ], { - let dest_expr = &write_args[0]; - let (span, calling_macro) = - if let Some(span) = is_expn_of(dest_expr.span, "write") { - (span, Some("write")) - } else if let Some(span) = is_expn_of(dest_expr.span, "writeln") { - (span, Some("writeln")) + let write_span = unwrap_args[0].span; + let calling_macro = + // ordering is important here, since `writeln!` uses `write!` internally + if is_expn_of(write_span, "writeln").is_some() { + Some("writeln") + } else if is_expn_of(write_span, "write").is_some() { + Some("write") } else { - (dest_expr.span, None) + None }; let prefix = if dest_name == "stderr" { "e" @@ -74,9 +75,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { span_lint( cx, SUGGEST_PRINT, - span, + expr.span, &format!( - "use of `{}!({}, ...).unwrap()`. Consider using `{}{}!` instead", + "use of `{}!({}(), ...).unwrap()`. Consider using `{}{}!` instead", macro_name, dest_name, prefix, @@ -87,9 +88,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { span_lint( cx, SUGGEST_PRINT, - span, + expr.span, &format!( - "use of `{}.write_fmt(...).unwrap()`. Consider using `{}print!` instead", + "use of `{}().write_fmt(...).unwrap()`. Consider using `{}print!` instead", dest_name, prefix, ) diff --git a/tests/ui/suggest_print.stderr b/tests/ui/suggest_print.stderr index f83f6cf7ad35..bae9f6f26795 100644 --- a/tests/ui/suggest_print.stderr +++ b/tests/ui/suggest_print.stderr @@ -1,38 +1,38 @@ -error: use of `stdout.write_fmt(...).unwrap()`. Consider using `print!` instead - --> $DIR/suggest_print.rs:16:16 +error: use of `write!(stdout(), ...).unwrap()`. Consider using `print!` instead + --> $DIR/suggest_print.rs:16:9 | 16 | write!(std::io::stdout(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D suggest-print` implied by `-D warnings` -error: use of `stderr.write_fmt(...).unwrap()`. Consider using `eprint!` instead - --> $DIR/suggest_print.rs:17:16 +error: use of `write!(stderr(), ...).unwrap()`. Consider using `eprint!` instead + --> $DIR/suggest_print.rs:17:9 | 17 | write!(std::io::stderr(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: use of `stdout.write_fmt(...).unwrap()`. Consider using `print!` instead - --> $DIR/suggest_print.rs:18:18 +error: use of `writeln!(stdout(), ...).unwrap()`. Consider using `println!` instead + --> $DIR/suggest_print.rs:18:9 | 18 | writeln!(std::io::stdout(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: use of `stderr.write_fmt(...).unwrap()`. Consider using `eprint!` instead - --> $DIR/suggest_print.rs:19:18 +error: use of `writeln!(stderr(), ...).unwrap()`. Consider using `eprintln!` instead + --> $DIR/suggest_print.rs:19:9 | 19 | writeln!(std::io::stderr(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: use of `stdout.write_fmt(...).unwrap()`. Consider using `print!` instead +error: use of `stdout().write_fmt(...).unwrap()`. Consider using `print!` instead --> $DIR/suggest_print.rs:20:9 | 20 | std::io::stdout().write_fmt(format_args!("test")).unwrap(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: use of `stderr.write_fmt(...).unwrap()`. Consider using `eprint!` instead +error: use of `stderr().write_fmt(...).unwrap()`. Consider using `eprint!` instead --> $DIR/suggest_print.rs:21:9 | 21 | std::io::stderr().write_fmt(format_args!("test")).unwrap(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From a46bf3f456ee5d0bfade70dcddbad6496c5575d0 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Thu, 12 Oct 2017 05:54:33 -0300 Subject: [PATCH 5/8] Clarify lint description --- clippy_lints/src/suggest_print.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/suggest_print.rs b/clippy_lints/src/suggest_print.rs index bf202b20057f..eb1266af7b75 100644 --- a/clippy_lints/src/suggest_print.rs +++ b/clippy_lints/src/suggest_print.rs @@ -19,7 +19,7 @@ declare_lint! { pub SUGGEST_PRINT, Warn, "using `write!()` family of functions instead of `print!()` family of \ - functions" + functions, when using the latter would work" } #[derive(Copy, Clone, Debug)] From aeeb38dab13742935df22408ec805f7196fece01 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Sat, 14 Oct 2017 21:26:39 -0300 Subject: [PATCH 6/8] Change lint name From `suggest_print` to `explicit_write` --- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/suggest_print.rs | 8 ++++---- tests/ui/suggest_print.rs | 2 +- tests/ui/suggest_print.stderr | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2e481151d297..8ea4aa35140b 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -542,7 +542,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { serde_api::SERDE_API_MISUSE, should_assert_eq::SHOULD_ASSERT_EQ, strings::STRING_LIT_AS_BYTES, - suggest_print::SUGGEST_PRINT, + suggest_print::EXPLICIT_WRITE, swap::ALMOST_SWAPPED, swap::MANUAL_SWAP, temporary_assignment::TEMPORARY_ASSIGNMENT, diff --git a/clippy_lints/src/suggest_print.rs b/clippy_lints/src/suggest_print.rs index eb1266af7b75..8349328a18ab 100644 --- a/clippy_lints/src/suggest_print.rs +++ b/clippy_lints/src/suggest_print.rs @@ -16,7 +16,7 @@ use utils::opt_def_id; /// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap(); /// ``` declare_lint! { - pub SUGGEST_PRINT, + pub EXPLICIT_WRITE, Warn, "using `write!()` family of functions instead of `print!()` family of \ functions, when using the latter would work" @@ -27,7 +27,7 @@ pub struct Pass; impl LintPass for Pass { fn get_lints(&self) -> LintArray { - lint_array!(SUGGEST_PRINT) + lint_array!(EXPLICIT_WRITE) } } @@ -74,7 +74,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if let Some(macro_name) = calling_macro { span_lint( cx, - SUGGEST_PRINT, + EXPLICIT_WRITE, expr.span, &format!( "use of `{}!({}(), ...).unwrap()`. Consider using `{}{}!` instead", @@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { } else { span_lint( cx, - SUGGEST_PRINT, + EXPLICIT_WRITE, expr.span, &format!( "use of `{}().write_fmt(...).unwrap()`. Consider using `{}print!` instead", diff --git a/tests/ui/suggest_print.rs b/tests/ui/suggest_print.rs index 0466d6c0b609..71992123ceb6 100644 --- a/tests/ui/suggest_print.rs +++ b/tests/ui/suggest_print.rs @@ -1,4 +1,4 @@ -#![warn(suggest_print)] +#![warn(explicit_write)] fn stdout() -> String { diff --git a/tests/ui/suggest_print.stderr b/tests/ui/suggest_print.stderr index bae9f6f26795..12e656b55408 100644 --- a/tests/ui/suggest_print.stderr +++ b/tests/ui/suggest_print.stderr @@ -4,7 +4,7 @@ error: use of `write!(stdout(), ...).unwrap()`. Consider using `print!` instead 16 | write!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D suggest-print` implied by `-D warnings` + = note: `-D explicit-write` implied by `-D warnings` error: use of `write!(stderr(), ...).unwrap()`. Consider using `eprint!` instead --> $DIR/suggest_print.rs:17:9 From eda013d3afd6311f1fd5bad56155d4ce7b76eb66 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Sat, 14 Oct 2017 21:42:14 -0300 Subject: [PATCH 7/8] Change lint filename suggest_print.rs -> explicit_write.rs --- .../src/{suggest_print.rs => explicit_write.rs} | 0 clippy_lints/src/lib.rs | 6 +++--- tests/ui/{suggest_print.rs => explicit_write.rs} | 0 .../{suggest_print.stderr => explicit_write.stderr} | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) rename clippy_lints/src/{suggest_print.rs => explicit_write.rs} (100%) rename tests/ui/{suggest_print.rs => explicit_write.rs} (100%) rename tests/ui/{suggest_print.stderr => explicit_write.stderr} (86%) diff --git a/clippy_lints/src/suggest_print.rs b/clippy_lints/src/explicit_write.rs similarity index 100% rename from clippy_lints/src/suggest_print.rs rename to clippy_lints/src/explicit_write.rs diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 8ea4aa35140b..a2878b8640c4 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -145,7 +145,7 @@ pub mod serde_api; pub mod shadow; pub mod should_assert_eq; pub mod strings; -pub mod suggest_print; +pub mod explicit_write; pub mod swap; pub mod temporary_assignment; pub mod transmute; @@ -327,7 +327,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { reg.register_late_lint_pass(box unused_io_amount::UnusedIoAmount); reg.register_late_lint_pass(box large_enum_variant::LargeEnumVariant::new(conf.enum_variant_size_threshold)); reg.register_late_lint_pass(box should_assert_eq::ShouldAssertEq); - reg.register_late_lint_pass(box suggest_print::Pass); + reg.register_late_lint_pass(box explicit_write::Pass); reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue); reg.register_early_lint_pass(box literal_digit_grouping::LiteralDigitGrouping); reg.register_late_lint_pass(box use_self::UseSelf); @@ -542,7 +542,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { serde_api::SERDE_API_MISUSE, should_assert_eq::SHOULD_ASSERT_EQ, strings::STRING_LIT_AS_BYTES, - suggest_print::EXPLICIT_WRITE, + explicit_write::EXPLICIT_WRITE, swap::ALMOST_SWAPPED, swap::MANUAL_SWAP, temporary_assignment::TEMPORARY_ASSIGNMENT, diff --git a/tests/ui/suggest_print.rs b/tests/ui/explicit_write.rs similarity index 100% rename from tests/ui/suggest_print.rs rename to tests/ui/explicit_write.rs diff --git a/tests/ui/suggest_print.stderr b/tests/ui/explicit_write.stderr similarity index 86% rename from tests/ui/suggest_print.stderr rename to tests/ui/explicit_write.stderr index 12e656b55408..9a813e897934 100644 --- a/tests/ui/suggest_print.stderr +++ b/tests/ui/explicit_write.stderr @@ -1,5 +1,5 @@ error: use of `write!(stdout(), ...).unwrap()`. Consider using `print!` instead - --> $DIR/suggest_print.rs:16:9 + --> $DIR/explicit_write.rs:16:9 | 16 | write!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,31 +7,31 @@ error: use of `write!(stdout(), ...).unwrap()`. Consider using `print!` instead = note: `-D explicit-write` implied by `-D warnings` error: use of `write!(stderr(), ...).unwrap()`. Consider using `eprint!` instead - --> $DIR/suggest_print.rs:17:9 + --> $DIR/explicit_write.rs:17:9 | 17 | write!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `writeln!(stdout(), ...).unwrap()`. Consider using `println!` instead - --> $DIR/suggest_print.rs:18:9 + --> $DIR/explicit_write.rs:18:9 | 18 | writeln!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `writeln!(stderr(), ...).unwrap()`. Consider using `eprintln!` instead - --> $DIR/suggest_print.rs:19:9 + --> $DIR/explicit_write.rs:19:9 | 19 | writeln!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `stdout().write_fmt(...).unwrap()`. Consider using `print!` instead - --> $DIR/suggest_print.rs:20:9 + --> $DIR/explicit_write.rs:20:9 | 20 | std::io::stdout().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `stderr().write_fmt(...).unwrap()`. Consider using `eprint!` instead - --> $DIR/suggest_print.rs:21:9 + --> $DIR/explicit_write.rs:21:9 | 21 | std::io::stderr().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 2842038627402052494f03ec32fc0f9dd548b05b Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Sat, 14 Oct 2017 21:46:19 -0300 Subject: [PATCH 8/8] Improve lint description --- clippy_lints/src/explicit_write.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 8349328a18ab..9650dd0909ca 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -18,8 +18,8 @@ use utils::opt_def_id; declare_lint! { pub EXPLICIT_WRITE, Warn, - "using `write!()` family of functions instead of `print!()` family of \ - functions, when using the latter would work" + "using the `write!()` family of functions instead of the `print!()` family \ + of functions, when using the latter would work" } #[derive(Copy, Clone, Debug)]