]> git.lizzy.rs Git - rust.git/blob - tests/ui/bytecount.rs
Merge remote-tracking branch 'upstream/master'
[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
11
12
13
14 #[deny(clippy::naive_bytecount)]
15 fn main() {
16     let x = vec![0_u8; 16];
17
18     let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count
19
20     let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count
21
22     let _ = x.iter().filter(|a| **a > 0).count(); // not an equality count, OK.
23
24     let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); // not a slice
25
26     let b = 0;
27
28     let _ = x.iter().filter(|_| b > 0).count(); // woah there
29
30     let _ = x.iter().filter(|_a| b == b + 1).count(); // nothing to see here, move along
31
32     let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
33
34     let y = vec![0_u16; 3];
35
36     let _ = y.iter().filter(|&&a| a == 0).count(); // naive count, but not bytes
37 }