Skip to content

Commit cdaa93d

Browse files
committed
Auto merge of #4544 - JoshMcguigan:issue-4542, r=flip1995
#4542 remove machine applicable suggestion This helps #4542 (but does not completely resolve) by removing the machine applicable suggestion (which was incorrect) for that case. I would have preferred to fix the machine applicable suggestion to handle format strings, but that's a bit beyond my current understanding of the clippy codebase. I'd be happy to give it a try given some guidance. changelog: only produce machine applicable suggestions on `explicit_write` lint
2 parents f08f171 + 24ec994 commit cdaa93d

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)