diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/needless_splitn.fixed | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/needless_splitn.fixed')
-rw-r--r-- | src/tools/clippy/tests/ui/needless_splitn.fixed | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/needless_splitn.fixed b/src/tools/clippy/tests/ui/needless_splitn.fixed new file mode 100644 index 000000000..61f5fc4e6 --- /dev/null +++ b/src/tools/clippy/tests/ui/needless_splitn.fixed @@ -0,0 +1,47 @@ +// run-rustfix +// edition:2018 + +#![feature(custom_inner_attributes)] +#![warn(clippy::needless_splitn)] +#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)] + +extern crate itertools; + +#[allow(unused_imports)] +use itertools::Itertools; + +fn main() { + let str = "key=value=end"; + let _ = str.split('=').next(); + let _ = str.split('=').nth(0); + let _ = str.splitn(2, '=').nth(1); + let (_, _) = str.splitn(2, '=').next_tuple().unwrap(); + let (_, _) = str.split('=').next_tuple().unwrap(); + let _: Vec<&str> = str.splitn(3, '=').collect(); + + let _ = str.rsplit('=').next(); + let _ = str.rsplit('=').nth(0); + let _ = str.rsplitn(2, '=').nth(1); + let (_, _) = str.rsplitn(2, '=').next_tuple().unwrap(); + let (_, _) = str.rsplit('=').next_tuple().unwrap(); + + let _ = str.split('=').next(); + let _ = str.split('=').nth(3); + let _ = str.splitn(5, '=').nth(4); + let _ = str.splitn(5, '=').nth(5); +} + +fn _question_mark(s: &str) -> Option<()> { + let _ = s.split('=').next()?; + let _ = s.split('=').nth(0)?; + let _ = s.rsplit('=').next()?; + let _ = s.rsplit('=').nth(0)?; + + Some(()) +} + +fn _test_msrv() { + #![clippy::msrv = "1.51"] + // `manual_split_once` MSRV shouldn't apply to `needless_splitn` + let _ = "key=value".split('=').nth(0).unwrap(); +} |