Skip to content

Commit 123f489

Browse files
committed
Add tests for static new methods
1 parent e48b154 commit 123f489

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

src/__core.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,30 @@ pub mod mem {
4747
}
4848
);
4949
}
50+
51+
#[cfg(feature = "const-fn")] // Remove this if there are more tests
52+
#[cfg(test)]
53+
mod test {
54+
use __core;
55+
use __core::mem::ManuallyDrop;
56+
use core;
57+
58+
#[cfg(feature = "const-fn")]
59+
#[test]
60+
fn static_uninitzialized() {
61+
static mut I: i32 = unsafe { __core::mem::uninitialized() };
62+
// Initialize before drop
63+
unsafe { core::ptr::write(&mut I as *mut i32, 42) };
64+
unsafe{ assert_eq!(I, 42) };
65+
}
66+
67+
#[cfg(feature = "const-fn")]
68+
#[test]
69+
fn static_new_manually_drop() {
70+
static mut M: ManuallyDrop<i32> = ManuallyDrop::new(42);
71+
unsafe { assert_eq!(*M, 42); }
72+
// Drop before deinitialization
73+
unsafe { core::ptr::drop_in_place(&mut M as &mut i32 as *mut i32) };
74+
}
75+
76+
}

src/binary_heap.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ mod tests {
433433
use binary_heap::{self, BinaryHeap, Min};
434434
use consts::*;
435435

436+
#[cfg(feature = "const-fn")]
437+
#[test]
438+
fn static_new() {
439+
static mut _B: BinaryHeap<i32, U16, Min> = BinaryHeap::new();
440+
}
441+
436442
#[test]
437443
fn min() {
438444
let mut heap = BinaryHeap::<_, U16, Min>::new();

src/linear_map.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,18 @@ where
442442
self.iter.next().map(|&mut (ref k, ref mut v)| (k, v))
443443
}
444444
}
445+
446+
447+
#[cfg(feature = "const-fn")] // Remove this if there are more tests
448+
#[cfg(test)]
449+
mod test {
450+
use consts::*;
451+
use LinearMap;
452+
453+
#[cfg(feature = "const-fn")]
454+
#[test]
455+
fn static_new() {
456+
static mut _L: LinearMap<i32, i32, U8>= LinearMap::new();
457+
}
458+
459+
}

src/ring_buffer/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ mod tests {
445445
use consts::*;
446446
use RingBuffer;
447447

448+
#[cfg(feature = "const-fn")]
449+
#[test]
450+
fn static_new() {
451+
static mut _R: RingBuffer<i32, U4> = RingBuffer::new();
452+
}
453+
448454
#[test]
449455
fn drop() {
450456
struct Droppable;

src/string.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ mod tests {
524524
use consts::*;
525525
use {String, Vec};
526526

527+
#[cfg(feature = "const-fn")]
528+
#[test]
529+
fn static_new() {
530+
static mut _S: String<U8> = String::new();
531+
}
532+
527533
#[test]
528534
fn debug() {
529535
extern crate std;

src/vec.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,12 @@ mod tests {
514514
use consts::*;
515515
use Vec;
516516

517+
#[cfg(feature = "const-fn")]
518+
#[test]
519+
fn static_new() {
520+
static mut _V: Vec<i32, U4> = Vec::new();
521+
}
522+
517523
macro_rules! droppable {
518524
() => (
519525
struct Droppable;

0 commit comments

Comments
 (0)