Skip to content

Commit 5f19f12

Browse files
committed
Moved ui test
1 parent cdbe28e commit 5f19f12

File tree

5 files changed

+56
-34
lines changed

5 files changed

+56
-34
lines changed

library/alloc/src/collections/btree/map/tests.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1786,13 +1786,6 @@ fn test_ord_absence() {
17861786
}
17871787
}
17881788

1789-
#[allow(dead_code)]
1790-
fn test_const() {
1791-
const MAP: &'static BTreeMap<(), ()> = &BTreeMap::new();
1792-
const LEN: usize = MAP.len();
1793-
const IS_EMPTY: bool = MAP.is_empty();
1794-
}
1795-
17961789
#[test]
17971790
fn test_occupied_entry_key() {
17981791
let mut a = BTreeMap::new();

library/alloc/src/collections/btree/set/tests.rs

-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ fn test_clone_eq() {
1616
assert_eq!(m.clone(), m);
1717
}
1818

19-
#[allow(dead_code)]
20-
fn test_const() {
21-
const SET: &'static BTreeSet<()> = &BTreeSet::new();
22-
const LEN: usize = SET.len();
23-
const IS_EMPTY: bool = SET.is_empty();
24-
}
25-
2619
#[test]
2720
fn test_iter_min_max() {
2821
let mut a = BTreeSet::new();

library/alloc/tests/const_fns.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Test several functions can be used for constants
2+
// 1. Vec::new()
3+
// 2. String::new()
4+
// 3. BTreeMap::new()
5+
// 4. BTreeSet::new()
6+
7+
#[allow(dead_code)]
8+
pub const MY_VEC: Vec<usize> = Vec::new();
9+
10+
#[allow(dead_code)]
11+
pub const MY_STRING: String = String::new();
12+
13+
// FIXME remove this struct once we put `K: ?const Ord` on BTreeMap::new.
14+
#[derive(PartialEq, Eq, PartialOrd)]
15+
pub struct MyType;
16+
17+
impl const Ord for MyType {
18+
fn cmp(&self, _: &Self) -> Ordering {
19+
Ordering::Equal
20+
}
21+
22+
fn max(self, _: Self) -> Self {
23+
Self
24+
}
25+
26+
fn min(self, _: Self) -> Self {
27+
Self
28+
}
29+
30+
fn clamp(self, _: Self, _: Self) -> Self {
31+
Self
32+
}
33+
}
34+
35+
use core::cmp::Ordering;
36+
use std::collections::{BTreeMap, BTreeSet};
37+
38+
pub const MY_BTREEMAP: BTreeMap<MyType, MyType> = BTreeMap::new();
39+
pub const MAP: &'static BTreeMap<MyType, MyType> = &MY_BTREEMAP;
40+
pub const MAP_LEN: usize = MAP.len();
41+
pub const MAP_IS_EMPTY: bool = MAP.is_empty();
42+
43+
pub const MY_BTREESET: BTreeSet<MyType> = BTreeSet::new();
44+
pub const SET: &'static BTreeSet<MyType> = &MY_BTREESET;
45+
pub const SET_LEN: usize = SET.len();
46+
pub const SET_IS_EMPTY: bool = SET.is_empty();
47+
48+
#[test]
49+
fn test_const() {
50+
assert_eq!(MAP_LEN, 0);
51+
assert_eq!(SET_LEN, 0);
52+
assert!(MAP_IS_EMPTY && SET_IS_EMPTY)
53+
}

library/alloc/tests/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#![feature(slice_partition_dedup)]
2222
#![feature(vec_spare_capacity)]
2323
#![feature(string_remove_matches)]
24+
#![feature(const_btree_new)]
25+
#![feature(const_trait_impl)]
2426

2527
use std::collections::hash_map::DefaultHasher;
2628
use std::hash::{Hash, Hasher};
@@ -30,6 +32,7 @@ mod binary_heap;
3032
mod borrow;
3133
mod boxed;
3234
mod btree_set_hash;
35+
mod const_fns;
3336
mod cow_str;
3437
mod fmt;
3538
mod heap;

src/test/ui/collections-const-new.rs

-20
This file was deleted.

0 commit comments

Comments
 (0)