]> git.lizzy.rs Git - rust.git/commitdiff
Add cross-crate const in pattern tests
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 7 Apr 2020 20:01:41 +0000 (13:01 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 28 Apr 2020 21:58:50 +0000 (14:58 -0700)
src/test/ui/consts/const_in_pattern/auxiliary/consts.rs [new file with mode: 0644]
src/test/ui/consts/const_in_pattern/cross-crate-fail.rs [new file with mode: 0644]
src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr [new file with mode: 0644]
src/test/ui/consts/const_in_pattern/cross-crate-pass.rs [new file with mode: 0644]

diff --git a/src/test/ui/consts/const_in_pattern/auxiliary/consts.rs b/src/test/ui/consts/const_in_pattern/auxiliary/consts.rs
new file mode 100644 (file)
index 0000000..303c2f1
--- /dev/null
@@ -0,0 +1,11 @@
+pub struct CustomEq;
+
+impl Eq for CustomEq {}
+impl PartialEq for CustomEq {
+    fn eq(&self, _: &Self) -> bool {
+        false
+    }
+}
+
+pub const NONE: Option<CustomEq> = None;
+pub const SOME: Option<CustomEq> = Some(CustomEq);
diff --git a/src/test/ui/consts/const_in_pattern/cross-crate-fail.rs b/src/test/ui/consts/const_in_pattern/cross-crate-fail.rs
new file mode 100644 (file)
index 0000000..a32450a
--- /dev/null
@@ -0,0 +1,16 @@
+// aux-build:consts.rs
+
+#![warn(indirect_structural_match)]
+
+extern crate consts;
+use consts::*;
+
+fn main() {
+    match None {
+        SOME => panic!(),
+        //~^ must be annotated with `#[derive(PartialEq, Eq)]`
+        //~| must be annotated with `#[derive(PartialEq, Eq)]`
+
+        _ => {}
+    }
+}
diff --git a/src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr b/src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr
new file mode 100644 (file)
index 0000000..d5bb0dd
--- /dev/null
@@ -0,0 +1,14 @@
+error: to use a constant of type `consts::CustomEq` in a pattern, `consts::CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
+  --> $DIR/cross-crate-fail.rs:10:9
+   |
+LL |         SOME => panic!(),
+   |         ^^^^
+
+error: to use a constant of type `consts::CustomEq` in a pattern, `consts::CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
+  --> $DIR/cross-crate-fail.rs:10:9
+   |
+LL |         SOME => panic!(),
+   |         ^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/consts/const_in_pattern/cross-crate-pass.rs b/src/test/ui/consts/const_in_pattern/cross-crate-pass.rs
new file mode 100644 (file)
index 0000000..23f73a2
--- /dev/null
@@ -0,0 +1,14 @@
+// run-pass
+// aux-build:consts.rs
+
+#![warn(indirect_structural_match)]
+
+extern crate consts;
+use consts::*;
+
+fn main() {
+    match Some(CustomEq) {
+        NONE => panic!(),
+        _ => {}
+    }
+}