]> git.proxmox.com Git - rustc.git/blobdiff - src/test/ui/closures/2229_closure_analysis/run_pass/tuple-struct-pattern-matching-with-methods.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / run_pass / tuple-struct-pattern-matching-with-methods.rs
diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/tuple-struct-pattern-matching-with-methods.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/tuple-struct-pattern-matching-with-methods.rs
new file mode 100644 (file)
index 0000000..b3bee79
--- /dev/null
@@ -0,0 +1,44 @@
+//check-pass
+#![feature(capture_disjoint_fields)]
+//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
+
+#[derive(Copy, Clone)]
+enum PointType {
+    TwoD(u32, u32),
+    ThreeD(u32, u32, u32)
+}
+
+// Testing tuple struct patterns
+struct Points {
+    points: Vec<PointType>,
+}
+
+impl Points {
+    pub fn test1(&mut self) -> Vec<usize> {
+        (0..self.points.len())
+            .filter_map(|i| {
+                match self.test2(i) {
+                    PointType::TwoD (..) => Some(i),
+                    PointType::ThreeD (..) => None,
+                }
+            })
+            .collect()
+    }
+
+    pub fn test2(&mut self, i: usize) -> PointType {
+        self.points[i]
+    }
+}
+
+fn main() {
+    let mut points = Points {
+        points: Vec::<PointType>::new()
+    };
+
+    points.points.push(PointType::ThreeD(0,0,0));
+    points.points.push(PointType::TwoD(0,0));
+    points.points.push(PointType::ThreeD(0,0,1));
+    points.points.push(PointType::TwoD(0,1));
+
+    println!("{:?}", points.test1());
+}