mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Escape backslash for singe_char_pattern.rs
This commit is contained in:
parent
d5d830a50f
commit
5cc451bc6c
4 changed files with 26 additions and 2 deletions
|
@ -66,7 +66,13 @@ pub(super) fn get_hint_if_single_char_arg(
|
|||
// for regular string: "a"
|
||||
&snip[1..(snip.len() - 1)]
|
||||
};
|
||||
let hint = format!("'{}'", if ch == "'" { "\\'" } else { ch });
|
||||
|
||||
let hint = format!("'{}'", match ch {
|
||||
"'" => "\\'" ,
|
||||
r"\" => "\\\\",
|
||||
_ => ch,
|
||||
});
|
||||
|
||||
Some(hint)
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -56,4 +56,7 @@ fn main() {
|
|||
x.split('a');
|
||||
x.split('\'');
|
||||
x.split('#');
|
||||
// Must escape backslash in raw strings when converting to char #8060
|
||||
x.split('\\');
|
||||
x.split('\\');
|
||||
}
|
||||
|
|
|
@ -56,4 +56,7 @@ fn main() {
|
|||
x.split(r###"a"###);
|
||||
x.split(r###"'"###);
|
||||
x.split(r###"#"###);
|
||||
// Must escape backslash in raw strings when converting to char #8060
|
||||
x.split(r#"\"#);
|
||||
x.split(r"\");
|
||||
}
|
||||
|
|
|
@ -192,5 +192,17 @@ error: single-character string constant used as pattern
|
|||
LL | x.split(r###"#"###);
|
||||
| ^^^^^^^^^^ help: try using a `char` instead: `'#'`
|
||||
|
||||
error: aborting due to 32 previous errors
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:60: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
|
||||
|
|
||||
LL | x.split(r"/");
|
||||
| ^^^^ help: try using a `char` instead: `'/'`
|
||||
|
||||
error: aborting due to 34 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue