Test unstable Alloc param on Box

This commit is contained in:
Avi Dessauer 2020-07-12 20:56:37 -04:00 committed by Jacob Hughes
parent 7616b30bff
commit a73e7d0a4d
3 changed files with 50 additions and 2 deletions

View File

@ -1,6 +1,5 @@
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(staged_api)] #![feature(staged_api)]
#![stable(feature = "stable_test_feature", since = "1.0.0")] #![stable(feature = "stable_test_feature", since = "1.0.0")]
#[stable(feature = "stable_test_feature", since = "1.0.0")] #[stable(feature = "stable_test_feature", since = "1.0.0")]
@ -75,3 +74,38 @@ pub const STRUCT4: Struct4 = Struct4 { field: 1 };
#[stable(feature = "stable_test_feature", since = "1.0.0")] #[stable(feature = "stable_test_feature", since = "1.0.0")]
pub const STRUCT5: Struct5 = Struct5 { field: 1 }; pub const STRUCT5: Struct5 = Struct5 { field: 1 };
#[stable(feature = "stable_test_feature", since = "1.0.0")]
pub trait Alloc {}
#[stable(feature = "stable_test_feature", since = "1.0.0")]
pub struct System {}
#[stable(feature = "stable_test_feature", since = "1.0.0")]
impl Alloc for System {}
#[stable(feature = "stable_test_feature", since = "1.0.0")]
pub struct Box1<T, #[unstable(feature = "box_alloc_param", issue = "none")] A: Alloc = System> {
ptr: *mut T,
alloc: A,
}
impl<T> Box1<T, System> {
#[stable(feature = "stable_test_feature", since = "1.0.0")]
pub fn new(mut t: T) -> Self {
unsafe { Self { ptr: &mut t, alloc: System {} } }
}
}
#[stable(feature = "stable_test_feature", since = "1.0.0")]
pub struct Box2<T, A: Alloc = System> {
ptr: *mut T,
alloc: A,
}
impl<T> Box2<T, System> {
#[stable(feature = "stable_test_feature", since = "1.0.0")]
pub fn new(mut t: T) -> Self {
Self { ptr: &mut t, alloc: System {} }
}
}

View File

@ -109,4 +109,10 @@ fn main() {
let _: Struct6<isize> = Struct6 { field: 1 }; // ok let _: Struct6<isize> = Struct6 { field: 1 }; // ok
let _: Struct6<isize> = Struct6 { field: 0 }; // ok let _: Struct6<isize> = Struct6 { field: 0 }; // ok
let _: Box1<isize, System> = Box1::new(1); //~ ERROR use of unstable library feature 'box_alloc_param'
let _: Box1<isize> = Box1::new(1); // ok
let _: Box2<isize, System> = Box2::new(1); // ok
let _: Box2<isize> = Box2::new(1); // ok
} }

View File

@ -168,6 +168,14 @@ LL | let _: Struct5<isize> = Struct5 { field: 0 };
| |
= help: add `#![feature(unstable_default)]` to the crate attributes to enable = help: add `#![feature(unstable_default)]` to the crate attributes to enable
error[E0658]: use of unstable library feature 'box_alloc_param'
--> $DIR/generics-default-stability.rs:113:24
|
LL | let _: Box1<isize, System> = Box1::new(1);
| ^^^^^^
|
= help: add `#![feature(box_alloc_param)]` to the crate attributes to enable
warning: use of deprecated item 'unstable_generic_param::Struct4::field': test warning: use of deprecated item 'unstable_generic_param::Struct4::field': test
--> $DIR/generics-default-stability.rs:84:39 --> $DIR/generics-default-stability.rs:84:39
| |
@ -192,6 +200,6 @@ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test
LL | let _: Struct5<isize> = Struct5 { field: 0 }; LL | let _: Struct5<isize> = Struct5 { field: 0 };
| ^^^^^^^^ | ^^^^^^^^
error: aborting due to 12 previous errors; 16 warnings emitted error: aborting due to 13 previous errors; 16 warnings emitted
For more information about this error, try `rustc --explain E0658`. For more information about this error, try `rustc --explain E0658`.