Rollup merge of #71839 - LG3696:master, r=cramertj
Make BTreeMap::new and BTreeSet::new const
This commit is contained in:
commit
f16c27f1c4
4 changed files with 14 additions and 2 deletions
|
@ -556,7 +556,8 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
|||
/// map.insert(1, "a");
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn new() -> BTreeMap<K, V> {
|
||||
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
|
||||
pub const fn new() -> BTreeMap<K, V> {
|
||||
BTreeMap { root: None, length: 0 }
|
||||
}
|
||||
|
||||
|
|
|
@ -309,7 +309,8 @@ impl<T: Ord> BTreeSet<T> {
|
|||
/// let mut set: BTreeSet<i32> = BTreeSet::new();
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn new() -> BTreeSet<T> {
|
||||
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
|
||||
pub const fn new() -> BTreeSet<T> {
|
||||
BTreeSet { map: BTreeMap::new() }
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#![feature(cfg_sanitize)]
|
||||
#![feature(cfg_target_has_atomic)]
|
||||
#![feature(coerce_unsized)]
|
||||
#![feature(const_btree_new)]
|
||||
#![feature(const_generic_impls_guard)]
|
||||
#![feature(const_generics)]
|
||||
#![feature(const_in_array_repeat_expressions)]
|
||||
|
|
|
@ -3,9 +3,18 @@
|
|||
// Test several functions can be used for constants
|
||||
// 1. Vec::new()
|
||||
// 2. String::new()
|
||||
// 3. BTreeMap::new()
|
||||
// 4. BTreeSet::new()
|
||||
|
||||
#![feature(const_btree_new)]
|
||||
|
||||
const MY_VEC: Vec<usize> = Vec::new();
|
||||
|
||||
const MY_STRING: String = String::new();
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
const MY_BTREEMAP: BTreeMap<u32, u32> = BTreeMap::new();
|
||||
|
||||
const MY_BTREESET: BTreeSet<u32> = BTreeSet::new();
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Add table
Reference in a new issue