2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2024-02-16 20:02:50 +00:00
|
|
|
//@ compile-flags: -g
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2016-03-11 18:36:46 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2014-07-13 13:12:47 +00:00
|
|
|
struct NewBool(bool);
|
|
|
|
|
2016-03-11 18:36:46 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2014-07-13 13:12:47 +00:00
|
|
|
enum Direction {
|
|
|
|
North,
|
|
|
|
East,
|
|
|
|
South,
|
|
|
|
West
|
|
|
|
}
|
2016-03-11 18:36:46 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2014-07-13 13:12:47 +00:00
|
|
|
struct Foo {
|
|
|
|
bar: Option<Direction>,
|
|
|
|
baz: NewBool
|
|
|
|
}
|
2016-03-11 18:36:46 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2014-07-13 13:12:47 +00:00
|
|
|
enum EnumWithStructVariants {
|
|
|
|
Variant1(bool),
|
|
|
|
Variant2 {
|
|
|
|
dir: Direction
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 04:16:35 +00:00
|
|
|
const TRUE_TRUE: (bool, bool) = (true, true);
|
|
|
|
const NONE: Option<Direction> = None;
|
2014-11-06 08:05:53 +00:00
|
|
|
const EAST: Direction = Direction::East;
|
2014-10-07 04:16:35 +00:00
|
|
|
const NEW_FALSE: NewBool = NewBool(false);
|
2014-11-06 08:05:53 +00:00
|
|
|
const STATIC_FOO: Foo = Foo { bar: Some(Direction::South), baz: NEW_FALSE };
|
|
|
|
const VARIANT2_NORTH: EnumWithStructVariants = EnumWithStructVariants::Variant2 {
|
|
|
|
dir: Direction::North };
|
2014-07-13 13:12:47 +00:00
|
|
|
|
|
|
|
pub mod glfw {
|
2016-03-11 18:36:46 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
2015-03-26 00:06:52 +00:00
|
|
|
pub struct InputState(usize);
|
2014-07-13 13:12:47 +00:00
|
|
|
|
2014-10-07 04:16:35 +00:00
|
|
|
pub const RELEASE : InputState = InputState(0);
|
|
|
|
pub const PRESS : InputState = InputState(1);
|
|
|
|
pub const REPEAT : InputState = InputState(2);
|
2014-07-13 13:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_6533() {
|
|
|
|
fn action_to_str(state: glfw::InputState) -> &'static str {
|
|
|
|
use glfw::{RELEASE, PRESS, REPEAT};
|
|
|
|
match state {
|
|
|
|
RELEASE => { "Released" }
|
|
|
|
PRESS => { "Pressed" }
|
|
|
|
REPEAT => { "Repeated" }
|
|
|
|
_ => { "Unknown" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(action_to_str(glfw::RELEASE), "Released");
|
|
|
|
assert_eq!(action_to_str(glfw::PRESS), "Pressed");
|
|
|
|
assert_eq!(action_to_str(glfw::REPEAT), "Repeated");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_13626() {
|
2014-12-20 02:20:51 +00:00
|
|
|
const VAL: [u8; 1] = [0];
|
2014-07-13 13:12:47 +00:00
|
|
|
match [1] {
|
|
|
|
VAL => unreachable!(),
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_14576() {
|
|
|
|
type Foo = (i32, i32);
|
2014-10-07 04:16:35 +00:00
|
|
|
const ON: Foo = (1, 1);
|
|
|
|
const OFF: Foo = (0, 0);
|
2014-07-13 13:12:47 +00:00
|
|
|
|
|
|
|
match (1, 1) {
|
|
|
|
OFF => unreachable!(),
|
|
|
|
ON => (),
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
|
|
|
|
2016-03-11 18:36:46 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2014-07-13 13:12:47 +00:00
|
|
|
enum C { D = 3, E = 4 }
|
2014-11-06 08:05:53 +00:00
|
|
|
const F : C = C::D;
|
2014-07-13 13:12:47 +00:00
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(match C::D { F => 1, _ => 2, }, 1);
|
2018-03-27 15:19:41 +00:00
|
|
|
|
|
|
|
// test gaps
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
enum G { H = 3, I = 5 }
|
|
|
|
const K : G = G::I;
|
|
|
|
|
|
|
|
assert_eq!(match G::I { K => 1, _ => 2, }, 1);
|
2014-07-13 13:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_13731() {
|
2016-03-11 18:36:46 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2014-09-11 05:07:49 +00:00
|
|
|
enum A { AA(()) }
|
2014-11-06 08:05:53 +00:00
|
|
|
const B: A = A::AA(());
|
2014-07-13 13:12:47 +00:00
|
|
|
|
2014-11-06 08:05:53 +00:00
|
|
|
match A::AA(()) {
|
2014-07-13 13:12:47 +00:00
|
|
|
B => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_15393() {
|
|
|
|
#![allow(dead_code)]
|
2016-03-11 18:36:46 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2014-07-13 13:12:47 +00:00
|
|
|
struct Flags {
|
2015-03-26 00:06:52 +00:00
|
|
|
bits: usize
|
2014-07-13 13:12:47 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 04:16:35 +00:00
|
|
|
const FOO: Flags = Flags { bits: 0x01 };
|
|
|
|
const BAR: Flags = Flags { bits: 0x02 };
|
2014-07-13 13:12:47 +00:00
|
|
|
match (Flags { bits: 0x02 }) {
|
|
|
|
FOO => unreachable!(),
|
|
|
|
BAR => (),
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(match (true, false) {
|
2015-01-25 21:05:03 +00:00
|
|
|
TRUE_TRUE => 1,
|
2014-07-13 13:12:47 +00:00
|
|
|
(false, false) => 2,
|
|
|
|
(false, true) => 3,
|
|
|
|
(true, false) => 4
|
|
|
|
}, 4);
|
|
|
|
|
2014-11-06 08:05:53 +00:00
|
|
|
assert_eq!(match Some(Some(Direction::North)) {
|
2015-01-25 21:05:03 +00:00
|
|
|
Some(NONE) => 1,
|
2014-11-06 08:05:53 +00:00
|
|
|
Some(Some(Direction::North)) => 2,
|
2014-07-13 13:12:47 +00:00
|
|
|
Some(Some(EAST)) => 3,
|
2014-11-06 08:05:53 +00:00
|
|
|
Some(Some(Direction::South)) => 4,
|
|
|
|
Some(Some(Direction::West)) => 5,
|
2014-07-13 13:12:47 +00:00
|
|
|
None => 6
|
|
|
|
}, 2);
|
|
|
|
|
2014-11-06 08:05:53 +00:00
|
|
|
assert_eq!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }) {
|
2015-01-25 21:05:03 +00:00
|
|
|
Foo { bar: None, baz: NewBool(true) } => 1,
|
2014-07-13 13:12:47 +00:00
|
|
|
Foo { bar: NONE, baz: NEW_FALSE } => 2,
|
|
|
|
STATIC_FOO => 3,
|
|
|
|
Foo { bar: _, baz: NEW_FALSE } => 4,
|
2014-11-06 08:05:53 +00:00
|
|
|
Foo { bar: Some(Direction::West), baz: NewBool(true) } => 5,
|
|
|
|
Foo { bar: Some(Direction::South), baz: NewBool(true) } => 6,
|
2014-07-13 13:12:47 +00:00
|
|
|
Foo { bar: Some(EAST), .. } => 7,
|
2014-11-06 08:05:53 +00:00
|
|
|
Foo { bar: Some(Direction::North), baz: NewBool(true) } => 8
|
2014-07-13 13:12:47 +00:00
|
|
|
}, 5);
|
|
|
|
|
2014-11-06 08:05:53 +00:00
|
|
|
assert_eq!(match (EnumWithStructVariants::Variant2 { dir: Direction::North }) {
|
2015-01-25 21:05:03 +00:00
|
|
|
EnumWithStructVariants::Variant1(true) => 1,
|
2014-11-06 08:05:53 +00:00
|
|
|
EnumWithStructVariants::Variant1(false) => 2,
|
|
|
|
EnumWithStructVariants::Variant2 { dir: Direction::West } => 3,
|
2014-07-13 13:12:47 +00:00
|
|
|
VARIANT2_NORTH => 4,
|
2014-11-06 08:05:53 +00:00
|
|
|
EnumWithStructVariants::Variant2 { dir: Direction::South } => 5,
|
|
|
|
EnumWithStructVariants::Variant2 { dir: Direction::East } => 6
|
2014-07-13 13:12:47 +00:00
|
|
|
}, 4);
|
|
|
|
|
|
|
|
issue_6533();
|
|
|
|
issue_13626();
|
|
|
|
issue_13731();
|
|
|
|
issue_14576();
|
|
|
|
issue_15393();
|
|
|
|
}
|