Skip to content

Commit bcc44b8

Browse files
Test associated const default qualifs cross-crate
This also tests for the ICE in rust-lang#71734
1 parent a91d648 commit bcc44b8

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

src/test/ui/consts/const_in_pattern/auxiliary/consts.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ impl PartialEq for CustomEq {
99

1010
pub const NONE: Option<CustomEq> = None;
1111
pub const SOME: Option<CustomEq> = Some(CustomEq);
12+
13+
pub trait AssocConst {
14+
const NONE: Option<CustomEq> = None;
15+
const SOME: Option<CustomEq> = Some(CustomEq);
16+
}

src/test/ui/consts/const_in_pattern/cross-crate-fail.rs

+12
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@
44

55
extern crate consts;
66

7+
struct Defaulted;
8+
impl consts::AssocConst for Defaulted {}
9+
710
fn main() {
11+
let _ = Defaulted;
812
match None {
913
consts::SOME => panic!(),
1014
//~^ must be annotated with `#[derive(PartialEq, Eq)]`
1115
//~| must be annotated with `#[derive(PartialEq, Eq)]`
1216

1317
_ => {}
1418
}
19+
20+
match None {
21+
<Defaulted as consts::AssocConst>::SOME => panic!(),
22+
//~^ must be annotated with `#[derive(PartialEq, Eq)]`
23+
//~| must be annotated with `#[derive(PartialEq, Eq)]`
24+
25+
_ => {}
26+
}
1527
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
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:9:9
2+
--> $DIR/cross-crate-fail.rs:13:9
33
|
44
LL | consts::SOME => panic!(),
55
| ^^^^^^^^^^^^
66

77
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:9:9
8+
--> $DIR/cross-crate-fail.rs:21:9
9+
|
10+
LL | <Defaulted as consts::AssocConst>::SOME => panic!(),
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: to use a constant of type `consts::CustomEq` in a pattern, `consts::CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
14+
--> $DIR/cross-crate-fail.rs:13:9
915
|
1016
LL | consts::SOME => panic!(),
1117
| ^^^^^^^^^^^^
1218

13-
error: aborting due to 2 previous errors
19+
error: to use a constant of type `consts::CustomEq` in a pattern, `consts::CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
20+
--> $DIR/cross-crate-fail.rs:21:9
21+
|
22+
LL | <Defaulted as consts::AssocConst>::SOME => panic!(),
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
1426

src/test/ui/consts/const_in_pattern/cross-crate-pass.rs

+9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
extern crate consts;
77
use consts::CustomEq;
88

9+
struct Defaulted;
10+
impl consts::AssocConst for Defaulted {}
11+
912
fn main() {
13+
let _ = Defaulted;
1014
match Some(CustomEq) {
1115
consts::NONE => panic!(),
1216
_ => {}
1317
}
18+
19+
match Some(CustomEq) {
20+
<Defaulted as consts::AssocConst>::NONE => panic!(),
21+
_ => {}
22+
}
1423
}

0 commit comments

Comments
 (0)