Skip to content

Commit 160063a

Browse files
committed
make String::new() const
1 parent 1d16826 commit 160063a

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
#![feature(inclusive_range_methods)]
126126
#![cfg_attr(stage0, feature(generic_param_attrs))]
127127
#![feature(rustc_const_unstable)]
128+
#![feature(const_vec_new)]
128129

129130
#![cfg_attr(not(test), feature(fn_traits, i128))]
130131
#![cfg_attr(test, feature(test))]

src/liballoc/string.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ impl String {
380380
/// ```
381381
#[inline]
382382
#[stable(feature = "rust1", since = "1.0.0")]
383-
pub fn new() -> String {
383+
#[rustc_const_unstable(feature = "const_string_new")]
384+
pub const fn new() -> String {
384385
String { vec: Vec::new() }
385386
}
386387

src/test/run-pass/vec-const-new.rs renamed to src/test/run-pass/collections-const-new.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Test that Vec::new() can be used for constants
11+
// Test several functions can be used for constants
12+
// 1. Vec::new()
13+
// 2. String::new()
1214

1315
#![feature(const_vec_new)]
16+
#![feature(const_string_new)]
1417

1518
const MY_VEC: Vec<usize> = Vec::new();
1619

20+
const MY_STRING: String = String::new();
21+
1722
pub fn main() {}

0 commit comments

Comments
 (0)