]> git.proxmox.com Git - rustc.git/blob - src/test/ui/closures/2229_closure_analysis/run_pass/tuple-struct-pattern-matching-with-methods.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / run_pass / tuple-struct-pattern-matching-with-methods.rs
1 // edition:2021
2 //check-pass
3
4 #[derive(Copy, Clone)]
5 enum PointType {
6 TwoD(u32, u32),
7 ThreeD(u32, u32, u32)
8 }
9
10 // Testing tuple struct patterns
11 struct Points {
12 points: Vec<PointType>,
13 }
14
15 impl Points {
16 pub fn test1(&mut self) -> Vec<usize> {
17 (0..self.points.len())
18 .filter_map(|i| {
19 match self.test2(i) {
20 PointType::TwoD (..) => Some(i),
21 PointType::ThreeD (..) => None,
22 }
23 })
24 .collect()
25 }
26
27 pub fn test2(&mut self, i: usize) -> PointType {
28 self.points[i]
29 }
30 }
31
32 fn main() {
33 let mut points = Points {
34 points: Vec::<PointType>::new()
35 };
36
37 points.points.push(PointType::ThreeD(0,0,0));
38 points.points.push(PointType::TwoD(0,0));
39 points.points.push(PointType::ThreeD(0,0,1));
40 points.points.push(PointType::TwoD(0,1));
41
42 println!("{:?}", points.test1());
43 }