]> git.lizzy.rs Git - rust.git/blob - tests/ui/bytecount.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[rust.git] / tests / ui / bytecount.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #[deny(clippy::naive_bytecount)]
11 fn main() {
12     let x = vec![0_u8; 16];
13
14     let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count
15
16     let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count
17
18     let _ = x.iter().filter(|a| **a > 0).count(); // not an equality count, OK.
19
20     let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); // not a slice
21
22     let b = 0;
23
24     let _ = x.iter().filter(|_| b > 0).count(); // woah there
25
26     let _ = x.iter().filter(|_a| b == b + 1).count(); // nothing to see here, move along
27
28     let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
29
30     let y = vec![0_u16; 3];
31
32     let _ = y.iter().filter(|&&a| a == 0).count(); // naive count, but not bytes
33 }