Auto merge of #53697 - Cyres:const-fn-int-ops, r=oli-obk

Add more const int ops

r? @oli-obk

Tracking Issue: #53718

list of `const fn`s in this PR:

- `feature = const_int_rotate`
  - `rotate_left`
  - `rotate_right`
- `feature = const_int_wrapping`
  - `wrapping_add`
  - `wrapping_sub`
  - `wrapping_mul`
  - `wrapping_shl`
  - `wrapping_shr`
- `feature = const_int_overflowing`
  - `overflowing_add`
  - `overflowing_sub`
  - `overflowing_mul`
  - `overflowing_shl`
  - `overflowing_shr`
- `feature = const_int_sign`
  - `is_positive`
  - `is_negative`
- `feature = const_int_conversion`
  - `reverse_bits`
  - `to_le_bytes`
  - `to_ne_bytes`
  - `from_be_bytes`
  - `from_le_bytes`
  - `from_ne_bytes`
  - `reverse_bits`
This commit is contained in:
bors 2018-09-03 16:31:34 +00:00
commit cd5c26f0eb
20 changed files with 1033 additions and 58 deletions

View file

@ -0,0 +1,28 @@
// Copyright 2018 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.
#![feature(reverse_bits, int_to_from_bytes)]
fn main() {
let x: &'static i32 = &(5_i32.reverse_bits());
//~^ ERROR does not live long enough
let y: &'static i32 = &(i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]));
//~^ ERROR does not live long enough
let z: &'static i32 = &(i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]));
//~^ ERROR does not live long enough
let a: &'static i32 = &(i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0])));
//~^ ERROR does not live long enough
let b: &'static [u8] = &(0x12_34_56_78_i32.to_be_bytes());
//~^ ERROR does not live long enough
let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes());
//~^ ERROR does not live long enough
let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes());
//~^ ERROR does not live long enough
}

View file

@ -0,0 +1,80 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-conversion.rs:14:28
|
LL | let x: &'static i32 = &(5_i32.reverse_bits());
| ^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-conversion.rs:16:28
|
LL | let y: &'static i32 = &(i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-conversion.rs:18:28
|
LL | let z: &'static i32 = &(i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-conversion.rs:20:28
|
LL | let a: &'static i32 = &(i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0])));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-conversion.rs:22:29
|
LL | let b: &'static [u8] = &(0x12_34_56_78_i32.to_be_bytes());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-conversion.rs:24:29
|
LL | let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-conversion.rs:26:29
|
LL | let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | //~^ ERROR does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,15 @@
// Copyright 2018 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.
fn main() {
let x: &'static (i32, bool) = &(5_i32.overflowing_add(3)); //~ ERROR does not live long enough
let y: &'static (i32, bool) = &(5_i32.overflowing_sub(3)); //~ ERROR does not live long enough
let z: &'static (i32, bool) = &(5_i32.overflowing_mul(3)); //~ ERROR does not live long enough
}

View file

@ -0,0 +1,35 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-overflowing.rs:12:36
|
LL | let x: &'static (i32, bool) = &(5_i32.overflowing_add(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-overflowing.rs:13:36
|
LL | let y: &'static (i32, bool) = &(5_i32.overflowing_sub(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | let z: &'static (i32, bool) = &(5_i32.overflowing_mul(3)); //~ ERROR does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-overflowing.rs:14:36
|
LL | let z: &'static (i32, bool) = &(5_i32.overflowing_mul(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,14 @@
// Copyright 2018 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.
fn main() {
let x: &'static i32 = &(5_i32.rotate_left(3)); //~ ERROR does not live long enough
let y: &'static i32 = &(5_i32.rotate_right(3)); //~ ERROR does not live long enough
}

View file

@ -0,0 +1,24 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-rotate.rs:12:28
|
LL | let x: &'static i32 = &(5_i32.rotate_left(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | let y: &'static i32 = &(5_i32.rotate_right(3)); //~ ERROR does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-rotate.rs:13:28
|
LL | let y: &'static i32 = &(5_i32.rotate_right(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,14 @@
// Copyright 2018 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.
fn main() {
let x: &'static bool = &(5_i32.is_negative()); //~ ERROR does not live long enough
let y: &'static bool = &(5_i32.is_positive()); //~ ERROR does not live long enough
}

View file

@ -0,0 +1,24 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-sign.rs:12:29
|
LL | let x: &'static bool = &(5_i32.is_negative()); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | let y: &'static bool = &(5_i32.is_positive()); //~ ERROR does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-sign.rs:13:29
|
LL | let y: &'static bool = &(5_i32.is_positive()); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,17 @@
// Copyright 2018 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.
fn main() {
let x: &'static i32 = &(5_i32.wrapping_add(3)); //~ ERROR does not live long enough
let y: &'static i32 = &(5_i32.wrapping_sub(3)); //~ ERROR does not live long enough
let z: &'static i32 = &(5_i32.wrapping_mul(3)); //~ ERROR does not live long enough
let a: &'static i32 = &(5_i32.wrapping_shl(3)); //~ ERROR does not live long enough
let b: &'static i32 = &(5_i32.wrapping_shr(3)); //~ ERROR does not live long enough
}

View file

@ -0,0 +1,57 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-wrapping.rs:12:28
|
LL | let x: &'static i32 = &(5_i32.wrapping_add(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-wrapping.rs:13:28
|
LL | let y: &'static i32 = &(5_i32.wrapping_sub(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-wrapping.rs:14:28
|
LL | let z: &'static i32 = &(5_i32.wrapping_mul(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
...
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-wrapping.rs:15:28
|
LL | let a: &'static i32 = &(5_i32.wrapping_shl(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | let b: &'static i32 = &(5_i32.wrapping_shr(3)); //~ ERROR does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: borrowed value does not live long enough
--> $DIR/const-int-wrapping.rs:16:28
|
LL | let b: &'static i32 = &(5_i32.wrapping_shr(3)); //~ ERROR does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0597`.