]> git.lizzy.rs Git - rust.git/commit
Auto merge of #8365 - Alexendoo:explicit-write-suggestion, r=camsteffen
authorbors <bors@rust-lang.org>
Sat, 5 Feb 2022 17:44:37 +0000 (17:44 +0000)
committerbors <bors@rust-lang.org>
Sat, 5 Feb 2022 17:44:37 +0000 (17:44 +0000)
commit68b44986de6a8c9e844afa55693a24f0d4a0978e
treefa2e21087e2a10dfada3a1879a5132ed789cf5be
parent29cc0d8e595f93cd0bd8341dd034c847f3a7746f
parent144b4a59c7a3d18a0dd2c4316061672d00516ea3
Auto merge of #8365 - Alexendoo:explicit-write-suggestion, r=camsteffen

Add `explicit_write` suggestions for `write!`s with format args

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

Fixes #4542

```rust
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 ðŸ˜›) for the `FormatArgsExpn` change

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

```rust
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!()`