forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lower constant patterns with ascribed types.
This commit fixes a bug introduced by rust-lang#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.
- Loading branch information
Showing
2 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |