Skip to content

Commit 1bf5a76

Browse files
committed
resolve #4542 by removing machine applicable suggestion
1 parent 535bc1d commit 1bf5a76

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

clippy_lints/src/explicit_write.rs

Lines changed: 2 additions & 1 deletion
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 {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![allow(unused_imports, clippy::blacklisted_name)]
2+
#![warn(clippy::explicit_write)]
3+
4+
fn main() {
5+
let bar = "bar";
6+
writeln!(std::io::stderr(), "foo {}", bar).unwrap();
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0599]: no method named `write_fmt` found for type `std::io::Stderr` in the current scope
2+
--> $DIR/explicit_write_non_rustfix.rs:6:5
3+
|
4+
LL | writeln!(std::io::stderr(), "foo {}", bar).unwrap();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `std::io::Stderr`
6+
|
7+
= help: items from traits can only be used if the trait is in scope
8+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
9+
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
10+
|
11+
LL | use std::io::Write;
12+
|
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)