rust/tests/ui/single_char_pattern.rs

70 lines
1.7 KiB
Rust
Raw Normal View History

#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)]
2023-11-28 15:31:24 -06:00
#![warn(clippy::single_char_pattern)]
2017-10-09 23:00:47 -05:00
use std::collections::HashSet;
fn main() {
let x = "foo";
x.split("x");
x.split("xx");
x.split('x');
let y = "x";
x.split(y);
x.split("ß");
x.split("");
x.split("💣");
// Can't use this lint for unicode code points which don't fit in a char
x.split("❤️");
x.split_inclusive("x");
2017-10-09 23:00:47 -05:00
x.contains("x");
x.starts_with("x");
x.ends_with("x");
x.find("x");
x.rfind("x");
x.rsplit("x");
x.split_terminator("x");
x.rsplit_terminator("x");
2021-05-30 08:35:06 -05:00
x.splitn(2, "x");
x.rsplitn(2, "x");
x.split_once("x");
x.rsplit_once("x");
2017-10-09 23:00:47 -05:00
x.matches("x");
x.rmatches("x");
x.match_indices("x");
x.rmatch_indices("x");
x.trim_start_matches("x");
x.trim_end_matches("x");
x.replace("x", "y");
x.replacen("x", "y", 3);
// Make sure we escape characters correctly.
x.split("\n");
x.split("'");
x.split("\'");
2023-12-27 15:15:17 -06:00
// Issue #11973: Don't escape `"` in `'"'`
x.split("\"");
2017-10-09 23:00:47 -05:00
let h = HashSet::<String>::new();
h.contains("X"); // should not warn
x.replace(';', ",").split(","); // issue #2978
x.starts_with("\x03"); // issue #2996
// Issue #3204
const S: &str = "#";
x.find(S);
// Raw string
x.split(r"a");
x.split(r#"a"#);
2019-08-08 22:45:49 -05:00
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"\");
// should not warn, the char versions are actually slower in some cases
x.strip_prefix("x");
x.strip_suffix("x");
2017-10-09 23:00:47 -05:00
}