Rollup merge of #64028 - Centril:stabilize-alloc-new-2, r=alexcrichton

Stabilize `Vec::new` and `String::new` as `const fn`s

Closes https://github.com/rust-lang/rust/issues/64022.

r? @oli-obk
This commit is contained in:
Mazdak Farrokhzad 2019-09-16 17:09:34 +02:00 committed by GitHub
commit be327a8f69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 21 deletions

View file

@ -1,15 +1,11 @@
// run-pass
// check-pass
#![allow(dead_code)]
// Test several functions can be used for constants
// 1. Vec::new()
// 2. String::new()
#![feature(const_vec_new)]
#![feature(const_string_new)]
const MY_VEC: Vec<usize> = Vec::new();
const MY_STRING: String = String::new();
pub fn main() {}
fn main() {}

View file

@ -14,8 +14,9 @@ trait Bar<T, U: Foo<T>> {
impl Foo<u32> for () {
const X: u32 = 42;
}
impl Foo<Vec<u32>> for String {
const X: Vec<u32> = Vec::new(); //~ ERROR not yet stable as a const fn
const X: Vec<u32> = Vec::new();
}
impl Bar<u32, ()> for () {}

View file

@ -4,13 +4,5 @@ error[E0493]: destructors cannot be evaluated at compile-time
LL | const F: u32 = (U::X, 42).1;
| ^^^^^^^^^^ constants cannot evaluate destructors
error: `std::vec::Vec::<T>::new` is not yet stable as a const fn
--> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:18:25
|
LL | const X: Vec<u32> = Vec::new();
| ^^^^^^^^^^
|
= help: add `#![feature(const_vec_new)]` to the crate attributes to enable
error: aborting due to 2 previous errors
error: aborting due to previous error