diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-04-07 13:01:41 -0700 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-04-28 14:58:50 -0700 |
| commit | e68a5c68000810cab9755754959318c4aaa93e5d (patch) | |
| tree | 063b679896c18844472bce7fb354f6a10a1c486b | |
| parent | b58da533bc0fc6afd61eafaf3860b9934c8120b8 (diff) | |
| download | rust-e68a5c68000810cab9755754959318c4aaa93e5d.tar.gz rust-e68a5c68000810cab9755754959318c4aaa93e5d.zip | |
Add cross-crate const in pattern tests
4 files changed, 55 insertions, 0 deletions
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 index 00000000000..303c2f12bbc --- /dev/null +++ b/src/test/ui/consts/const_in_pattern/auxiliary/consts.rs @@ -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 index 00000000000..a32450ab92f --- /dev/null +++ b/src/test/ui/consts/const_in_pattern/cross-crate-fail.rs @@ -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 index 00000000000..d5bb0dd0f25 --- /dev/null +++ b/src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr @@ -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 index 00000000000..23f73a27d66 --- /dev/null +++ b/src/test/ui/consts/const_in_pattern/cross-crate-pass.rs @@ -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!(), + _ => {} + } +} |
