stabilize const_int_wrapping.

This commit is contained in:
Mazdak Farrokhzad 2018-12-24 18:53:28 +01:00
parent a2b0f247bf
commit 7e7c337aef
3 changed files with 32 additions and 18 deletions

View file

@ -114,7 +114,6 @@
#![feature(const_str_as_bytes)]
#![feature(const_str_len)]
#![feature(const_int_rotate)]
#![feature(const_int_wrapping)]
#![feature(const_int_sign)]
#![feature(const_int_conversion)]
#![feature(const_transmute)]

View file

@ -994,7 +994,7 @@ assert_eq!(", stringify!($SelfT), "::max_value().wrapping_add(2), ", stringify!(
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_add(self, rhs: Self) -> Self {
unsafe {
@ -1018,7 +1018,7 @@ stringify!($SelfT), "::max_value());",
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_sub(self, rhs: Self) -> Self {
unsafe {
@ -1041,7 +1041,7 @@ assert_eq!(11i8.wrapping_mul(12), -124);",
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_mul(self, rhs: Self) -> Self {
unsafe {
@ -1205,7 +1205,7 @@ assert_eq!((-1", stringify!($SelfT), ").wrapping_shl(128), -1);",
$EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
@ -1233,7 +1233,7 @@ assert_eq!((-128i16).wrapping_shr(64), -128);",
$EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {
@ -2884,7 +2884,7 @@ assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::ma
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_add(self, rhs: Self) -> Self {
unsafe {
@ -2907,7 +2907,7 @@ assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::ma
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_sub(self, rhs: Self) -> Self {
unsafe {
@ -2931,7 +2931,7 @@ $EndFeature, "
/// assert_eq!(25u8.wrapping_mul(12), 44);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_mul(self, rhs: Self) -> Self {
unsafe {
@ -3081,7 +3081,7 @@ Basic usage:
assert_eq!(1", stringify!($SelfT), ".wrapping_shl(128), 1);", $EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
@ -3111,7 +3111,7 @@ Basic usage:
assert_eq!(128", stringify!($SelfT), ".wrapping_shr(128), 128);", $EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_unstable(feature = "const_int_wrapping")]
#[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {

View file

@ -342,15 +342,11 @@ fn check_terminator(
// some intrinsics are waved through if called inside the
// standard library. Users never need to call them directly
match tcx.fn_sig(def_id).abi() {
abi::Abi::RustIntrinsic => match &tcx.item_name(def_id).as_str()[..] {
| "size_of"
| "min_align_of"
| "needs_drop"
=> {},
_ => return Err((
abi::Abi::RustIntrinsic => if !is_intrinsic_whitelisted(tcx, def_id) {
return Err((
span,
"can only call a curated list of intrinsics in `min_const_fn`".into(),
)),
))
},
abi::Abi::Rust if tcx.is_min_const_fn(def_id) => {},
abi::Abi::Rust => return Err((
@ -390,3 +386,22 @@ fn check_terminator(
},
}
}
/// Returns true if the `def_id` refers to an intrisic which we've whitelisted.
///
/// Adding more intrinsics requires sign-off from @rust-lang/lang.
fn is_intrinsic_whitelisted(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
match &tcx.item_name(def_id).as_str()[..] {
| "size_of"
| "min_align_of"
| "needs_drop"
// Arithmetic:
| "overflowing_add" // ~> wrapping_add
| "overflowing_sub" // ~> wrapping_sub
| "overflowing_mul" // ~> wrapping_mul
| "unchecked_shl" // ~> wrapping_shl
| "unchecked_shr" // ~> wrapping_shr
=> true,
_ => false,
}
}