Skip to content

Commit 6b17699

Browse files
committed
make box-alloc test even harder
1 parent 56b720e commit 6b17699

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/pass/issue-95453.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![feature(allocator_api)]
1+
#![allow(incomplete_features)] // for triat upcasting
2+
#![feature(allocator_api, trait_upcasting)]
23

34
use std::alloc::{AllocError, Allocator};
45
use std::alloc::Layout;
@@ -37,6 +38,10 @@ impl MyTrait for [u8; 1] {
3738
}
3839
}
3940

41+
trait TheTrait: MyTrait {}
42+
43+
impl TheTrait for [u8; 1] {}
44+
4045
/// `Box<T, G>` is a `ScalarPair` where the 2nd component is the allocator.
4146
fn test1() {
4247
let mut space = vec![MaybeUninit::new(0); 1];
@@ -46,6 +51,10 @@ fn test1() {
4651

4752
let boxed = Box::new_in([42u8; 1], &once_alloc);
4853
let _val = *boxed;
54+
let with_dyn: Box<dyn TheTrait, &OnceAlloc> = boxed;
55+
assert_eq!(42, with_dyn.hello());
56+
let with_dyn: Box<dyn MyTrait, &OnceAlloc> = with_dyn; // upcast
57+
assert_eq!(42, with_dyn.hello());
4958
}
5059

5160
// Make the allocator itself so big that the Box is not even a ScalarPair any more.
@@ -70,6 +79,10 @@ fn test2() {
7079

7180
let boxed = Box::new_in([0u8; 1], OnceAllocRef(&once_alloc, 0));
7281
let _val = *boxed;
82+
let with_dyn: Box<dyn TheTrait, OnceAllocRef> = boxed;
83+
assert_eq!(42, with_dyn.hello());
84+
let with_dyn: Box<dyn MyTrait, OnceAllocRef> = with_dyn; // upcast
85+
assert_eq!(42, with_dyn.hello());
7386
}
7487

7588
fn main() {

0 commit comments

Comments
 (0)