Auto merge of #58161 - davidtwco:issue-57960, r=arielb1

Lower constant patterns with ascribed types.

Fixes #57960.

This PR 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 PR unwraps that to
access the constant pattern inside and behaves as before.

r? @pnkfelix
This commit is contained in:
bors 2019-02-08 17:13:56 +00:00
commit a2ec156a5b
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);
}