Add cross-crate const in pattern tests

This commit is contained in:
Dylan MacKenzie 2020-04-07 13:01:41 -07:00
parent b58da533bc
commit e68a5c6800
4 changed files with 55 additions and 0 deletions

View File

@ -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);

View File

@ -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)]`
_ => {}
}
}

View File

@ -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

View File

@ -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!(),
_ => {}
}
}