-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #7903 #7906
Merged
Merged
Fix #7903 #7906
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#![allow(unused_variables)] | ||
#![allow(clippy::assertions_on_constants)] | ||
#![allow(clippy::eq_op)] | ||
#![allow(clippy::print_literal)] | ||
#![warn(clippy::to_string_in_format_args)] | ||
|
||
use std::io::{stdout, Write}; | ||
|
@@ -97,9 +98,20 @@ fn main() { | |
println!("{}", Z(1).to_string()); | ||
println!("{}", x.to_string()); | ||
println!("{}", x_ref.to_string()); | ||
// https://github.com/rust-lang/rust-clippy/issues/7903 | ||
println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar"); | ||
println!("{foo}{bar}", foo = "foo", bar = "bar".to_string()); | ||
println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo"); | ||
println!("{foo}{bar}", bar = "bar", foo = "foo".to_string()); | ||
|
||
// negative tests | ||
println!("error: something failed at {}", Somewhere.to_string()); | ||
// The next two tests are negative because caching the string might be faster than calling `<X as | ||
// Display>::fmt` twice. | ||
println!("{} and again {0}", x.to_string()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment on this. Comments would be helpful here. One to separate |
||
println!("{foo}{foo}", foo = "foo".to_string()); | ||
my_macro!(); | ||
println!("error: something failed at {}", my_other_macro!()); | ||
// https://github.com/rust-lang/rust-clippy/issues/7903 | ||
println!("{foo}{foo:?}", foo = "foo".to_string()); | ||
} |
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,106 +1,130 @@ | ||
error: `to_string` applied to a type that implements `Display` in `format!` args | ||
--> $DIR/format_args.rs:75:72 | ||
--> $DIR/format_args.rs:76:72 | ||
| | ||
LL | let _ = format!("error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
| | ||
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings` | ||
|
||
error: `to_string` applied to a type that implements `Display` in `write!` args | ||
--> $DIR/format_args.rs:79:27 | ||
--> $DIR/format_args.rs:80:27 | ||
| | ||
LL | Location::caller().to_string() | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `writeln!` args | ||
--> $DIR/format_args.rs:84:27 | ||
--> $DIR/format_args.rs:85:27 | ||
| | ||
LL | Location::caller().to_string() | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `print!` args | ||
--> $DIR/format_args.rs:86:63 | ||
--> $DIR/format_args.rs:87:63 | ||
| | ||
LL | print!("error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:87:65 | ||
--> $DIR/format_args.rs:88:65 | ||
| | ||
LL | println!("error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `eprint!` args | ||
--> $DIR/format_args.rs:88:64 | ||
--> $DIR/format_args.rs:89:64 | ||
| | ||
LL | eprint!("error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `eprintln!` args | ||
--> $DIR/format_args.rs:89:66 | ||
--> $DIR/format_args.rs:90:66 | ||
| | ||
LL | eprintln!("error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `format_args!` args | ||
--> $DIR/format_args.rs:90:77 | ||
--> $DIR/format_args.rs:91:77 | ||
| | ||
LL | let _ = format_args!("error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `assert!` args | ||
--> $DIR/format_args.rs:91:70 | ||
--> $DIR/format_args.rs:92:70 | ||
| | ||
LL | assert!(true, "error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `assert_eq!` args | ||
--> $DIR/format_args.rs:92:73 | ||
--> $DIR/format_args.rs:93:73 | ||
| | ||
LL | assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `assert_ne!` args | ||
--> $DIR/format_args.rs:93:73 | ||
--> $DIR/format_args.rs:94:73 | ||
| | ||
LL | assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `panic!` args | ||
--> $DIR/format_args.rs:94:63 | ||
--> $DIR/format_args.rs:95:63 | ||
| | ||
LL | panic!("error: something failed at {}", Location::caller().to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:95:20 | ||
--> $DIR/format_args.rs:96:20 | ||
| | ||
LL | println!("{}", X(1).to_string()); | ||
| ^^^^^^^^^^^^^^^^ help: use this: `*X(1)` | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:96:20 | ||
--> $DIR/format_args.rs:97:20 | ||
| | ||
LL | println!("{}", Y(&X(1)).to_string()); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: use this: `***Y(&X(1))` | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:97:24 | ||
--> $DIR/format_args.rs:98:24 | ||
| | ||
LL | println!("{}", Z(1).to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:98:20 | ||
--> $DIR/format_args.rs:99:20 | ||
| | ||
LL | println!("{}", x.to_string()); | ||
| ^^^^^^^^^^^^^ help: use this: `**x` | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:99:20 | ||
--> $DIR/format_args.rs:100:20 | ||
| | ||
LL | println!("{}", x_ref.to_string()); | ||
| ^^^^^^^^^^^^^^^^^ help: use this: `***x_ref` | ||
|
||
error: aborting due to 17 previous errors | ||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:102:39 | ||
| | ||
LL | println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar"); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:103:52 | ||
| | ||
LL | println!("{foo}{bar}", foo = "foo", bar = "bar".to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:104:39 | ||
| | ||
LL | println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo"); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: `to_string` applied to a type that implements `Display` in `println!` args | ||
--> $DIR/format_args.rs:105:52 | ||
| | ||
LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string()); | ||
| ^^^^^^^^^^^^ help: remove this | ||
|
||
error: aborting due to 21 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay for now since it fixes an ICE, but note that we want to move away from depending on the exact HIR per #7843.