Skip to content

Decode qualifs for associated const defaults #71813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,11 +1123,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
match self.kind(id) {
EntryKind::Const(qualif, _)
| EntryKind::AssocConst(
AssocContainer::ImplDefault | AssocContainer::ImplFinal,
AssocContainer::ImplDefault
| AssocContainer::ImplFinal
| AssocContainer::TraitWithDefault,
qualif,
_,
) => qualif,
_ => bug!(),
_ => bug!("mir_const_qualif: unexpected kind"),
}
}

Expand Down
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!(),
_ => {}
}
}