forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#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 rust-lang#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!()`
- Loading branch information
Showing
15 changed files
with
173 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,82 @@ | ||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:29:26 | ||
--> $DIR/expect_fun_call.rs:35:26 | ||
| | ||
LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` | ||
| | ||
= note: `-D clippy::expect-fun-call` implied by `-D warnings` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:32:26 | ||
--> $DIR/expect_fun_call.rs:38:26 | ||
| | ||
LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:42:25 | ||
--> $DIR/expect_fun_call.rs:41:37 | ||
| | ||
LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:51:25 | ||
| | ||
LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:45:25 | ||
--> $DIR/expect_fun_call.rs:54:25 | ||
| | ||
LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:57:17 | ||
--> $DIR/expect_fun_call.rs:66:17 | ||
| | ||
LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:78:21 | ||
--> $DIR/expect_fun_call.rs:87:21 | ||
| | ||
LL | Some("foo").expect(&get_string()); | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:79:21 | ||
--> $DIR/expect_fun_call.rs:88:21 | ||
| | ||
LL | Some("foo").expect(get_string().as_ref()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:80:21 | ||
--> $DIR/expect_fun_call.rs:89:21 | ||
| | ||
LL | Some("foo").expect(get_string().as_str()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:82:21 | ||
--> $DIR/expect_fun_call.rs:91:21 | ||
| | ||
LL | Some("foo").expect(get_static_str()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:83:21 | ||
--> $DIR/expect_fun_call.rs:92:21 | ||
| | ||
LL | Some("foo").expect(get_non_static_str(&0)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:87:16 | ||
--> $DIR/expect_fun_call.rs:96:16 | ||
| | ||
LL | Some(true).expect(&format!("key {}, {}", 1, 2)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))` | ||
|
||
error: use of `expect` followed by a function call | ||
--> $DIR/expect_fun_call.rs:93:17 | ||
--> $DIR/expect_fun_call.rs:102:17 | ||
| | ||
LL | opt_ref.expect(&format!("{:?}", opt_ref)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{:?}", opt_ref))` | ||
|
||
error: aborting due to 12 previous errors | ||
error: aborting due to 13 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,76 @@ | ||
error: use of `write!(stdout(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:17:9 | ||
--> $DIR/explicit_write.rs:23:9 | ||
| | ||
LL | write!(std::io::stdout(), "test").unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")` | ||
| | ||
= note: `-D clippy::explicit-write` implied by `-D warnings` | ||
|
||
error: use of `write!(stderr(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:18:9 | ||
--> $DIR/explicit_write.rs:24:9 | ||
| | ||
LL | write!(std::io::stderr(), "test").unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")` | ||
|
||
error: use of `writeln!(stdout(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:19:9 | ||
--> $DIR/explicit_write.rs:25:9 | ||
| | ||
LL | writeln!(std::io::stdout(), "test").unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test")` | ||
|
||
error: use of `writeln!(stderr(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:20:9 | ||
--> $DIR/explicit_write.rs:26:9 | ||
| | ||
LL | writeln!(std::io::stderr(), "test").unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test")` | ||
|
||
error: use of `stdout().write_fmt(...).unwrap()` | ||
--> $DIR/explicit_write.rs:21:9 | ||
--> $DIR/explicit_write.rs:27:9 | ||
| | ||
LL | std::io::stdout().write_fmt(format_args!("test")).unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")` | ||
|
||
error: use of `stderr().write_fmt(...).unwrap()` | ||
--> $DIR/explicit_write.rs:22:9 | ||
--> $DIR/explicit_write.rs:28:9 | ||
| | ||
LL | std::io::stderr().write_fmt(format_args!("test")).unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")` | ||
|
||
error: use of `writeln!(stdout(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:25:9 | ||
--> $DIR/explicit_write.rs:31:9 | ||
| | ||
LL | writeln!(std::io::stdout(), "test/ntest").unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test/ntest")` | ||
|
||
error: use of `writeln!(stderr(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:26:9 | ||
--> $DIR/explicit_write.rs:32:9 | ||
| | ||
LL | writeln!(std::io::stderr(), "test/ntest").unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test/ntest")` | ||
|
||
error: aborting due to 8 previous errors | ||
error: use of `writeln!(stderr(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:35:9 | ||
| | ||
LL | writeln!(std::io::stderr(), "with {}", value).unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {}", value)` | ||
|
||
error: use of `writeln!(stderr(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:36:9 | ||
| | ||
LL | writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {} {}", 2, value)` | ||
|
||
error: use of `writeln!(stderr(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:37:9 | ||
| | ||
LL | writeln!(std::io::stderr(), "with {value}").unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {value}")` | ||
|
||
error: use of `writeln!(stderr(), ...).unwrap()` | ||
--> $DIR/explicit_write.rs:38:9 | ||
| | ||
LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("macro arg {}", one!())` | ||
|
||
error: aborting due to 12 previous errors | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.