Skip to content

Stabilize the int_to_from_bytes feature #56207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 12 additions & 36 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
@@ -1921,12 +1921,10 @@ big-endian (network) byte order.
# Examples

```
#![feature(int_to_from_bytes)]

let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
assert_eq!(bytes, ", $be_bytes, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
@@ -1941,12 +1939,10 @@ little-endian byte order.
# Examples

```
#![feature(int_to_from_bytes)]

let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
assert_eq!(bytes, ", $le_bytes, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
@@ -1969,16 +1965,14 @@ instead.
# Examples

```
#![feature(int_to_from_bytes)]

let bytes = ", $swap_op, stringify!($SelfT), ".to_ne_bytes();
assert_eq!(bytes, if cfg!(target_endian = \"big\") {
", $be_bytes, "
} else {
", $le_bytes, "
});
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
@@ -1993,12 +1987,10 @@ big endian.
# Examples

```
#![feature(int_to_from_bytes)]

let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
assert_eq!(value, ", $swap_op, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
@@ -2014,12 +2006,10 @@ little endian.
# Examples

```
#![feature(int_to_from_bytes)]

let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
assert_eq!(value, ", $swap_op, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
@@ -2041,16 +2031,14 @@ appropriate instead.
# Examples

```
#![feature(int_to_from_bytes)]

let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"big\") {
", $be_bytes, "
} else {
", $le_bytes, "
});
assert_eq!(value, ", $swap_op, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
@@ -3663,12 +3651,10 @@ big-endian (network) byte order.
# Examples

```
#![feature(int_to_from_bytes)]

let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
assert_eq!(bytes, ", $be_bytes, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
@@ -3683,12 +3669,10 @@ little-endian byte order.
# Examples

```
#![feature(int_to_from_bytes)]

let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
assert_eq!(bytes, ", $le_bytes, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
@@ -3711,16 +3695,14 @@ instead.
# Examples

```
#![feature(int_to_from_bytes)]

let bytes = ", $swap_op, stringify!($SelfT), ".to_ne_bytes();
assert_eq!(bytes, if cfg!(target_endian = \"big\") {
", $be_bytes, "
} else {
", $le_bytes, "
});
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
@@ -3735,12 +3717,10 @@ big endian.
# Examples

```
#![feature(int_to_from_bytes)]

let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
assert_eq!(value, ", $swap_op, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
@@ -3756,12 +3736,10 @@ little endian.
# Examples

```
#![feature(int_to_from_bytes)]

let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
assert_eq!(value, ", $swap_op, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
@@ -3783,16 +3761,14 @@ appropriate instead.
# Examples

```
#![feature(int_to_from_bytes)]

let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"big\") {
", $be_bytes, "
} else {
", $le_bytes, "
});
assert_eq!(value, ", $swap_op, ");
```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
2 changes: 1 addition & 1 deletion src/test/run-pass/const-int-conversion.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(const_int_conversion, const_int_ops, reverse_bits, int_to_from_bytes)]
#![feature(const_int_conversion, const_int_ops, reverse_bits)]

const REVERSE: u32 = 0x12345678_u32.reverse_bits();
const FROM_BE_BYTES: i32 = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-int-conversion.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(reverse_bits, int_to_from_bytes)]
#![feature(reverse_bits)]

fn main() {
let x: &'static i32 = &(5_i32.reverse_bits());