6

Add `explicit_write` suggestions for `write!`s with format args by Alexendoo · P...

 2 years ago
source link: https://github.com/rust-lang/rust-clippy/pull/8365
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Member

Alexendoo commented 20 days ago

changelog: Add [explicit_write] suggestions for write!s with format args

Fixes #4542

writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();

Now suggests:

error: use of `writeln!(stderr(), ...).unwrap()`
  --> $DIR/explicit_write.rs:36:9
   |
LL |         writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("macro arg {}", one!())`

r? @camsteffen (again, sorry stuck_out_tongue) for the FormatArgsExpn change

Before this change inputs_span returned a span pointing to just 1 in

macro_rules! one {
    () => { 1 };
}

`writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();`

And the source_callsite of that span didn't include the format string, it was just one!()


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK