Skip to content

Commit 17dcd0d

Browse files
committed
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 `'"'` ```
2 parents bc962c2 + e5c9fb6 commit 17dcd0d

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

clippy_lints/src/methods/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub(super) fn get_hint_if_single_char_arg(
7474
match ch {
7575
"'" => "\\'",
7676
r"\" => "\\\\",
77+
"\\\"" => "\"", // no need to escape `"` in `'"'`
7778
_ => ch,
7879
}
7980
);

tests/ui/single_char_pattern.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fn main() {
4242
x.split('\n');
4343
x.split('\'');
4444
x.split('\'');
45+
// Issue #11973: Don't escape `"` in `'"'`
46+
x.split('"');
4547

4648
let h = HashSet::<String>::new();
4749
h.contains("X"); // should not warn

tests/ui/single_char_pattern.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fn main() {
4242
x.split("\n");
4343
x.split("'");
4444
x.split("\'");
45+
// Issue #11973: Don't escape `"` in `'"'`
46+
x.split("\"");
4547

4648
let h = HashSet::<String>::new();
4749
h.contains("X"); // should not warn

tests/ui/single_char_pattern.stderr

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,58 +182,64 @@ LL | x.split("\'");
182182
| ^^^^ help: try using a `char` instead: `'\''`
183183

184184
error: single-character string constant used as pattern
185-
--> $DIR/single_char_pattern.rs:49:31
185+
--> $DIR/single_char_pattern.rs:46:13
186+
|
187+
LL | x.split("\"");
188+
| ^^^^ help: try using a `char` instead: `'"'`
189+
190+
error: single-character string constant used as pattern
191+
--> $DIR/single_char_pattern.rs:51:31
186192
|
187193
LL | x.replace(';', ",").split(","); // issue #2978
188194
| ^^^ help: try using a `char` instead: `','`
189195

190196
error: single-character string constant used as pattern
191-
--> $DIR/single_char_pattern.rs:50:19
197+
--> $DIR/single_char_pattern.rs:52:19
192198
|
193199
LL | x.starts_with("\x03"); // issue #2996
194200
| ^^^^^^ help: try using a `char` instead: `'\x03'`
195201

196202
error: single-character string constant used as pattern
197-
--> $DIR/single_char_pattern.rs:57:13
203+
--> $DIR/single_char_pattern.rs:59:13
198204
|
199205
LL | x.split(r"a");
200206
| ^^^^ help: try using a `char` instead: `'a'`
201207

202208
error: single-character string constant used as pattern
203-
--> $DIR/single_char_pattern.rs:58:13
209+
--> $DIR/single_char_pattern.rs:60:13
204210
|
205211
LL | x.split(r#"a"#);
206212
| ^^^^^^ help: try using a `char` instead: `'a'`
207213

208214
error: single-character string constant used as pattern
209-
--> $DIR/single_char_pattern.rs:59:13
215+
--> $DIR/single_char_pattern.rs:61:13
210216
|
211217
LL | x.split(r###"a"###);
212218
| ^^^^^^^^^^ help: try using a `char` instead: `'a'`
213219

214220
error: single-character string constant used as pattern
215-
--> $DIR/single_char_pattern.rs:60:13
221+
--> $DIR/single_char_pattern.rs:62:13
216222
|
217223
LL | x.split(r###"'"###);
218224
| ^^^^^^^^^^ help: try using a `char` instead: `'\''`
219225

220226
error: single-character string constant used as pattern
221-
--> $DIR/single_char_pattern.rs:61:13
227+
--> $DIR/single_char_pattern.rs:63:13
222228
|
223229
LL | x.split(r###"#"###);
224230
| ^^^^^^^^^^ help: try using a `char` instead: `'#'`
225231

226232
error: single-character string constant used as pattern
227-
--> $DIR/single_char_pattern.rs:63:13
233+
--> $DIR/single_char_pattern.rs:65:13
228234
|
229235
LL | x.split(r#"\"#);
230236
| ^^^^^^ help: try using a `char` instead: `'\\'`
231237

232238
error: single-character string constant used as pattern
233-
--> $DIR/single_char_pattern.rs:64:13
239+
--> $DIR/single_char_pattern.rs:66:13
234240
|
235241
LL | x.split(r"\");
236242
| ^^^^ help: try using a `char` instead: `'\\'`
237243

238-
error: aborting due to 39 previous errors
244+
error: aborting due to 40 previous errors
239245

0 commit comments

Comments
 (0)