From bcc44b8e025978ae14ff11d484aacbb85aa8eaed Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sat, 2 May 2020 14:39:12 -0700 Subject: [PATCH] Test associated const default qualifs cross-crate This also tests for the ICE in #71734 --- .../const_in_pattern/auxiliary/consts.rs | 5 +++++ .../const_in_pattern/cross-crate-fail.rs | 12 ++++++++++++ .../const_in_pattern/cross-crate-fail.stderr | 18 +++++++++++++++--- .../const_in_pattern/cross-crate-pass.rs | 9 +++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) 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 303c2f12bbce..b438bcd9fb5e 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 c9e6050fdc50..05c53e5edccc 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 c97298f66e67..5d147e32f5a8 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 ccf655c11cf8..1d8ecf8ae664 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!(), + _ => {} + } }