diff options
| author | bors <bors@rust-lang.org> | 2019-04-12 17:03:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-12 17:03:01 +0000 |
| commit | d516925ec8ff4d39e32830442959fad16407e87e (patch) | |
| tree | e0a4543b1410d9ed3e629135453e309814936922 | |
| parent | abf7f911d88e9209b54cfba2776d7dbca5a440ce (diff) | |
| parent | db6ca9b8d364e4afca8101e483a36ceb78546711 (diff) | |
| download | rust-d516925ec8ff4d39e32830442959fad16407e87e.tar.gz rust-d516925ec8ff4d39e32830442959fad16407e87e.zip | |
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
fix format does not parse escaped braces error related: https://github.com/rust-lang/rust-clippy/issues/3920
| -rw-r--r-- | clippy_lints/src/format.rs | 4 | ||||
| -rw-r--r-- | tests/ui/format.fixed | 2 | ||||
| -rw-r--r-- | tests/ui/format.rs | 2 | ||||
| -rw-r--r-- | tests/ui/format.stderr | 28 |
4 files changed, 27 insertions, 9 deletions
diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 02a47d65421..542823c2b8e 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -91,7 +91,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { ExprKind::Match(ref matchee, _, _) => { if let ExprKind::Tup(ref tup) = matchee.node { if tup.is_empty() { - let sugg = format!("{}.to_string()", snippet(cx, expr.span, "<expr>").into_owned()); + let actual_snippet = snippet(cx, expr.span, "<expr>").to_string(); + let actual_snippet = actual_snippet.replace("{{}}", "{}"); + let sugg = format!("{}.to_string()", actual_snippet); span_useless_format(cx, span, "consider using .to_string()", sugg); } } diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed index ab973e07511..e4217411f05 100644 --- a/tests/ui/format.fixed +++ b/tests/ui/format.fixed @@ -11,6 +11,8 @@ macro_rules! foo { fn main() { "foo".to_string(); + "{}".to_string(); + "{} abc {}".to_string(); "foo".to_string(); format!("{:?}", "foo"); // Don't warn about `Debug`. diff --git a/tests/ui/format.rs b/tests/ui/format.rs index 2ef31f0b948..61ef3e7243d 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -11,6 +11,8 @@ macro_rules! foo { fn main() { format!("foo"); + format!("{{}}"); + format!("{{}} abc {{}}"); format!("{}", "foo"); format!("{:?}", "foo"); // Don't warn about `Debug`. diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 7ca63e2fea5..ec1253589f6 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -7,52 +7,64 @@ LL | format!("foo"); = note: `-D clippy::useless-format` implied by `-D warnings` error: useless use of `format!` + --> $DIR/format.rs:14:5 + | +LL | format!("{{}}"); + | ^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"{}".to_string();` + +error: useless use of `format!` --> $DIR/format.rs:15:5 | +LL | format!("{{}} abc {{}}"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"{} abc {}".to_string();` + +error: useless use of `format!` + --> $DIR/format.rs:17:5 + | LL | format!("{}", "foo"); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"foo".to_string();` error: useless use of `format!` - --> $DIR/format.rs:19:5 + --> $DIR/format.rs:21:5 | LL | format!("{:+}", "foo"); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"foo".to_string();` error: useless use of `format!` - --> $DIR/format.rs:20:5 + --> $DIR/format.rs:22:5 | LL | format!("{:<}", "foo"); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `"foo".to_string();` error: useless use of `format!` - --> $DIR/format.rs:25:5 + --> $DIR/format.rs:27:5 | LL | format!("{}", arg); | ^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `arg.to_string();` error: useless use of `format!` - --> $DIR/format.rs:29:5 + --> $DIR/format.rs:31:5 | LL | format!("{:+}", arg); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `arg.to_string();` error: useless use of `format!` - --> $DIR/format.rs:30:5 + --> $DIR/format.rs:32:5 | LL | format!("{:<}", arg); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^^ help: consider using .to_string(): `arg.to_string();` error: useless use of `format!` - --> $DIR/format.rs:57:5 + --> $DIR/format.rs:59:5 | LL | format!("{}", 42.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `to_string()` is enough: `42.to_string();` error: useless use of `format!` - --> $DIR/format.rs:59:5 + --> $DIR/format.rs:61:5 | LL | format!("{}", x.display().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `to_string()` is enough: `x.display().to_string();` -error: aborting due to 9 previous errors +error: aborting due to 11 previous errors |
