Skip to content

Commit e68a5c6

Browse files
Add cross-crate const in pattern tests
1 parent b58da53 commit e68a5c6

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub struct CustomEq;
2+
3+
impl Eq for CustomEq {}
4+
impl PartialEq for CustomEq {
5+
fn eq(&self, _: &Self) -> bool {
6+
false
7+
}
8+
}
9+
10+
pub const NONE: Option<CustomEq> = None;
11+
pub const SOME: Option<CustomEq> = Some(CustomEq);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aux-build:consts.rs
2+
3+
#![warn(indirect_structural_match)]
4+
5+
extern crate consts;
6+
use consts::*;
7+
8+
fn main() {
9+
match None {
10+
SOME => panic!(),
11+
//~^ must be annotated with `#[derive(PartialEq, Eq)]`
12+
//~| must be annotated with `#[derive(PartialEq, Eq)]`
13+
14+
_ => {}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: to use a constant of type `consts::CustomEq` in a pattern, `consts::CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/cross-crate-fail.rs:10:9
3+
|
4+
LL | SOME => panic!(),
5+
| ^^^^
6+
7+
error: to use a constant of type `consts::CustomEq` in a pattern, `consts::CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
8+
--> $DIR/cross-crate-fail.rs:10:9
9+
|
10+
LL | SOME => panic!(),
11+
| ^^^^
12+
13+
error: aborting due to 2 previous errors
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
// aux-build:consts.rs
3+
4+
#![warn(indirect_structural_match)]
5+
6+
extern crate consts;
7+
use consts::*;
8+
9+
fn main() {
10+
match Some(CustomEq) {
11+
NONE => panic!(),
12+
_ => {}
13+
}
14+
}

0 commit comments

Comments
 (0)