about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-01-03 21:30:01 +0000
committerbors <bors@rust-lang.org>2024-01-03 21:30:01 +0000
commit17dcd0d2e4953fb00277c45c9b193a36394b1bea (patch)
tree79cae704f57681aae3b49428ee9d7536f3b455aa
parentbc962c246a8f3efe4a1217b36c64a03652493327 (diff)
parente5c9fb68279322000536166a4a82a754904e52f7 (diff)
downloadrust-17dcd0d2e4953fb00277c45c9b193a36394b1bea.tar.gz
rust-17dcd0d2e4953fb00277c45c9b193a36394b1bea.zip
Auto merge of #12030 - torfsen:11973-fix-quoting-of-double-quote-in-char-literal, r=llogiq
11973: Don't escape `"` in `'"'`

Fixes #11973.

```
changelog: [`single_char_pattern`]: don't escape `"` in `'"'`
```
-rw-r--r--clippy_lints/src/methods/utils.rs1
-rw-r--r--tests/ui/single_char_pattern.fixed2
-rw-r--r--tests/ui/single_char_pattern.rs2
-rw-r--r--tests/ui/single_char_pattern.stderr26
4 files changed, 21 insertions, 10 deletions
diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs
index 9ad4250a141..3a0305b4d55 100644
--- a/clippy_lints/src/methods/utils.rs
+++ b/clippy_lints/src/methods/utils.rs
@@ -74,6 +74,7 @@ pub(super) fn get_hint_if_single_char_arg(
             match ch {
                 "'" => "\\'",
                 r"\" => "\\\\",
+                "\\\"" => "\"", // no need to escape `"` in `'"'`
                 _ => ch,
             }
         );
diff --git a/tests/ui/single_char_pattern.fixed b/tests/ui/single_char_pattern.fixed
index 79e7eda4070..9573fdbcfde 100644
--- a/tests/ui/single_char_pattern.fixed
+++ b/tests/ui/single_char_pattern.fixed
@@ -42,6 +42,8 @@ fn main() {
     x.split('\n');
     x.split('\'');
     x.split('\'');
+    // Issue #11973: Don't escape `"` in `'"'`
+    x.split('"');
 
     let h = HashSet::<String>::new();
     h.contains("X"); // should not warn
diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs
index 81962c0a6e9..8a04480dbc6 100644
--- a/tests/ui/single_char_pattern.rs
+++ b/tests/ui/single_char_pattern.rs
@@ -42,6 +42,8 @@ fn main() {
     x.split("\n");
     x.split("'");
     x.split("\'");
+    // Issue #11973: Don't escape `"` in `'"'`
+    x.split("\"");
 
     let h = HashSet::<String>::new();
     h.contains("X"); // should not warn
diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr
index 6e57ab3489f..781ab316d9d 100644
--- a/tests/ui/single_char_pattern.stderr
+++ b/tests/ui/single_char_pattern.stderr
@@ -182,58 +182,64 @@ LL |     x.split("\'");
    |             ^^^^ help: try using a `char` instead: `'\''`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:49:31
+  --> $DIR/single_char_pattern.rs:46:13
+   |
+LL |     x.split("\"");
+   |             ^^^^ help: try using a `char` instead: `'"'`
+
+error: single-character string constant used as pattern
+  --> $DIR/single_char_pattern.rs:51:31
    |
 LL |     x.replace(';', ",").split(","); // issue #2978
    |                               ^^^ help: try using a `char` instead: `','`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:50:19
+  --> $DIR/single_char_pattern.rs:52:19
    |
 LL |     x.starts_with("\x03"); // issue #2996
    |                   ^^^^^^ help: try using a `char` instead: `'\x03'`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:57:13
+  --> $DIR/single_char_pattern.rs:59:13
    |
 LL |     x.split(r"a");
    |             ^^^^ help: try using a `char` instead: `'a'`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:58:13
+  --> $DIR/single_char_pattern.rs:60:13
    |
 LL |     x.split(r#"a"#);
    |             ^^^^^^ help: try using a `char` instead: `'a'`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:59:13
+  --> $DIR/single_char_pattern.rs:61:13
    |
 LL |     x.split(r###"a"###);
    |             ^^^^^^^^^^ help: try using a `char` instead: `'a'`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:60:13
+  --> $DIR/single_char_pattern.rs:62:13
    |
 LL |     x.split(r###"'"###);
    |             ^^^^^^^^^^ help: try using a `char` instead: `'\''`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:61:13
+  --> $DIR/single_char_pattern.rs:63:13
    |
 LL |     x.split(r###"#"###);
    |             ^^^^^^^^^^ help: try using a `char` instead: `'#'`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:63:13
+  --> $DIR/single_char_pattern.rs:65:13
    |
 LL |     x.split(r#"\"#);
    |             ^^^^^^ help: try using a `char` instead: `'\\'`
 
 error: single-character string constant used as pattern
-  --> $DIR/single_char_pattern.rs:64:13
+  --> $DIR/single_char_pattern.rs:66:13
    |
 LL |     x.split(r"\");
    |             ^^^^ help: try using a `char` instead: `'\\'`
 
-error: aborting due to 39 previous errors
+error: aborting due to 40 previous errors