Skip to content

Commit 24ec994

Browse files
committed
remove machine applicable suggestion explicit_write format #4542
1 parent 535bc1d commit 24ec994

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clippy_lints/src/explicit_write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ fn write_output_string(write_args: &HirVec<Expr>) -> Option<String> {
140140
if output_args.len() > 0;
141141
if let ExprKind::AddrOf(_, ref output_string_expr) = output_args[0].node;
142142
if let ExprKind::Array(ref string_exprs) = output_string_expr.node;
143-
if string_exprs.len() > 0;
143+
// we only want to provide an automatic suggestion for simple (non-format) strings
144+
if string_exprs.len() == 1;
144145
if let ExprKind::Lit(ref lit) = string_exprs[0].node;
145146
if let LitKind::Str(ref write_output, _) = lit.node;
146147
then {
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![allow(unused_imports, clippy::blacklisted_name)]
2+
#![warn(clippy::explicit_write)]
3+
4+
fn main() {
5+
use std::io::Write;
6+
let bar = "bar";
7+
writeln!(std::io::stderr(), "foo {}", bar).unwrap();
8+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: use of `writeln!(stderr(), ...).unwrap()`. Consider using `eprintln!` instead
2+
--> $DIR/explicit_write_non_rustfix.rs:7:5
3+
|
4+
LL | writeln!(std::io::stderr(), "foo {}", bar).unwrap();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::explicit-write` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)