Skip to content

fallible allocator experiment #111970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
pitaj committed Jun 6, 2023
commit 0e723c3cc7a1aee7d6105dee9ebc1305157df2dd
13 changes: 2 additions & 11 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::assert_eq;
use core::iter::IntoIterator;
use core::num::NonZeroUsize;
use core::ptr::NonNull;
use std::alloc::{Allocator, Layout, System, FallibleAdapter, IntoLayout, handle_alloc_error};
use std::alloc::{Allocator, Layout, System, Fatal};
use std::assert_matches::assert_matches;
use std::borrow::Cow;
use std::cell::Cell;
Expand Down Expand Up @@ -1096,16 +1096,7 @@ fn test_into_iter_drop_allocator() {
unsafe { System.deallocate(ptr, layout) }
}

type Result<T, E: std::error::Error> = T
where
E: IntoLayout;

fn map_result<T, E: std::error::Error>(result: Result<T, E>) -> Self::Result<T, E>
where
E: IntoLayout
{
result.unwrap_or_else(|e| handle_alloc_error(e.into_layout()))
}
type ErrorHandling = Fatal;
}

let mut drop_count = 0;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/allocator/object-safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#![feature(allocator_api)]

use std::alloc::{Allocator, System};
use std::alloc::{Allocator, System, Fatal};

fn ensure_object_safe(_: &dyn Allocator) {}
fn ensure_object_safe(_: &dyn Allocator<ErrorHandling = Fatal>) {}

fn main() {
ensure_object_safe(&System);
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/box/large-allocator-ice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(allocator_api)]
#![allow(unused_must_use)]

use std::alloc::Allocator;
use std::alloc::{Allocator, Fatal};

struct BigAllocator([usize; 2]);

Expand All @@ -16,6 +16,7 @@ unsafe impl Allocator for BigAllocator {
unsafe fn deallocate(&self, _: std::ptr::NonNull<u8>, _: std::alloc::Layout) {
todo!()
}
type ErrorHandling = Fatal;
}

fn main() {
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/box/leak-alloc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(allocator_api)]

use std::alloc::{AllocError, Allocator, Layout, System};
use std::alloc::{AllocError, Allocator, Layout, System, Fatal};
use std::ptr::NonNull;

use std::boxed::Box;
Expand All @@ -15,6 +15,8 @@ unsafe impl Allocator for Alloc {
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
System.deallocate(ptr, layout)
}

type ErrorHandling = Fatal;
}

fn use_value(_: u32) {}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/box/leak-alloc.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0505]: cannot move out of `alloc` because it is borrowed
--> $DIR/leak-alloc.rs:26:10
--> $DIR/leak-alloc.rs:28:10
|
LL | let alloc = Alloc {};
| ----- binding `alloc` declared here
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/debuginfo/debuginfo-box-with-large-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![feature(allocator_api)]

use std::alloc::{AllocError, Allocator, Layout};
use std::alloc::{AllocError, Allocator, Layout, Fatal};
use std::ptr::NonNull;

struct ZST;
Expand All @@ -16,6 +16,7 @@ unsafe impl Allocator for &ZST {
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
todo!()
}
type ErrorHandling = Fatal;
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0401.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ LL | bfnr(x);
- impl<A, F> Fn<A> for &F
where A: Tuple, F: Fn<A>, F: ?Sized;
- impl<Args, F, A> Fn<Args> for Box<F, A>
where Args: Tuple, F: Fn<Args>, A: alloc::falloc::Allocator, F: ?Sized;
where Args: Tuple, F: Fn<Args>, A: Allocator, F: ?Sized;
note: required by a bound in `bfnr`
--> $DIR/E0401.rs:4:30
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/e0119/conflict-with-std.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | impl AsRef<Q> for Box<Q> {
|
= note: conflicting implementation in crate `alloc`:
- impl<T, A> AsRef<T> for Box<T, A>
where A: alloc::falloc::Allocator, T: ?Sized;
where A: Allocator, T: ?Sized;

error[E0119]: conflicting implementations of trait `From<S>` for type `S`
--> $DIR/conflict-with-std.rs:12:1
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/hygiene/panic-location.run.stderr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
thread 'main' panicked at 'capacity overflow', library/alloc/src/falloc.rs:94:5
thread 'main' panicked at 'capacity overflow', library/alloc/src/falloc.rs:518:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace