2015-01-29 01:19:28 -06:00
|
|
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
2013-03-13 21:25:28 -05:00
|
|
|
// 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.
|
|
|
|
|
2014-02-19 20:56:33 -06:00
|
|
|
use std::fmt;
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2015-03-30 08:38:59 -05:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
2016-02-05 06:13:36 -06:00
|
|
|
#[allow(non_camel_case_types)]
|
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
|
|
|
pub enum Os {
|
2016-02-05 06:13:36 -06:00
|
|
|
Windows,
|
|
|
|
Macos,
|
|
|
|
Linux,
|
|
|
|
Android,
|
|
|
|
Freebsd,
|
|
|
|
iOS,
|
|
|
|
Dragonfly,
|
|
|
|
Bitrig,
|
|
|
|
Netbsd,
|
|
|
|
Openbsd,
|
|
|
|
NaCl,
|
|
|
|
Solaris,
|
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
|
|
|
}
|
|
|
|
|
2015-01-28 07:34:18 -06:00
|
|
|
#[derive(PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)]
|
2013-03-13 21:25:28 -05:00
|
|
|
pub enum Abi {
|
|
|
|
// NB: This ordering MUST match the AbiDatas array below.
|
|
|
|
// (This is ensured by the test indices_are_correct().)
|
|
|
|
|
|
|
|
// Single platform ABIs come first (`for_arch()` relies on this)
|
|
|
|
Cdecl,
|
|
|
|
Stdcall,
|
|
|
|
Fastcall,
|
2015-12-26 14:29:28 -06:00
|
|
|
Vectorcall,
|
2013-03-13 21:25:28 -05:00
|
|
|
Aapcs,
|
2013-11-16 17:25:56 -06:00
|
|
|
Win64,
|
2016-06-26 19:34:02 -05:00
|
|
|
SysV64,
|
2013-03-13 21:25:28 -05:00
|
|
|
|
|
|
|
// Multiplatform ABIs second
|
|
|
|
Rust,
|
|
|
|
C,
|
2013-11-08 13:06:57 -06:00
|
|
|
System,
|
2013-03-13 21:25:28 -05:00
|
|
|
RustIntrinsic,
|
2014-05-29 00:26:56 -05:00
|
|
|
RustCall,
|
2015-08-06 13:11:26 -05:00
|
|
|
PlatformIntrinsic,
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
#[allow(non_camel_case_types)]
|
2015-03-30 08:38:59 -05:00
|
|
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
2013-03-13 21:25:28 -05:00
|
|
|
pub enum Architecture {
|
|
|
|
X86,
|
|
|
|
X86_64,
|
|
|
|
Arm,
|
2014-06-17 02:16:03 -05:00
|
|
|
Mips,
|
|
|
|
Mipsel
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
2015-03-30 08:38:59 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-02-27 01:48:21 -06:00
|
|
|
pub struct AbiData {
|
2013-03-13 21:25:28 -05:00
|
|
|
abi: Abi,
|
|
|
|
|
|
|
|
// Name of this ABI as we like it called.
|
|
|
|
name: &'static str,
|
|
|
|
}
|
|
|
|
|
2015-03-30 08:38:59 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-02-27 01:48:21 -06:00
|
|
|
pub enum AbiArchitecture {
|
2014-06-09 15:12:30 -05:00
|
|
|
/// Not a real ABI (e.g., intrinsic)
|
2016-02-05 06:13:36 -06:00
|
|
|
Rust,
|
2014-06-09 15:12:30 -05:00
|
|
|
/// An ABI that specifies cross-platform defaults (e.g., "C")
|
2016-02-05 06:13:36 -06:00
|
|
|
All,
|
2014-06-09 15:12:30 -05:00
|
|
|
/// Multiple architectures (bitset)
|
|
|
|
Archs(u32)
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
2014-10-27 17:37:07 -05:00
|
|
|
#[allow(non_upper_case_globals)]
|
2015-02-27 08:36:53 -06:00
|
|
|
const AbiDatas: &'static [AbiData] = &[
|
2013-03-13 21:25:28 -05:00
|
|
|
// Platform-specific ABIs
|
2016-02-05 06:13:36 -06:00
|
|
|
AbiData {abi: Abi::Cdecl, name: "cdecl" },
|
|
|
|
AbiData {abi: Abi::Stdcall, name: "stdcall" },
|
|
|
|
AbiData {abi: Abi::Fastcall, name: "fastcall" },
|
|
|
|
AbiData {abi: Abi::Vectorcall, name: "vectorcall"},
|
|
|
|
AbiData {abi: Abi::Aapcs, name: "aapcs" },
|
|
|
|
AbiData {abi: Abi::Win64, name: "win64" },
|
2016-07-07 03:27:30 -05:00
|
|
|
AbiData {abi: Abi::SysV64, name: "sysv64" },
|
2013-03-13 21:25:28 -05:00
|
|
|
|
|
|
|
// Cross-platform ABIs
|
|
|
|
//
|
|
|
|
// NB: Do not adjust this ordering without
|
|
|
|
// adjusting the indices below.
|
2016-02-05 06:13:36 -06:00
|
|
|
AbiData {abi: Abi::Rust, name: "Rust" },
|
|
|
|
AbiData {abi: Abi::C, name: "C" },
|
|
|
|
AbiData {abi: Abi::System, name: "system" },
|
|
|
|
AbiData {abi: Abi::RustIntrinsic, name: "rust-intrinsic" },
|
|
|
|
AbiData {abi: Abi::RustCall, name: "rust-call" },
|
|
|
|
AbiData {abi: Abi::PlatformIntrinsic, name: "platform-intrinsic" }
|
2013-03-13 21:25:28 -05:00
|
|
|
];
|
|
|
|
|
2014-06-09 15:12:30 -05:00
|
|
|
/// Returns the ABI with the given name (if any).
|
2013-03-13 21:25:28 -05:00
|
|
|
pub fn lookup(name: &str) -> Option<Abi> {
|
2014-06-12 05:13:25 -05:00
|
|
|
AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi)
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
2014-02-28 15:09:09 -06:00
|
|
|
pub fn all_names() -> Vec<&'static str> {
|
2014-02-28 14:54:01 -06:00
|
|
|
AbiDatas.iter().map(|d| d.name).collect()
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
2013-05-31 17:17:22 -05:00
|
|
|
impl Abi {
|
2013-03-13 21:25:28 -05:00
|
|
|
#[inline]
|
2015-01-17 17:33:05 -06:00
|
|
|
pub fn index(&self) -> usize {
|
|
|
|
*self as usize
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2013-05-31 17:17:22 -05:00
|
|
|
pub fn data(&self) -> &'static AbiData {
|
2013-03-13 21:25:28 -05:00
|
|
|
&AbiDatas[self.index()]
|
|
|
|
}
|
|
|
|
|
2013-05-31 17:17:22 -05:00
|
|
|
pub fn name(&self) -> &'static str {
|
2013-03-13 21:25:28 -05:00
|
|
|
self.data().name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 17:45:07 -06:00
|
|
|
impl fmt::Display for Abi {
|
2014-02-19 20:56:33 -06:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-05-10 16:05:06 -05:00
|
|
|
write!(f, "\"{}\"", self.name())
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 17:45:07 -06:00
|
|
|
impl fmt::Display for Os {
|
2014-06-11 02:48:17 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2016-02-05 06:13:36 -06:00
|
|
|
Os::Linux => "linux".fmt(f),
|
|
|
|
Os::Windows => "windows".fmt(f),
|
|
|
|
Os::Macos => "macos".fmt(f),
|
|
|
|
Os::iOS => "ios".fmt(f),
|
|
|
|
Os::Android => "android".fmt(f),
|
|
|
|
Os::Freebsd => "freebsd".fmt(f),
|
|
|
|
Os::Dragonfly => "dragonfly".fmt(f),
|
|
|
|
Os::Bitrig => "bitrig".fmt(f),
|
|
|
|
Os::Netbsd => "netbsd".fmt(f),
|
|
|
|
Os::Openbsd => "openbsd".fmt(f),
|
|
|
|
Os::NaCl => "nacl".fmt(f),
|
|
|
|
Os::Solaris => "solaris".fmt(f),
|
2014-06-11 02:48:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 07:45:17 -05:00
|
|
|
#[allow(non_snake_case)]
|
2013-03-13 21:25:28 -05:00
|
|
|
#[test]
|
|
|
|
fn lookup_Rust() {
|
|
|
|
let abi = lookup("Rust");
|
2013-08-03 18:59:24 -05:00
|
|
|
assert!(abi.is_some() && abi.unwrap().data().name == "Rust");
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lookup_cdecl() {
|
|
|
|
let abi = lookup("cdecl");
|
2013-08-03 18:59:24 -05:00
|
|
|
assert!(abi.is_some() && abi.unwrap().data().name == "cdecl");
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lookup_baz() {
|
|
|
|
let abi = lookup("baz");
|
|
|
|
assert!(abi.is_none());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn indices_are_correct() {
|
2013-08-03 11:45:23 -05:00
|
|
|
for (i, abi_data) in AbiDatas.iter().enumerate() {
|
2013-11-08 13:06:57 -06:00
|
|
|
assert_eq!(i, abi_data.abi.index());
|
2013-03-13 21:25:28 -05:00
|
|
|
}
|
|
|
|
}
|