150
150
mod arith;
151
151
mod bit;
152
152
mod function;
153
+ mod place;
153
154
mod range;
154
155
155
156
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
156
157
pub use self :: arith:: { Add , Sub , Mul , Div , Rem , Neg } ;
157
-
158
158
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
159
159
pub use self :: arith:: { AddAssign , SubAssign , MulAssign , DivAssign , RemAssign } ;
160
160
161
161
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
162
162
pub use self :: bit:: { Not , BitAnd , BitOr , BitXor , Shl , Shr } ;
163
-
164
163
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
165
164
pub use self :: bit:: { BitAndAssign , BitOrAssign , BitXorAssign , ShlAssign , ShrAssign } ;
166
165
@@ -173,6 +172,9 @@ pub use self::range::{Range, RangeFrom, RangeFull, RangeTo};
173
172
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
174
173
pub use self :: range:: { RangeInclusive , RangeToInclusive } ;
175
174
175
+ #[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
176
+ pub use self :: place:: { Place , Placer , InPlace , Boxed , BoxPlace } ;
177
+
176
178
use marker:: Unsize ;
177
179
178
180
/// The `Drop` trait is used to run some code when a value goes out of scope.
@@ -592,123 +594,6 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
592
594
#[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
593
595
impl < T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * const U > for * const T { }
594
596
595
- /// Both `PLACE <- EXPR` and `box EXPR` desugar into expressions
596
- /// that allocate an intermediate "place" that holds uninitialized
597
- /// state. The desugaring evaluates EXPR, and writes the result at
598
- /// the address returned by the `pointer` method of this trait.
599
- ///
600
- /// A `Place` can be thought of as a special representation for a
601
- /// hypothetical `&uninit` reference (which Rust cannot currently
602
- /// express directly). That is, it represents a pointer to
603
- /// uninitialized storage.
604
- ///
605
- /// The client is responsible for two steps: First, initializing the
606
- /// payload (it can access its address via `pointer`). Second,
607
- /// converting the agent to an instance of the owning pointer, via the
608
- /// appropriate `finalize` method (see the `InPlace`.
609
- ///
610
- /// If evaluating EXPR fails, then it is up to the destructor for the
611
- /// implementation of Place to clean up any intermediate state
612
- /// (e.g. deallocate box storage, pop a stack, etc).
613
- #[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
614
- pub trait Place < Data : ?Sized > {
615
- /// Returns the address where the input value will be written.
616
- /// Note that the data at this address is generally uninitialized,
617
- /// and thus one should use `ptr::write` for initializing it.
618
- fn pointer ( & mut self ) -> * mut Data ;
619
- }
620
-
621
- /// Interface to implementations of `PLACE <- EXPR`.
622
- ///
623
- /// `PLACE <- EXPR` effectively desugars into:
624
- ///
625
- /// ```rust,ignore
626
- /// let p = PLACE;
627
- /// let mut place = Placer::make_place(p);
628
- /// let raw_place = Place::pointer(&mut place);
629
- /// let value = EXPR;
630
- /// unsafe {
631
- /// std::ptr::write(raw_place, value);
632
- /// InPlace::finalize(place)
633
- /// }
634
- /// ```
635
- ///
636
- /// The type of `PLACE <- EXPR` is derived from the type of `PLACE`;
637
- /// if the type of `PLACE` is `P`, then the final type of the whole
638
- /// expression is `P::Place::Owner` (see the `InPlace` and `Boxed`
639
- /// traits).
640
- ///
641
- /// Values for types implementing this trait usually are transient
642
- /// intermediate values (e.g. the return value of `Vec::emplace_back`)
643
- /// or `Copy`, since the `make_place` method takes `self` by value.
644
- #[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
645
- pub trait Placer < Data : ?Sized > {
646
- /// `Place` is the intermedate agent guarding the
647
- /// uninitialized state for `Data`.
648
- type Place : InPlace < Data > ;
649
-
650
- /// Creates a fresh place from `self`.
651
- fn make_place ( self ) -> Self :: Place ;
652
- }
653
-
654
- /// Specialization of `Place` trait supporting `PLACE <- EXPR`.
655
- #[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
656
- pub trait InPlace < Data : ?Sized > : Place < Data > {
657
- /// `Owner` is the type of the end value of `PLACE <- EXPR`
658
- ///
659
- /// Note that when `PLACE <- EXPR` is solely used for
660
- /// side-effecting an existing data-structure,
661
- /// e.g. `Vec::emplace_back`, then `Owner` need not carry any
662
- /// information at all (e.g. it can be the unit type `()` in that
663
- /// case).
664
- type Owner ;
665
-
666
- /// Converts self into the final value, shifting
667
- /// deallocation/cleanup responsibilities (if any remain), over to
668
- /// the returned instance of `Owner` and forgetting self.
669
- unsafe fn finalize ( self ) -> Self :: Owner ;
670
- }
671
-
672
- /// Core trait for the `box EXPR` form.
673
- ///
674
- /// `box EXPR` effectively desugars into:
675
- ///
676
- /// ```rust,ignore
677
- /// let mut place = BoxPlace::make_place();
678
- /// let raw_place = Place::pointer(&mut place);
679
- /// let value = EXPR;
680
- /// unsafe {
681
- /// ::std::ptr::write(raw_place, value);
682
- /// Boxed::finalize(place)
683
- /// }
684
- /// ```
685
- ///
686
- /// The type of `box EXPR` is supplied from its surrounding
687
- /// context; in the above expansion, the result type `T` is used
688
- /// to determine which implementation of `Boxed` to use, and that
689
- /// `<T as Boxed>` in turn dictates determines which
690
- /// implementation of `BoxPlace` to use, namely:
691
- /// `<<T as Boxed>::Place as BoxPlace>`.
692
- #[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
693
- pub trait Boxed {
694
- /// The kind of data that is stored in this kind of box.
695
- type Data ; /* (`Data` unused b/c cannot yet express below bound.) */
696
- /// The place that will negotiate the storage of the data.
697
- type Place : BoxPlace < Self :: Data > ;
698
-
699
- /// Converts filled place into final owning value, shifting
700
- /// deallocation/cleanup responsibilities (if any remain), over to
701
- /// returned instance of `Self` and forgetting `filled`.
702
- unsafe fn finalize ( filled : Self :: Place ) -> Self ;
703
- }
704
-
705
- /// Specialization of `Place` trait supporting `box EXPR`.
706
- #[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
707
- pub trait BoxPlace < Data : ?Sized > : Place < Data > {
708
- /// Creates a globally fresh place.
709
- fn make_place ( ) -> Self ;
710
- }
711
-
712
597
/// This trait has been superseded by the `Try` trait, but must remain
713
598
/// here as `?` is still lowered to it in stage0 .
714
599
#[ cfg( stage0) ]
0 commit comments