diff --git a/src/test/ui/consts/const_in_pattern/auxiliary/consts.rs b/src/test/ui/consts/const_in_pattern/auxiliary/consts.rs index 303c2f12bbc..b438bcd9fb5 100644 --- a/src/test/ui/consts/const_in_pattern/auxiliary/consts.rs +++ b/src/test/ui/consts/const_in_pattern/auxiliary/consts.rs @@ -9,3 +9,8 @@ impl PartialEq for CustomEq { pub const NONE: Option = None; pub const SOME: Option = Some(CustomEq); + +pub trait AssocConst { + const NONE: Option = None; + const SOME: Option = Some(CustomEq); +} diff --git a/src/test/ui/consts/const_in_pattern/cross-crate-fail.rs b/src/test/ui/consts/const_in_pattern/cross-crate-fail.rs index c9e6050fdc5..05c53e5edcc 100644 --- a/src/test/ui/consts/const_in_pattern/cross-crate-fail.rs +++ b/src/test/ui/consts/const_in_pattern/cross-crate-fail.rs @@ -4,7 +4,11 @@ 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)]` @@ -12,4 +16,12 @@ fn main() { _ => {} } + + match None { + ::SOME => panic!(), + //~^ must be annotated with `#[derive(PartialEq, Eq)]` + //~| must be annotated with `#[derive(PartialEq, Eq)]` + + _ => {} + } } diff --git a/src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr b/src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr index c97298f66e6..5d147e32f5a 100644 --- a/src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr +++ b/src/test/ui/consts/const_in_pattern/cross-crate-fail.stderr @@ -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 | ::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 | ::SOME => panic!(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/const_in_pattern/cross-crate-pass.rs b/src/test/ui/consts/const_in_pattern/cross-crate-pass.rs index ccf655c11cf..1d8ecf8ae66 100644 --- a/src/test/ui/consts/const_in_pattern/cross-crate-pass.rs +++ b/src/test/ui/consts/const_in_pattern/cross-crate-pass.rs @@ -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) { + ::NONE => panic!(), + _ => {} + } }