add strip_{prefix,suffix} to PATTERN_METHODS
this will warn, if a single_char_pattern is used in one of the above methods
This commit is contained in:
parent
019dfb9502
commit
c080899848
@ -2190,7 +2190,7 @@ const TRAIT_METHODS: [ShouldImplTraitCase; 30] = [
|
||||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
const PATTERN_METHODS: [(&str, usize); 17] = [
|
||||
const PATTERN_METHODS: [(&str, usize); 19] = [
|
||||
("contains", 1),
|
||||
("starts_with", 1),
|
||||
("ends_with", 1),
|
||||
@ -2206,6 +2206,8 @@ const PATTERN_METHODS: [(&str, usize); 17] = [
|
||||
("rmatches", 1),
|
||||
("match_indices", 1),
|
||||
("rmatch_indices", 1),
|
||||
("strip_prefix", 1),
|
||||
("strip_suffix", 1),
|
||||
("trim_start_matches", 1),
|
||||
("trim_end_matches", 1),
|
||||
];
|
||||
|
@ -33,6 +33,8 @@ fn main() {
|
||||
x.rmatch_indices('x');
|
||||
x.trim_start_matches('x');
|
||||
x.trim_end_matches('x');
|
||||
x.strip_prefix('x');
|
||||
x.strip_suffix('x');
|
||||
// Make sure we escape characters correctly.
|
||||
x.split('\n');
|
||||
x.split('\'');
|
||||
|
@ -33,6 +33,8 @@ fn main() {
|
||||
x.rmatch_indices("x");
|
||||
x.trim_start_matches("x");
|
||||
x.trim_end_matches("x");
|
||||
x.strip_prefix("x");
|
||||
x.strip_suffix("x");
|
||||
// Make sure we escape characters correctly.
|
||||
x.split("\n");
|
||||
x.split("'");
|
||||
|
@ -121,64 +121,76 @@ LL | x.trim_end_matches("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:37:13
|
||||
--> $DIR/single_char_pattern.rs:36:20
|
||||
|
|
||||
LL | x.strip_prefix("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:37:20
|
||||
|
|
||||
LL | x.strip_suffix("x");
|
||||
| ^^^ help: try using a `char` instead: `'x'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:39:13
|
||||
|
|
||||
LL | x.split("/n");
|
||||
| ^^^^ help: try using a `char` instead: `'/n'`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:38:13
|
||||
--> $DIR/single_char_pattern.rs:40:13
|
||||
|
|
||||
LL | x.split("'");
|
||||
| ^^^ help: try using a `char` instead: `'/''`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:39:13
|
||||
--> $DIR/single_char_pattern.rs:41:13
|
||||
|
|
||||
LL | x.split("/'");
|
||||
| ^^^^ help: try using a `char` instead: `'/''`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:44:31
|
||||
--> $DIR/single_char_pattern.rs:46: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:45:19
|
||||
--> $DIR/single_char_pattern.rs:47: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:52:13
|
||||
--> $DIR/single_char_pattern.rs:54: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:53:13
|
||||
--> $DIR/single_char_pattern.rs:55: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:54:13
|
||||
--> $DIR/single_char_pattern.rs:56: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:55:13
|
||||
--> $DIR/single_char_pattern.rs:57:13
|
||||
|
|
||||
LL | x.split(r###"'"###);
|
||||
| ^^^^^^^^^^ help: try using a `char` instead: `'/''`
|
||||
|
||||
error: single-character string constant used as pattern
|
||||
--> $DIR/single_char_pattern.rs:56:13
|
||||
--> $DIR/single_char_pattern.rs:58:13
|
||||
|
|
||||
LL | x.split(r###"#"###);
|
||||
| ^^^^^^^^^^ help: try using a `char` instead: `'#'`
|
||||
|
||||
error: aborting due to 30 previous errors
|
||||
error: aborting due to 32 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user