2014-07-13 08:12:47 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
struct NewBool(bool);
|
|
|
|
|
|
|
|
enum Direction {
|
|
|
|
North,
|
|
|
|
East,
|
|
|
|
South,
|
|
|
|
West
|
|
|
|
}
|
|
|
|
struct Foo {
|
|
|
|
bar: Option<Direction>,
|
|
|
|
baz: NewBool
|
|
|
|
}
|
|
|
|
enum EnumWithStructVariants {
|
|
|
|
Variant1(bool),
|
|
|
|
Variant2 {
|
|
|
|
dir: Direction
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 23:16:35 -05:00
|
|
|
const TRUE_TRUE: (bool, bool) = (true, true);
|
|
|
|
const NONE: Option<Direction> = None;
|
2014-11-06 02:05:53 -06:00
|
|
|
const EAST: Direction = Direction::East;
|
2014-10-06 23:16:35 -05:00
|
|
|
const NEW_FALSE: NewBool = NewBool(false);
|
2014-11-06 02:05:53 -06: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 08:12:47 -05:00
|
|
|
|
|
|
|
pub mod glfw {
|
|
|
|
pub struct InputState(uint);
|
|
|
|
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-05 19:01:33 -06:00
|
|
|
impl Copy for InputState {}
|
|
|
|
|
2014-10-06 23:16:35 -05:00
|
|
|
pub const RELEASE : InputState = InputState(0);
|
|
|
|
pub const PRESS : InputState = InputState(1);
|
|
|
|
pub const REPEAT : InputState = InputState(2);
|
2014-07-13 08:12:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_6533() {
|
|
|
|
use glfw;
|
|
|
|
|
|
|
|
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-10-06 23:16:35 -05:00
|
|
|
const VAL: [u8, ..1] = [0];
|
2014-07-13 08:12:47 -05:00
|
|
|
match [1] {
|
|
|
|
VAL => unreachable!(),
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_14576() {
|
|
|
|
type Foo = (i32, i32);
|
2014-10-06 23:16:35 -05:00
|
|
|
const ON: Foo = (1, 1);
|
|
|
|
const OFF: Foo = (0, 0);
|
2014-07-13 08:12:47 -05:00
|
|
|
|
|
|
|
match (1, 1) {
|
|
|
|
OFF => unreachable!(),
|
|
|
|
ON => (),
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
|
|
|
|
|
|
|
enum C { D = 3, E = 4 }
|
2014-11-06 02:05:53 -06:00
|
|
|
const F : C = C::D;
|
2014-07-13 08:12:47 -05:00
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
assert_eq!(match C::D { F => 1i, _ => 2, }, 1);
|
2014-07-13 08:12:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_13731() {
|
2014-09-11 00:07:49 -05:00
|
|
|
enum A { AA(()) }
|
2014-11-06 02:05:53 -06:00
|
|
|
const B: A = A::AA(());
|
2014-07-13 08:12:47 -05:00
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
match A::AA(()) {
|
2014-07-13 08:12:47 -05:00
|
|
|
B => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_15393() {
|
|
|
|
#![allow(dead_code)]
|
|
|
|
struct Flags {
|
|
|
|
bits: uint
|
|
|
|
}
|
|
|
|
|
2014-10-06 23:16:35 -05:00
|
|
|
const FOO: Flags = Flags { bits: 0x01 };
|
|
|
|
const BAR: Flags = Flags { bits: 0x02 };
|
2014-07-13 08:12:47 -05:00
|
|
|
match (Flags { bits: 0x02 }) {
|
|
|
|
FOO => unreachable!(),
|
|
|
|
BAR => (),
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(match (true, false) {
|
|
|
|
TRUE_TRUE => 1i,
|
|
|
|
(false, false) => 2,
|
|
|
|
(false, true) => 3,
|
|
|
|
(true, false) => 4
|
|
|
|
}, 4);
|
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
assert_eq!(match Some(Some(Direction::North)) {
|
2014-07-13 08:12:47 -05:00
|
|
|
Some(NONE) => 1i,
|
2014-11-06 02:05:53 -06:00
|
|
|
Some(Some(Direction::North)) => 2,
|
2014-07-13 08:12:47 -05:00
|
|
|
Some(Some(EAST)) => 3,
|
2014-11-06 02:05:53 -06:00
|
|
|
Some(Some(Direction::South)) => 4,
|
|
|
|
Some(Some(Direction::West)) => 5,
|
2014-07-13 08:12:47 -05:00
|
|
|
None => 6
|
|
|
|
}, 2);
|
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
assert_eq!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }) {
|
2014-07-13 08:12:47 -05:00
|
|
|
Foo { bar: None, baz: NewBool(true) } => 1i,
|
|
|
|
Foo { bar: NONE, baz: NEW_FALSE } => 2,
|
|
|
|
STATIC_FOO => 3,
|
|
|
|
Foo { bar: _, baz: NEW_FALSE } => 4,
|
2014-11-06 02:05:53 -06:00
|
|
|
Foo { bar: Some(Direction::West), baz: NewBool(true) } => 5,
|
|
|
|
Foo { bar: Some(Direction::South), baz: NewBool(true) } => 6,
|
2014-07-13 08:12:47 -05:00
|
|
|
Foo { bar: Some(EAST), .. } => 7,
|
2014-11-06 02:05:53 -06:00
|
|
|
Foo { bar: Some(Direction::North), baz: NewBool(true) } => 8
|
2014-07-13 08:12:47 -05:00
|
|
|
}, 5);
|
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
assert_eq!(match (EnumWithStructVariants::Variant2 { dir: Direction::North }) {
|
|
|
|
EnumWithStructVariants::Variant1(true) => 1i,
|
|
|
|
EnumWithStructVariants::Variant1(false) => 2,
|
|
|
|
EnumWithStructVariants::Variant2 { dir: Direction::West } => 3,
|
2014-07-13 08:12:47 -05:00
|
|
|
VARIANT2_NORTH => 4,
|
2014-11-06 02:05:53 -06:00
|
|
|
EnumWithStructVariants::Variant2 { dir: Direction::South } => 5,
|
|
|
|
EnumWithStructVariants::Variant2 { dir: Direction::East } => 6
|
2014-07-13 08:12:47 -05:00
|
|
|
}, 4);
|
|
|
|
|
|
|
|
issue_6533();
|
|
|
|
issue_13626();
|
|
|
|
issue_13731();
|
|
|
|
issue_14576();
|
|
|
|
issue_15393();
|
|
|
|
}
|