]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_split_once.rs
Auto merge of #8624 - pitaj:is_digit_ascii_radix, r=xFrednet
[rust.git] / tests / ui / manual_split_once.rs
1 // run-rustfix
2
3 #![feature(custom_inner_attributes)]
4 #![warn(clippy::manual_split_once)]
5 #![allow(clippy::iter_skip_next, clippy::iter_nth_zero)]
6
7 extern crate itertools;
8
9 #[allow(unused_imports)]
10 use itertools::Itertools;
11
12 fn main() {
13     let _ = "key=value".splitn(2, '=').nth(2);
14     let _ = "key=value".splitn(2, '=').nth(1).unwrap();
15     let _ = "key=value".splitn(2, '=').skip(1).next().unwrap();
16     let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap();
17
18     let s = String::from("key=value");
19     let _ = s.splitn(2, '=').nth(1).unwrap();
20
21     let s = Box::<str>::from("key=value");
22     let _ = s.splitn(2, '=').nth(1).unwrap();
23
24     let s = &"key=value";
25     let _ = s.splitn(2, '=').skip(1).next().unwrap();
26
27     fn _f(s: &str) -> Option<&str> {
28         let _ = s.splitn(2, '=').nth(1)?;
29         let _ = s.splitn(2, '=').skip(1).next()?;
30         let _ = s.rsplitn(2, '=').nth(1)?;
31         let _ = s.rsplitn(2, '=').skip(1).next()?;
32         None
33     }
34
35     // Don't lint, slices don't have `split_once`
36     let _ = [0, 1, 2].splitn(2, |&x| x == 1).nth(1).unwrap();
37
38     // `rsplitn` gives the results in the reverse order of `rsplit_once`
39     let _ = "key=value".rsplitn(2, '=').nth(1).unwrap();
40     let (_, _) = "key=value".rsplitn(2, '=').next_tuple().unwrap();
41     let _ = s.rsplitn(2, '=').nth(1);
42 }
43
44 fn _msrv_1_51() {
45     #![clippy::msrv = "1.51"]
46     // `str::split_once` was stabilized in 1.52. Do not lint this
47     let _ = "key=value".splitn(2, '=').nth(1).unwrap();
48 }
49
50 fn _msrv_1_52() {
51     #![clippy::msrv = "1.52"]
52     let _ = "key=value".splitn(2, '=').nth(1).unwrap();
53 }