5555
5656#![ stable( feature = "rust1" , since = "1.0.0" ) ]
5757
58- use heap:: Heap ;
5958use raw_vec:: RawVec ;
6059
6160use core:: any:: Any ;
6261use core:: borrow;
6362use core:: cmp:: Ordering ;
6463use core:: fmt;
6564use core:: hash:: { Hash , Hasher } ;
66- use core:: heap:: { Alloc , Layout } ;
6765use core:: iter:: FusedIterator ;
68- use core:: marker:: { self , Unpin , Unsize } ;
66+ use core:: marker:: { Unpin , Unsize } ;
6967use core:: mem:: { self , Pin } ;
7068use core:: ops:: { CoerceUnsized , Deref , DerefMut , Generator , GeneratorState } ;
71- use core:: ops:: { BoxPlace , Boxed , InPlace , Place , Placer } ;
7269use core:: ptr:: { self , NonNull , Unique } ;
7370use core:: convert:: From ;
7471use str:: from_boxed_utf8_unchecked;
7572
76- /// A value that represents the heap. This is the default place that the `box`
77- /// keyword allocates into when no place is supplied.
78- ///
79- /// The following two examples are equivalent:
80- ///
81- /// ```
82- /// #![feature(box_heap)]
83- ///
84- /// #![feature(box_syntax, placement_in_syntax)]
85- /// use std::boxed::HEAP;
86- ///
87- /// fn main() {
88- /// let foo: Box<i32> = in HEAP { 5 };
89- /// let foo = box 5;
90- /// }
91- /// ```
92- #[ unstable( feature = "box_heap" ,
93- reason = "may be renamed; uncertain about custom allocator design" ,
94- issue = "27779" ) ]
95- pub const HEAP : ExchangeHeapSingleton = ExchangeHeapSingleton { _force_singleton : ( ) } ;
96-
97- /// This the singleton type used solely for `boxed::HEAP`.
98- #[ unstable( feature = "box_heap" ,
99- reason = "may be renamed; uncertain about custom allocator design" ,
100- issue = "27779" ) ]
101- #[ allow( missing_debug_implementations) ]
102- #[ derive( Copy , Clone ) ]
103- pub struct ExchangeHeapSingleton {
104- _force_singleton : ( ) ,
105- }
106-
10773/// A pointer type for heap allocation.
10874///
10975/// See the [module-level documentation](../../std/boxed/index.html) for more.
@@ -112,121 +78,6 @@ pub struct ExchangeHeapSingleton {
11278#[ stable( feature = "rust1" , since = "1.0.0" ) ]
11379pub struct Box < T : ?Sized > ( Unique < T > ) ;
11480
115- /// `IntermediateBox` represents uninitialized backing storage for `Box`.
116- ///
117- /// FIXME (pnkfelix): Ideally we would just reuse `Box<T>` instead of
118- /// introducing a separate `IntermediateBox<T>`; but then you hit
119- /// issues when you e.g. attempt to destructure an instance of `Box`,
120- /// since it is a lang item and so it gets special handling by the
121- /// compiler. Easier just to make this parallel type for now.
122- ///
123- /// FIXME (pnkfelix): Currently the `box` protocol only supports
124- /// creating instances of sized types. This IntermediateBox is
125- /// designed to be forward-compatible with a future protocol that
126- /// supports creating instances of unsized types; that is why the type
127- /// parameter has the `?Sized` generalization marker, and is also why
128- /// this carries an explicit size. However, it probably does not need
129- /// to carry the explicit alignment; that is just a work-around for
130- /// the fact that the `align_of` intrinsic currently requires the
131- /// input type to be Sized (which I do not think is strictly
132- /// necessary).
133- #[ unstable( feature = "placement_in" ,
134- reason = "placement box design is still being worked out." ,
135- issue = "27779" ) ]
136- #[ allow( missing_debug_implementations) ]
137- pub struct IntermediateBox < T : ?Sized > {
138- ptr : * mut u8 ,
139- layout : Layout ,
140- marker : marker:: PhantomData < * mut T > ,
141- }
142-
143- #[ unstable( feature = "placement_in" ,
144- reason = "placement box design is still being worked out." ,
145- issue = "27779" ) ]
146- unsafe impl < T > Place < T > for IntermediateBox < T > {
147- fn pointer ( & mut self ) -> * mut T {
148- self . ptr as * mut T
149- }
150- }
151-
152- unsafe fn finalize < T > ( b : IntermediateBox < T > ) -> Box < T > {
153- let p = b. ptr as * mut T ;
154- mem:: forget ( b) ;
155- Box :: from_raw ( p)
156- }
157-
158- fn make_place < T > ( ) -> IntermediateBox < T > {
159- let layout = Layout :: new :: < T > ( ) ;
160-
161- let p = if layout. size ( ) == 0 {
162- mem:: align_of :: < T > ( ) as * mut u8
163- } else {
164- unsafe {
165- Heap . alloc ( layout. clone ( ) ) . unwrap_or_else ( |err| {
166- Heap . oom ( err)
167- } )
168- }
169- } ;
170-
171- IntermediateBox {
172- ptr : p,
173- layout,
174- marker : marker:: PhantomData ,
175- }
176- }
177-
178- #[ unstable( feature = "placement_in" ,
179- reason = "placement box design is still being worked out." ,
180- issue = "27779" ) ]
181- impl < T > BoxPlace < T > for IntermediateBox < T > {
182- fn make_place ( ) -> IntermediateBox < T > {
183- make_place ( )
184- }
185- }
186-
187- #[ unstable( feature = "placement_in" ,
188- reason = "placement box design is still being worked out." ,
189- issue = "27779" ) ]
190- impl < T > InPlace < T > for IntermediateBox < T > {
191- type Owner = Box < T > ;
192- unsafe fn finalize ( self ) -> Box < T > {
193- finalize ( self )
194- }
195- }
196-
197- #[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
198- impl < T > Boxed for Box < T > {
199- type Data = T ;
200- type Place = IntermediateBox < T > ;
201- unsafe fn finalize ( b : IntermediateBox < T > ) -> Box < T > {
202- finalize ( b)
203- }
204- }
205-
206- #[ unstable( feature = "placement_in" ,
207- reason = "placement box design is still being worked out." ,
208- issue = "27779" ) ]
209- impl < T > Placer < T > for ExchangeHeapSingleton {
210- type Place = IntermediateBox < T > ;
211-
212- fn make_place ( self ) -> IntermediateBox < T > {
213- make_place ( )
214- }
215- }
216-
217- #[ unstable( feature = "placement_in" ,
218- reason = "placement box design is still being worked out." ,
219- issue = "27779" ) ]
220- impl < T : ?Sized > Drop for IntermediateBox < T > {
221- fn drop ( & mut self ) {
222- if self . layout . size ( ) > 0 {
223- unsafe {
224- Heap . dealloc ( self . ptr , self . layout . clone ( ) )
225- }
226- }
227- }
228- }
229-
23081impl < T > Box < T > {
23182 /// Allocates memory on the heap and then places `x` into it.
23283 ///
0 commit comments