Skip to content

Commit

Permalink
resolve #4542 by removing machine applicable suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMcguigan committed Sep 17, 2019
1 parent 535bc1d commit 1bf5a76
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/explicit_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ fn write_output_string(write_args: &HirVec<Expr>) -> Option<String> {
if output_args.len() > 0;
if let ExprKind::AddrOf(_, ref output_string_expr) = output_args[0].node;
if let ExprKind::Array(ref string_exprs) = output_string_expr.node;
if string_exprs.len() > 0;
// we only want to provide an automatic suggestion for simple (non-format) strings
if string_exprs.len() == 1;
if let ExprKind::Lit(ref lit) = string_exprs[0].node;
if let LitKind::Str(ref write_output, _) = lit.node;
then {
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/explicit_write_non_rustfix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![allow(unused_imports, clippy::blacklisted_name)]
#![warn(clippy::explicit_write)]

fn main() {
let bar = "bar";
writeln!(std::io::stderr(), "foo {}", bar).unwrap();
}
16 changes: 16 additions & 0 deletions tests/ui/explicit_write_non_rustfix.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0599]: no method named `write_fmt` found for type `std::io::Stderr` in the current scope
--> $DIR/explicit_write_non_rustfix.rs:6:5
|
LL | writeln!(std::io::stderr(), "foo {}", bar).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `std::io::Stderr`
|
= help: items from traits can only be used if the trait is in scope
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
|
LL | use std::io::Write;
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

0 comments on commit 1bf5a76

Please sign in to comment.