mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-27 22:34:14 +00:00
Add cross-crate const in pattern tests
This commit is contained in:
parent
b58da533bc
commit
e68a5c6800
11
src/test/ui/consts/const_in_pattern/auxiliary/consts.rs
Normal file
11
src/test/ui/consts/const_in_pattern/auxiliary/consts.rs
Normal 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);
|
16
src/test/ui/consts/const_in_pattern/cross-crate-fail.rs
Normal file
16
src/test/ui/consts/const_in_pattern/cross-crate-fail.rs
Normal 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)]`
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
14
src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr
Normal file
14
src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr
Normal 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
|
||||
|
14
src/test/ui/consts/const_in_pattern/cross-crate-pass.rs
Normal file
14
src/test/ui/consts/const_in_pattern/cross-crate-pass.rs
Normal 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!(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user