Lower constant patterns with ascribed types.

This commit fixes a bug introduced by #55937 which started checking user
type annotations for associated type patterns. Where lowering a
associated constant expression would previously return a
`PatternKind::Constant`, it now returns a `PatternKind::AscribeUserType`
with a `PatternKind::Constant` inside, this commit unwraps that to
access the constant pattern inside and behaves as before.
This commit is contained in:
David Wood 2019-02-04 19:12:46 +01:00
parent 8ae730a442
commit 6717727fcb
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
2 changed files with 68 additions and 4 deletions

View file

@ -0,0 +1,39 @@
// run-pass
#![allow(dead_code)]
trait Range {
const FIRST: u8;
const LAST: u8;
}
struct OneDigit;
impl Range for OneDigit {
const FIRST: u8 = 0;
const LAST: u8 = 9;
}
struct TwoDigits;
impl Range for TwoDigits {
const FIRST: u8 = 10;
const LAST: u8 = 99;
}
struct ThreeDigits;
impl Range for ThreeDigits {
const FIRST: u8 = 100;
const LAST: u8 = 255;
}
fn digits(x: u8) -> u32 {
match x {
OneDigit::FIRST...OneDigit::LAST => 1,
TwoDigits::FIRST...TwoDigits::LAST => 2,
ThreeDigits::FIRST...ThreeDigits::LAST => 3,
_ => unreachable!(),
}
}
fn main() {
assert_eq!(digits(100), 3);
}