Skip to content

Commit cd132f5

Browse files
committed
port compile-fail allocator tests to stable API
1 parent 033eae5 commit cd132f5

File tree

6 files changed

+21
-51
lines changed

6 files changed

+21
-51
lines changed
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
#![feature(allocator_api)]
2-
3-
extern crate alloc;
4-
5-
use alloc::alloc::Global;
6-
use std::alloc::{AllocRef, Layout};
1+
use std::alloc::{alloc, dealloc, realloc, Layout};
72

83
// error-pattern: allocation has size 1 and alignment 1, but gave size 1 and alignment 2
94

105
fn main() {
116
unsafe {
12-
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
13-
Global.dealloc(x, Layout::from_size_align_unchecked(1, 2));
7+
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8+
dealloc(x, Layout::from_size_align_unchecked(1, 2));
149
}
1510
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
#![feature(allocator_api)]
2-
3-
extern crate alloc;
4-
5-
use alloc::alloc::Global;
6-
use std::alloc::{AllocRef, Layout};
1+
use std::alloc::{alloc, dealloc, realloc, Layout};
72

83
// error-pattern: allocation has size 1 and alignment 1, but gave size 2 and alignment 1
94

105
fn main() {
116
unsafe {
12-
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
13-
Global.dealloc(x, Layout::from_size_align_unchecked(2, 1));
7+
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8+
dealloc(x, Layout::from_size_align_unchecked(2, 1));
149
}
1510
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
#![feature(allocator_api)]
2-
3-
extern crate alloc;
4-
5-
use alloc::alloc::Global;
6-
use std::alloc::{AllocRef, Layout};
1+
use std::alloc::{alloc, dealloc, realloc, Layout};
72

83
// error-pattern: dereferenced after this allocation got freed
94

105
fn main() {
116
unsafe {
12-
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
13-
Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
14-
Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
7+
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8+
dealloc(x, Layout::from_size_align_unchecked(1, 1));
9+
dealloc(x, Layout::from_size_align_unchecked(1, 1));
1510
}
1611
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
#![feature(allocator_api)]
2-
3-
extern crate alloc;
4-
5-
use alloc::alloc::Global;
6-
use std::alloc::{AllocRef, Layout};
1+
use std::alloc::{alloc, dealloc, realloc, Layout};
72

83
// error-pattern: allocation has size 1 and alignment 1, but gave size 2 and alignment 1
94

105
fn main() {
116
unsafe {
12-
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
13-
Global.realloc(x, Layout::from_size_align_unchecked(2, 1), 1).unwrap();
7+
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8+
realloc(x, Layout::from_size_align_unchecked(2, 1), 1);
149
}
1510
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
#![feature(allocator_api)]
2-
3-
extern crate alloc;
4-
5-
use alloc::alloc::Global;
6-
use std::alloc::{AllocRef, Layout};
1+
use std::alloc::{alloc, dealloc, realloc, Layout};
72

83
fn main() {
94
unsafe {
10-
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
11-
Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
12-
let _z = *(x.as_ptr() as *mut u8); //~ ERROR dereferenced after this allocation got freed
5+
let x = alloc(Layout::from_size_align_unchecked(1, 1));
6+
realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
7+
let _z = *x; //~ ERROR dereferenced after this allocation got freed
138
}
149
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
#![feature(allocator_api)]
2-
3-
extern crate alloc;
4-
5-
use alloc::alloc::Global;
6-
use std::alloc::{AllocRef, Layout};
1+
use std::alloc::{alloc, dealloc, realloc, Layout};
72

83
// error-pattern: dereferenced after this allocation got freed
94

105
fn main() {
116
unsafe {
12-
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap().0;
13-
Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
14-
Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
7+
let x = alloc(Layout::from_size_align_unchecked(1, 1));
8+
dealloc(x, Layout::from_size_align_unchecked(1, 1));
9+
realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
1510
}
1611
}

0 commit comments

Comments
 (0)