Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test unstable Alloc param on Box
  • Loading branch information
Avi-D-coder committed Jul 13, 2020
commit 5c9b5bf121c212f38fc4d2945afb423443e9d24a
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![crate_type = "lib"]
#![feature(staged_api)]

#![stable(feature = "stable_test_feature", since = "1.0.0")]

#[stable(feature = "stable_test_feature", since = "1.0.0")]
Expand Down Expand Up @@ -75,3 +74,38 @@ pub const STRUCT4: Struct4 = Struct4 { field: 1 };

#[stable(feature = "stable_test_feature", since = "1.0.0")]
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 {} }
}
}
6 changes: 6 additions & 0 deletions src/test/ui/stability-attribute/generics-default-stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ fn main() {

let _: Struct6<isize> = Struct6 { field: 1 }; // 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ LL | let _: Struct5<isize> = Struct5 { field: 0 };
|
= 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
--> $DIR/generics-default-stability.rs:84:39
|
Expand All @@ -192,6 +200,6 @@ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test
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`.