Format tests with rustfmt (276-287 of 299)
This commit is contained in:
parent
7a1b08e46e
commit
7d09004aee
12 changed files with 255 additions and 235 deletions
|
|
@ -11,8 +11,10 @@ fn main() {
|
|||
// This is branchless code to select one or the other pointer.
|
||||
// However, it drops provenance when transmuting to TwoPtrs, so this is UB.
|
||||
let val = unsafe {
|
||||
transmute::<_, &str>( //~ERROR type validation failed: encountered a dangling reference
|
||||
!mask & transmute::<_, TwoPtrs>("false !") | mask & transmute::<_, TwoPtrs>("true !"),
|
||||
transmute::<_, &str>(
|
||||
//~ERROR type validation failed: encountered a dangling reference
|
||||
!mask & transmute::<_, TwoPtrs>("false !")
|
||||
| mask & transmute::<_, TwoPtrs>("true !"),
|
||||
)
|
||||
};
|
||||
println!("{}", val);
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ pub fn main() {
|
|||
let ptr = EvilSend(pointer);
|
||||
|
||||
unsafe {
|
||||
let j1 = spawn(move || {
|
||||
*ptr.0
|
||||
});
|
||||
let j1 = spawn(move || *ptr.0);
|
||||
|
||||
let j2 = spawn(move || {
|
||||
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1)
|
||||
__rust_dealloc(
|
||||
ptr.0 as *mut _,
|
||||
std::mem::size_of::<usize>(),
|
||||
std::mem::align_of::<usize>(),
|
||||
); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1)
|
||||
});
|
||||
|
||||
j1.join().unwrap();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,11 @@ pub fn main() {
|
|||
});
|
||||
|
||||
let j2 = spawn(move || {
|
||||
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1)
|
||||
__rust_dealloc(
|
||||
ptr.0 as *mut _,
|
||||
std::mem::size_of::<usize>(),
|
||||
std::mem::align_of::<usize>(),
|
||||
); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1)
|
||||
});
|
||||
|
||||
j1.join().unwrap();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ fn main() {
|
|||
unsafe {
|
||||
// Make sure we check the ABI when Miri itself invokes a function
|
||||
// as part of a shim implementation.
|
||||
std::intrinsics::r#try( //~ ERROR calling a function with ABI C using caller ABI Rust
|
||||
std::intrinsics::r#try(
|
||||
//~ ERROR calling a function with ABI C using caller ABI Rust
|
||||
std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
|
||||
std::ptr::null_mut(),
|
||||
|_, _| unreachable!(),
|
||||
|
|
|
|||
|
|
@ -10,12 +10,16 @@ fn main() {
|
|||
}
|
||||
|
||||
#[cfg(fn_ptr)]
|
||||
unsafe { std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)() }
|
||||
unsafe {
|
||||
std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)()
|
||||
}
|
||||
//[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C
|
||||
|
||||
// `Instance` caching should not suppress ABI check.
|
||||
#[cfg(cache)]
|
||||
unsafe { foo() }
|
||||
unsafe {
|
||||
foo()
|
||||
}
|
||||
|
||||
{
|
||||
#[cfg_attr(any(cache, fn_ptr), allow(clashing_extern_declarations))]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
// ignore-32bit
|
||||
|
||||
fn main() {
|
||||
let _fat: [u8; (1<<61)+(1<<31)] =
|
||||
[0; (1u64<<61) as usize +(1u64<<31) as usize]; //~ ERROR post-monomorphization error
|
||||
let _fat: [u8; (1 << 61) + (1 << 31)] = [0; (1u64 << 61) as usize + (1u64 << 31) as usize]; //~ ERROR post-monomorphization error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
fn main() {
|
||||
assert!(std::char::from_u32(-1_i32 as u32).is_none());
|
||||
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value
|
||||
'a' => {true},
|
||||
'b' => {false},
|
||||
_ => {true},
|
||||
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } {
|
||||
//~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value
|
||||
'a' => true,
|
||||
'b' => false,
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ fn test_corr() {
|
|||
r2 // | |
|
||||
}); // | |
|
||||
// |synchronizes-with |happens-before
|
||||
let j3 = spawn(move || { // | |
|
||||
let j3 = spawn(move || {
|
||||
// | |
|
||||
acquires_value(&y, 1); // <------------------+ |
|
||||
x.load(Relaxed) // <----------------------------------------------+
|
||||
// The two reads on x are ordered by hb, so they cannot observe values
|
||||
|
|
@ -84,12 +85,14 @@ fn test_wrc() {
|
|||
x.store(1, Release); // ---------------------+---------------------+
|
||||
}); // | |
|
||||
// |synchronizes-with |
|
||||
let j2 = spawn(move || { // | |
|
||||
let j2 = spawn(move || {
|
||||
// | |
|
||||
acquires_value(&x, 1); // <------------------+ |
|
||||
y.store(1, Release); // ---------------------+ |happens-before
|
||||
}); // | |
|
||||
// |synchronizes-with |
|
||||
let j3 = spawn(move || { // | |
|
||||
let j3 = spawn(move || {
|
||||
// | |
|
||||
acquires_value(&y, 1); // <------------------+ |
|
||||
x.load(Relaxed) // <-----------------------------------------------+
|
||||
});
|
||||
|
|
@ -112,7 +115,8 @@ fn test_message_passing() {
|
|||
y.store(1, Release); // ---------------------+ |
|
||||
}); // | |
|
||||
// |synchronizes-with | happens-before
|
||||
let j2 = spawn(move || { // | |
|
||||
let j2 = spawn(move || {
|
||||
// | |
|
||||
acquires_value(&y, 1); // <------------------+ |
|
||||
unsafe { *x.0 } // <---------------------------------------------+
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,25 +16,23 @@ fn wake_nobody() {
|
|||
|
||||
// Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting.
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAKE,
|
||||
1,
|
||||
), 0);
|
||||
assert_eq!(libc::syscall(libc::SYS_futex, &futex as *const i32, libc::FUTEX_WAKE, 1,), 0);
|
||||
}
|
||||
|
||||
// Same, but without omitting the unused arguments.
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAKE,
|
||||
1,
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0,
|
||||
), 0);
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAKE,
|
||||
1,
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0,
|
||||
),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,12 +43,7 @@ fn wake_dangling() {
|
|||
|
||||
// Wake 1 waiter. Expect zero waiters woken up, as nobody is waiting.
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
ptr,
|
||||
libc::FUTEX_WAKE,
|
||||
1,
|
||||
), 0);
|
||||
assert_eq!(libc::syscall(libc::SYS_futex, ptr, libc::FUTEX_WAKE, 1,), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,13 +52,16 @@ fn wait_wrong_val() {
|
|||
|
||||
// Only wait if the futex value is 456.
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAIT,
|
||||
456,
|
||||
ptr::null::<libc::timespec>(),
|
||||
), -1);
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAIT,
|
||||
456,
|
||||
ptr::null::<libc::timespec>(),
|
||||
),
|
||||
-1
|
||||
);
|
||||
assert_eq!(*libc::__errno_location(), libc::EAGAIN);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,16 +73,16 @@ fn wait_timeout() {
|
|||
|
||||
// Wait for 200ms, with nobody waking us up early.
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAIT,
|
||||
123,
|
||||
&libc::timespec {
|
||||
tv_sec: 0,
|
||||
tv_nsec: 200_000_000,
|
||||
},
|
||||
), -1);
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAIT,
|
||||
123,
|
||||
&libc::timespec { tv_sec: 0, tv_nsec: 200_000_000 },
|
||||
),
|
||||
-1
|
||||
);
|
||||
assert_eq!(*libc::__errno_location(), libc::ETIMEDOUT);
|
||||
}
|
||||
|
||||
|
|
@ -114,15 +110,18 @@ fn wait_absolute_timeout() {
|
|||
|
||||
// Wait for 200ms from now, with nobody waking us up early.
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAIT_BITSET,
|
||||
123,
|
||||
&timeout,
|
||||
0usize,
|
||||
u32::MAX,
|
||||
), -1);
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&futex as *const i32,
|
||||
libc::FUTEX_WAIT_BITSET,
|
||||
123,
|
||||
&timeout,
|
||||
0usize,
|
||||
u32::MAX,
|
||||
),
|
||||
-1
|
||||
);
|
||||
assert_eq!(*libc::__errno_location(), libc::ETIMEDOUT);
|
||||
}
|
||||
|
||||
|
|
@ -137,23 +136,29 @@ fn wait_wake() {
|
|||
let t = thread::spawn(move || {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAKE,
|
||||
10, // Wake up at most 10 threads.
|
||||
), 1); // Woken up one thread.
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAKE,
|
||||
10, // Wake up at most 10 threads.
|
||||
),
|
||||
1
|
||||
); // Woken up one thread.
|
||||
}
|
||||
});
|
||||
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAIT,
|
||||
0,
|
||||
ptr::null::<libc::timespec>(),
|
||||
), 0);
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAIT,
|
||||
0,
|
||||
ptr::null::<libc::timespec>(),
|
||||
),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
assert!((200..1000).contains(&start.elapsed().as_millis()));
|
||||
|
|
@ -168,40 +173,49 @@ fn wait_wake_bitset() {
|
|||
let t = thread::spawn(move || {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAKE_BITSET,
|
||||
10, // Wake up at most 10 threads.
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0b1001, // bitset
|
||||
), 0); // Didn't match any thread.
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAKE_BITSET,
|
||||
10, // Wake up at most 10 threads.
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0b1001, // bitset
|
||||
),
|
||||
0
|
||||
); // Didn't match any thread.
|
||||
}
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAKE_BITSET,
|
||||
10, // Wake up at most 10 threads.
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0b0110, // bitset
|
||||
), 1); // Woken up one thread.
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAKE_BITSET,
|
||||
10, // Wake up at most 10 threads.
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0b0110, // bitset
|
||||
),
|
||||
1
|
||||
); // Woken up one thread.
|
||||
}
|
||||
});
|
||||
|
||||
unsafe {
|
||||
assert_eq!(libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAIT_BITSET,
|
||||
0,
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0b0100, // bitset
|
||||
), 0);
|
||||
assert_eq!(
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const i32,
|
||||
libc::FUTEX_WAIT_BITSET,
|
||||
0,
|
||||
ptr::null::<libc::timespec>(),
|
||||
0usize,
|
||||
0b0100, // bitset
|
||||
),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
assert!((400..1000).contains(&start.elapsed().as_millis()));
|
||||
|
|
@ -237,12 +251,7 @@ fn concurrent_wait_wake() {
|
|||
|
||||
FUTEX.store(FREE, Ordering::Relaxed);
|
||||
unsafe {
|
||||
libc::syscall(
|
||||
libc::SYS_futex,
|
||||
&FUTEX as *const AtomicI32,
|
||||
libc::FUTEX_WAKE,
|
||||
1,
|
||||
);
|
||||
libc::syscall(libc::SYS_futex, &FUTEX as *const AtomicI32, libc::FUTEX_WAKE, 1);
|
||||
}
|
||||
|
||||
t.join().unwrap();
|
||||
|
|
|
|||
|
|
@ -40,10 +40,15 @@ struct TupleStruct<A, B: DeclaredTrait, C>(
|
|||
<C as WhereTrait>::Type,
|
||||
Option<<C as WhereTrait>::Type>,
|
||||
<i32 as DeclaredTrait>::Type,
|
||||
) where C: WhereTrait;
|
||||
)
|
||||
where
|
||||
C: WhereTrait;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Struct<A, B: DeclaredTrait, C> where C: WhereTrait {
|
||||
pub struct Struct<A, B: DeclaredTrait, C>
|
||||
where
|
||||
C: WhereTrait,
|
||||
{
|
||||
m1: module::Type,
|
||||
m2: Option<module::Type>,
|
||||
a1: A,
|
||||
|
|
@ -62,7 +67,10 @@ pub struct Struct<A, B: DeclaredTrait, C> where C: WhereTrait {
|
|||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum Enum<A, B: DeclaredTrait, C> where C: WhereTrait {
|
||||
enum Enum<A, B: DeclaredTrait, C>
|
||||
where
|
||||
C: WhereTrait,
|
||||
{
|
||||
Unit,
|
||||
Seq(
|
||||
module::Type,
|
||||
|
|
@ -101,35 +109,11 @@ enum Enum<A, B: DeclaredTrait, C> where C: WhereTrait {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
let e: Enum<
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
> = Enum::Seq(
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
PrivateStruct(0),
|
||||
0,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
);
|
||||
let e: Enum<i32, i32, i32> =
|
||||
Enum::Seq(0, None, 0, PrivateStruct(0), 0, 0, None, 0, None, 0, 0, None, 0, None, 0);
|
||||
assert_eq!(e, e);
|
||||
|
||||
let e: Enum<
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
> = Enum::Map {
|
||||
let e: Enum<i32, i32, i32> = Enum::Map {
|
||||
m1: 0,
|
||||
m2: None,
|
||||
a1: 0,
|
||||
|
|
@ -147,52 +131,29 @@ fn main() {
|
|||
d: 0,
|
||||
};
|
||||
assert_eq!(e, e);
|
||||
let e: TupleStruct<
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
> = TupleStruct(
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
PrivateStruct(0),
|
||||
0,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
);
|
||||
assert_eq!(e, e);
|
||||
let e: TupleStruct<i32, i32, i32> =
|
||||
TupleStruct(0, None, 0, PrivateStruct(0), 0, 0, None, 0, None, 0, 0, None, 0, None, 0);
|
||||
assert_eq!(e, e);
|
||||
|
||||
let e: Struct<
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
> = Struct {
|
||||
m1: 0,
|
||||
m2: None,
|
||||
a1: 0,
|
||||
a2: PrivateStruct(0),
|
||||
b: 0,
|
||||
b1: 0,
|
||||
b2: None,
|
||||
b3: 0,
|
||||
b4: None,
|
||||
c: 0,
|
||||
c1: 0,
|
||||
c2: None,
|
||||
c3: 0,
|
||||
c4: None,
|
||||
d: 0,
|
||||
};
|
||||
assert_eq!(e, e);
|
||||
let e: Struct<i32, i32, i32> = Struct {
|
||||
m1: 0,
|
||||
m2: None,
|
||||
a1: 0,
|
||||
a2: PrivateStruct(0),
|
||||
b: 0,
|
||||
b1: 0,
|
||||
b2: None,
|
||||
b3: 0,
|
||||
b4: None,
|
||||
c: 0,
|
||||
c1: 0,
|
||||
c2: None,
|
||||
c3: 0,
|
||||
c4: None,
|
||||
d: 0,
|
||||
};
|
||||
assert_eq!(e, e);
|
||||
|
||||
let e = Enum::Unit::<i32, i32, i32>;
|
||||
assert_eq!(e, e);
|
||||
let e = Enum::Unit::<i32, i32, i32>;
|
||||
assert_eq!(e, e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,58 +1,90 @@
|
|||
#![feature(allocator_api, slice_ptr_get)]
|
||||
|
||||
use std::alloc::{Allocator, Global, Layout, System};
|
||||
use std::ptr::NonNull;
|
||||
use std::alloc::{Global, Allocator, Layout, System};
|
||||
use std::slice;
|
||||
|
||||
fn check_alloc<T: Allocator>(allocator: T) { unsafe {
|
||||
for &align in &[4, 8, 16, 32] {
|
||||
let layout_20 = Layout::from_size_align(20, align).unwrap();
|
||||
let layout_40 = Layout::from_size_align(40, 4*align).unwrap();
|
||||
let layout_10 = Layout::from_size_align(10, align/2).unwrap();
|
||||
fn check_alloc<T: Allocator>(allocator: T) {
|
||||
unsafe {
|
||||
for &align in &[4, 8, 16, 32] {
|
||||
let layout_20 = Layout::from_size_align(20, align).unwrap();
|
||||
let layout_40 = Layout::from_size_align(40, 4 * align).unwrap();
|
||||
let layout_10 = Layout::from_size_align(10, align / 2).unwrap();
|
||||
|
||||
for _ in 0..32 {
|
||||
let a = allocator.allocate(layout_20).unwrap().as_non_null_ptr();
|
||||
assert_eq!(a.as_ptr() as usize % layout_20.align(), 0, "pointer is incorrectly aligned");
|
||||
allocator.deallocate(a, layout_20);
|
||||
for _ in 0..32 {
|
||||
let a = allocator.allocate(layout_20).unwrap().as_non_null_ptr();
|
||||
assert_eq!(
|
||||
a.as_ptr() as usize % layout_20.align(),
|
||||
0,
|
||||
"pointer is incorrectly aligned"
|
||||
);
|
||||
allocator.deallocate(a, layout_20);
|
||||
}
|
||||
|
||||
let p1 = allocator.allocate_zeroed(layout_20).unwrap().as_non_null_ptr();
|
||||
assert_eq!(
|
||||
p1.as_ptr() as usize % layout_20.align(),
|
||||
0,
|
||||
"pointer is incorrectly aligned"
|
||||
);
|
||||
assert_eq!(*p1.as_ptr(), 0);
|
||||
|
||||
// old size < new size
|
||||
let p2 = allocator.grow(p1, layout_20, layout_40).unwrap().as_non_null_ptr();
|
||||
assert_eq!(
|
||||
p2.as_ptr() as usize % layout_40.align(),
|
||||
0,
|
||||
"pointer is incorrectly aligned"
|
||||
);
|
||||
let slice = slice::from_raw_parts(p2.as_ptr(), 20);
|
||||
assert_eq!(&slice, &[0_u8; 20]);
|
||||
|
||||
// old size == new size
|
||||
let p3 = allocator.grow(p2, layout_40, layout_40).unwrap().as_non_null_ptr();
|
||||
assert_eq!(
|
||||
p3.as_ptr() as usize % layout_40.align(),
|
||||
0,
|
||||
"pointer is incorrectly aligned"
|
||||
);
|
||||
let slice = slice::from_raw_parts(p3.as_ptr(), 20);
|
||||
assert_eq!(&slice, &[0_u8; 20]);
|
||||
|
||||
// old size > new size
|
||||
let p4 = allocator.shrink(p3, layout_40, layout_10).unwrap().as_non_null_ptr();
|
||||
assert_eq!(
|
||||
p4.as_ptr() as usize % layout_10.align(),
|
||||
0,
|
||||
"pointer is incorrectly aligned"
|
||||
);
|
||||
let slice = slice::from_raw_parts(p4.as_ptr(), 10);
|
||||
assert_eq!(&slice, &[0_u8; 10]);
|
||||
|
||||
allocator.deallocate(p4, layout_10);
|
||||
}
|
||||
|
||||
let p1 = allocator.allocate_zeroed(layout_20).unwrap().as_non_null_ptr();
|
||||
assert_eq!(p1.as_ptr() as usize % layout_20.align(), 0, "pointer is incorrectly aligned");
|
||||
assert_eq!(*p1.as_ptr(), 0);
|
||||
|
||||
// old size < new size
|
||||
let p2 = allocator.grow(p1, layout_20, layout_40).unwrap().as_non_null_ptr();
|
||||
assert_eq!(p2.as_ptr() as usize % layout_40.align(), 0, "pointer is incorrectly aligned");
|
||||
let slice = slice::from_raw_parts(p2.as_ptr(), 20);
|
||||
assert_eq!(&slice, &[0_u8; 20]);
|
||||
|
||||
// old size == new size
|
||||
let p3 = allocator.grow(p2, layout_40, layout_40).unwrap().as_non_null_ptr();
|
||||
assert_eq!(p3.as_ptr() as usize % layout_40.align(), 0, "pointer is incorrectly aligned");
|
||||
let slice = slice::from_raw_parts(p3.as_ptr(), 20);
|
||||
assert_eq!(&slice, &[0_u8; 20]);
|
||||
|
||||
// old size > new size
|
||||
let p4 = allocator.shrink(p3, layout_40, layout_10).unwrap().as_non_null_ptr();
|
||||
assert_eq!(p4.as_ptr() as usize % layout_10.align(), 0, "pointer is incorrectly aligned");
|
||||
let slice = slice::from_raw_parts(p4.as_ptr(), 10);
|
||||
assert_eq!(&slice, &[0_u8; 10]);
|
||||
|
||||
allocator.deallocate(p4, layout_10);
|
||||
}
|
||||
} }
|
||||
}
|
||||
|
||||
fn check_align_requests<T: Allocator>(allocator: T) {
|
||||
for &size in &[2, 8, 64] { // size less than and bigger than alignment
|
||||
for &align in &[4, 8, 16, 32] { // Be sure to cover less than and bigger than `MIN_ALIGN` for all architectures
|
||||
for &size in &[2, 8, 64] {
|
||||
// size less than and bigger than alignment
|
||||
for &align in &[4, 8, 16, 32] {
|
||||
// Be sure to cover less than and bigger than `MIN_ALIGN` for all architectures
|
||||
let iterations = 32;
|
||||
unsafe {
|
||||
let pointers: Vec<_> = (0..iterations).map(|_| {
|
||||
allocator.allocate(Layout::from_size_align(size, align).unwrap()).unwrap().as_non_null_ptr()
|
||||
}).collect();
|
||||
let pointers: Vec<_> = (0..iterations)
|
||||
.map(|_| {
|
||||
allocator
|
||||
.allocate(Layout::from_size_align(size, align).unwrap())
|
||||
.unwrap()
|
||||
.as_non_null_ptr()
|
||||
})
|
||||
.collect();
|
||||
for &ptr in &pointers {
|
||||
assert_eq!((ptr.as_ptr() as usize) % align, 0,
|
||||
"Got a pointer less aligned than requested")
|
||||
assert_eq!(
|
||||
(ptr.as_ptr() as usize) % align,
|
||||
0,
|
||||
"Got a pointer less aligned than requested"
|
||||
)
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
fn iter_empty_and_zst() {
|
||||
for _ in Vec::<u32>::new().iter() { // this iterates over a Unique::empty()
|
||||
for _ in Vec::<u32>::new().iter() {
|
||||
// this iterates over a Unique::empty()
|
||||
panic!("We should never be here.");
|
||||
}
|
||||
|
||||
|
|
@ -21,13 +22,13 @@ fn test_iterator_step_by_nth() {
|
|||
}
|
||||
|
||||
fn iter_any() {
|
||||
let f = |x: &u8| { 10u8 == *x };
|
||||
let f = |x: &u8| 10u8 == *x;
|
||||
f(&1u8);
|
||||
|
||||
let g = |(), x: &u8| { 10u8 == *x };
|
||||
let g = |(), x: &u8| 10u8 == *x;
|
||||
g((), &1u8);
|
||||
|
||||
let h = |(), (), x: &u8| { 10u8 == *x };
|
||||
let h = |(), (), x: &u8| 10u8 == *x;
|
||||
h((), (), &1u8);
|
||||
|
||||
[1, 2, 3u8].iter().any(|elt| 10 == *elt);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue