2021-07-17 12:52:03 -05:00
|
|
|
// run-rustfix
|
|
|
|
|
|
|
|
#![feature(custom_inner_attributes)]
|
|
|
|
#![warn(clippy::manual_split_once)]
|
2022-04-04 10:30:38 -05:00
|
|
|
#![allow(clippy::iter_skip_next, clippy::iter_nth_zero)]
|
2021-07-17 12:52:03 -05:00
|
|
|
|
|
|
|
extern crate itertools;
|
|
|
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use itertools::Itertools;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _ = "key=value".splitn(2, '=').nth(2);
|
|
|
|
let _ = "key=value".split_once('=').unwrap().1;
|
|
|
|
let _ = "key=value".split_once('=').unwrap().1;
|
|
|
|
let (_, _) = "key=value".split_once('=').unwrap();
|
|
|
|
|
|
|
|
let s = String::from("key=value");
|
2022-04-04 10:30:38 -05:00
|
|
|
let _ = s.split_once('=').unwrap().1;
|
2021-07-17 12:52:03 -05:00
|
|
|
|
|
|
|
let s = Box::<str>::from("key=value");
|
2022-04-04 10:30:38 -05:00
|
|
|
let _ = s.split_once('=').unwrap().1;
|
2021-07-17 12:52:03 -05:00
|
|
|
|
|
|
|
let s = &"key=value";
|
2022-04-04 10:30:38 -05:00
|
|
|
let _ = s.split_once('=').unwrap().1;
|
2021-07-17 12:52:03 -05:00
|
|
|
|
|
|
|
fn _f(s: &str) -> Option<&str> {
|
2022-04-04 10:30:38 -05:00
|
|
|
let _ = s.split_once('=')?.1;
|
|
|
|
let _ = s.split_once('=')?.1;
|
|
|
|
let _ = s.rsplit_once('=')?.0;
|
|
|
|
let _ = s.rsplit_once('=')?.0;
|
2021-07-17 12:52:03 -05:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't lint, slices don't have `split_once`
|
|
|
|
let _ = [0, 1, 2].splitn(2, |&x| x == 1).nth(1).unwrap();
|
2021-09-10 11:20:39 -05:00
|
|
|
|
|
|
|
// `rsplitn` gives the results in the reverse order of `rsplit_once`
|
2021-10-28 22:32:37 -05:00
|
|
|
let _ = "key=value".rsplit_once('=').unwrap().0;
|
2021-09-10 11:20:39 -05:00
|
|
|
let (_, _) = "key=value".rsplit_once('=').map(|(x, y)| (y, x)).unwrap();
|
2022-04-04 10:30:38 -05:00
|
|
|
let _ = s.rsplit_once('=').map(|x| x.0);
|
2021-07-17 12:52:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn _msrv_1_51() {
|
|
|
|
#![clippy::msrv = "1.51"]
|
2022-04-09 06:34:43 -05:00
|
|
|
// `str::split_once` was stabilized in 1.52. Do not lint this
|
2021-07-17 12:52:03 -05:00
|
|
|
let _ = "key=value".splitn(2, '=').nth(1).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn _msrv_1_52() {
|
|
|
|
#![clippy::msrv = "1.52"]
|
|
|
|
let _ = "key=value".split_once('=').unwrap().1;
|
|
|
|
}
|