]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/get_first.fixed
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / get_first.fixed
1 // run-rustfix
2 #![warn(clippy::get_first)]
3 use std::collections::BTreeMap;
4 use std::collections::HashMap;
5 use std::collections::VecDeque;
6
7 struct Bar {
8 arr: [u32; 3],
9 }
10
11 impl Bar {
12 fn get(&self, pos: usize) -> Option<&u32> {
13 self.arr.get(pos)
14 }
15 }
16
17 fn main() {
18 let x = vec![2, 3, 5];
19 let _ = x.first(); // Use x.first()
20 let _ = x.get(1);
21 let _ = x[0];
22
23 let y = [2, 3, 5];
24 let _ = y.first(); // Use y.first()
25 let _ = y.get(1);
26 let _ = y[0];
27
28 let z = &[2, 3, 5];
29 let _ = z.first(); // Use z.first()
30 let _ = z.get(1);
31 let _ = z[0];
32
33 let vecdeque: VecDeque<_> = x.iter().cloned().collect();
34 let hashmap: HashMap<u8, char> = HashMap::from_iter(vec![(0, 'a'), (1, 'b')]);
35 let btreemap: BTreeMap<u8, char> = BTreeMap::from_iter(vec![(0, 'a'), (1, 'b')]);
36 let _ = vecdeque.get(0); // Do not lint, because VecDeque is not slice.
37 let _ = hashmap.get(&0); // Do not lint, because HashMap is not slice.
38 let _ = btreemap.get(&0); // Do not lint, because BTreeMap is not slice.
39
40 let bar = Bar { arr: [0, 1, 2] };
41 let _ = bar.get(0); // Do not lint, because Bar is struct.
42 }