Skip to content

Commit

Permalink
11973: Don't escape " in '"'
Browse files Browse the repository at this point in the history
  • Loading branch information
torfsen committed Dec 27, 2023
1 parent 7343db9 commit e5c9fb6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/methods/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub(super) fn get_hint_if_single_char_arg(
match ch {
"'" => "\\'",
r"\" => "\\\\",
"\\\"" => "\"", // no need to escape `"` in `'"'`
_ => ch,
}
);
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/single_char_pattern.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/single_char_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions tests/ui/single_char_pattern.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e5c9fb6

Please sign in to comment.