]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/map_identity.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / src / tools / clippy / tests / ui / map_identity.rs
CommitLineData
f20569fa
XL
1// run-rustfix
2#![warn(clippy::map_identity)]
3#![allow(clippy::needless_return)]
4
5fn main() {
6 let x: [u16; 3] = [1, 2, 3];
7 // should lint
8 let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect();
9 let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect();
10 let _: Option<u8> = Some(3).map(|x| x);
11 let _: Result<i8, f32> = Ok(-3).map(|x| {
12 return x;
13 });
14 // should not lint
15 let _: Vec<_> = x.iter().map(|x| 2 * x).collect();
16 let _: Vec<_> = x.iter().map(not_identity).map(|x| return x - 4).collect();
17 let _: Option<u8> = None.map(|x: u8| x - 1);
18 let _: Result<i8, f32> = Err(2.3).map(|x: i8| {
19 return x + 3;
20 });
21}
22
23fn not_identity(x: &u16) -> u16 {
24 *x
25}