Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Test associated const default qualifs cross-crate
This also tests for the ICE in #71734
  • Loading branch information
ecstatic-morse committed May 2, 2020
commit bcc44b8e025978ae14ff11d484aacbb85aa8eaed
5 changes: 5 additions & 0 deletions src/test/ui/consts/const_in_pattern/auxiliary/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ impl PartialEq for CustomEq {

pub const NONE: Option<CustomEq> = None;
pub const SOME: Option<CustomEq> = Some(CustomEq);

pub trait AssocConst {
const NONE: Option<CustomEq> = None;
const SOME: Option<CustomEq> = Some(CustomEq);
}
12 changes: 12 additions & 0 deletions src/test/ui/consts/const_in_pattern/cross-crate-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@

extern crate consts;

struct Defaulted;
impl consts::AssocConst for Defaulted {}

fn main() {
let _ = Defaulted;
match None {
consts::SOME => panic!(),
//~^ must be annotated with `#[derive(PartialEq, Eq)]`
//~| must be annotated with `#[derive(PartialEq, Eq)]`

_ => {}
}

match None {
<Defaulted as consts::AssocConst>::SOME => panic!(),
//~^ must be annotated with `#[derive(PartialEq, Eq)]`
//~| must be annotated with `#[derive(PartialEq, Eq)]`

_ => {}
}
}
18 changes: 15 additions & 3 deletions src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
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:9:9
--> $DIR/cross-crate-fail.rs:13:9
|
LL | consts::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:9:9
--> $DIR/cross-crate-fail.rs:21:9
|
LL | <Defaulted as consts::AssocConst>::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:13:9
|
LL | consts::SOME => panic!(),
| ^^^^^^^^^^^^

error: aborting due to 2 previous errors
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:21:9
|
LL | <Defaulted as consts::AssocConst>::SOME => panic!(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

9 changes: 9 additions & 0 deletions src/test/ui/consts/const_in_pattern/cross-crate-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
extern crate consts;
use consts::CustomEq;

struct Defaulted;
impl consts::AssocConst for Defaulted {}

fn main() {
let _ = Defaulted;
match Some(CustomEq) {
consts::NONE => panic!(),
_ => {}
}

match Some(CustomEq) {
<Defaulted as consts::AssocConst>::NONE => panic!(),
_ => {}
}
}