Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cfadb35

Browse files
author
Clar Charr
committedMay 27, 2017
Move more stuff out of markers.
1 parent 6f25280 commit cfadb35

File tree

5 files changed

+313
-311
lines changed

5 files changed

+313
-311
lines changed
 

‎src/libcore/ops/fn.rs

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/// A version of the call operator that takes an immutable receiver.
2+
///
3+
/// # Examples
4+
///
5+
/// Closures automatically implement this trait, which allows them to be
6+
/// invoked. Note, however, that `Fn` takes an immutable reference to any
7+
/// captured variables. To take a mutable capture, implement [`FnMut`], and to
8+
/// consume the capture, implement [`FnOnce`].
9+
///
10+
/// [`FnMut`]: trait.FnMut.html
11+
/// [`FnOnce`]: trait.FnOnce.html
12+
///
13+
/// ```
14+
/// let square = |x| x * x;
15+
/// assert_eq!(square(5), 25);
16+
/// ```
17+
///
18+
/// Closures can also be passed to higher-level functions through a `Fn`
19+
/// parameter (or a `FnMut` or `FnOnce` parameter, which are supertraits of
20+
/// `Fn`).
21+
///
22+
/// ```
23+
/// fn call_with_one<F>(func: F) -> usize
24+
/// where F: Fn(usize) -> usize {
25+
/// func(1)
26+
/// }
27+
///
28+
/// let double = |x| x * 2;
29+
/// assert_eq!(call_with_one(double), 2);
30+
/// ```
31+
#[lang = "fn"]
32+
#[stable(feature = "rust1", since = "1.0.0")]
33+
#[rustc_paren_sugar]
34+
#[fundamental] // so that regex can rely that `&str: !FnMut`
35+
pub trait Fn<Args> : FnMut<Args> {
36+
/// This is called when the call operator is used.
37+
#[unstable(feature = "fn_traits", issue = "29625")]
38+
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
39+
}
40+
41+
/// A version of the call operator that takes a mutable receiver.
42+
///
43+
/// # Examples
44+
///
45+
/// Closures that mutably capture variables automatically implement this trait,
46+
/// which allows them to be invoked.
47+
///
48+
/// ```
49+
/// let mut x = 5;
50+
/// {
51+
/// let mut square_x = || x *= x;
52+
/// square_x();
53+
/// }
54+
/// assert_eq!(x, 25);
55+
/// ```
56+
///
57+
/// Closures can also be passed to higher-level functions through a `FnMut`
58+
/// parameter (or a `FnOnce` parameter, which is a supertrait of `FnMut`).
59+
///
60+
/// ```
61+
/// fn do_twice<F>(mut func: F)
62+
/// where F: FnMut()
63+
/// {
64+
/// func();
65+
/// func();
66+
/// }
67+
///
68+
/// let mut x: usize = 1;
69+
/// {
70+
/// let add_two_to_x = || x += 2;
71+
/// do_twice(add_two_to_x);
72+
/// }
73+
///
74+
/// assert_eq!(x, 5);
75+
/// ```
76+
#[lang = "fn_mut"]
77+
#[stable(feature = "rust1", since = "1.0.0")]
78+
#[rustc_paren_sugar]
79+
#[fundamental] // so that regex can rely that `&str: !FnMut`
80+
pub trait FnMut<Args> : FnOnce<Args> {
81+
/// This is called when the call operator is used.
82+
#[unstable(feature = "fn_traits", issue = "29625")]
83+
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
84+
}
85+
86+
/// A version of the call operator that takes a by-value receiver.
87+
///
88+
/// # Examples
89+
///
90+
/// By-value closures automatically implement this trait, which allows them to
91+
/// be invoked.
92+
///
93+
/// ```
94+
/// let x = 5;
95+
/// let square_x = move || x * x;
96+
/// assert_eq!(square_x(), 25);
97+
/// ```
98+
///
99+
/// By-value Closures can also be passed to higher-level functions through a
100+
/// `FnOnce` parameter.
101+
///
102+
/// ```
103+
/// fn consume_with_relish<F>(func: F)
104+
/// where F: FnOnce() -> String
105+
/// {
106+
/// // `func` consumes its captured variables, so it cannot be run more
107+
/// // than once
108+
/// println!("Consumed: {}", func());
109+
///
110+
/// println!("Delicious!");
111+
///
112+
/// // Attempting to invoke `func()` again will throw a `use of moved
113+
/// // value` error for `func`
114+
/// }
115+
///
116+
/// let x = String::from("x");
117+
/// let consume_and_return_x = move || x;
118+
/// consume_with_relish(consume_and_return_x);
119+
///
120+
/// // `consume_and_return_x` can no longer be invoked at this point
121+
/// ```
122+
#[lang = "fn_once"]
123+
#[stable(feature = "rust1", since = "1.0.0")]
124+
#[rustc_paren_sugar]
125+
#[fundamental] // so that regex can rely that `&str: !FnMut`
126+
pub trait FnOnce<Args> {
127+
/// The returned type after the call operator is used.
128+
#[stable(feature = "fn_once_output", since = "1.12.0")]
129+
type Output;
130+
131+
/// This is called when the call operator is used.
132+
#[unstable(feature = "fn_traits", issue = "29625")]
133+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
134+
}
135+
136+
mod impls {
137+
#[stable(feature = "rust1", since = "1.0.0")]
138+
impl<'a,A,F:?Sized> Fn<A> for &'a F
139+
where F : Fn<A>
140+
{
141+
extern "rust-call" fn call(&self, args: A) -> F::Output {
142+
(**self).call(args)
143+
}
144+
}
145+
146+
#[stable(feature = "rust1", since = "1.0.0")]
147+
impl<'a,A,F:?Sized> FnMut<A> for &'a F
148+
where F : Fn<A>
149+
{
150+
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
151+
(**self).call(args)
152+
}
153+
}
154+
155+
#[stable(feature = "rust1", since = "1.0.0")]
156+
impl<'a,A,F:?Sized> FnOnce<A> for &'a F
157+
where F : Fn<A>
158+
{
159+
type Output = F::Output;
160+
161+
extern "rust-call" fn call_once(self, args: A) -> F::Output {
162+
(*self).call(args)
163+
}
164+
}
165+
166+
#[stable(feature = "rust1", since = "1.0.0")]
167+
impl<'a,A,F:?Sized> FnMut<A> for &'a mut F
168+
where F : FnMut<A>
169+
{
170+
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
171+
(*self).call_mut(args)
172+
}
173+
}
174+
175+
#[stable(feature = "rust1", since = "1.0.0")]
176+
impl<'a,A,F:?Sized> FnOnce<A> for &'a mut F
177+
where F : FnMut<A>
178+
{
179+
type Output = F::Output;
180+
extern "rust-call" fn call_once(mut self, args: A) -> F::Output {
181+
(*self).call_mut(args)
182+
}
183+
}
184+
}
185+
186+

‎src/libcore/ops/markers.rs

Lines changed: 0 additions & 303 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use fmt;
1211
use marker::Unsize;
1312

1413
/// The `Drop` trait is used to run some code when a value goes out of scope.
@@ -359,191 +358,6 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
359358
fn deref_mut(&mut self) -> &mut T { *self }
360359
}
361360

362-
/// A version of the call operator that takes an immutable receiver.
363-
///
364-
/// # Examples
365-
///
366-
/// Closures automatically implement this trait, which allows them to be
367-
/// invoked. Note, however, that `Fn` takes an immutable reference to any
368-
/// captured variables. To take a mutable capture, implement [`FnMut`], and to
369-
/// consume the capture, implement [`FnOnce`].
370-
///
371-
/// [`FnMut`]: trait.FnMut.html
372-
/// [`FnOnce`]: trait.FnOnce.html
373-
///
374-
/// ```
375-
/// let square = |x| x * x;
376-
/// assert_eq!(square(5), 25);
377-
/// ```
378-
///
379-
/// Closures can also be passed to higher-level functions through a `Fn`
380-
/// parameter (or a `FnMut` or `FnOnce` parameter, which are supertraits of
381-
/// `Fn`).
382-
///
383-
/// ```
384-
/// fn call_with_one<F>(func: F) -> usize
385-
/// where F: Fn(usize) -> usize {
386-
/// func(1)
387-
/// }
388-
///
389-
/// let double = |x| x * 2;
390-
/// assert_eq!(call_with_one(double), 2);
391-
/// ```
392-
#[lang = "fn"]
393-
#[stable(feature = "rust1", since = "1.0.0")]
394-
#[rustc_paren_sugar]
395-
#[fundamental] // so that regex can rely that `&str: !FnMut`
396-
pub trait Fn<Args> : FnMut<Args> {
397-
/// This is called when the call operator is used.
398-
#[unstable(feature = "fn_traits", issue = "29625")]
399-
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
400-
}
401-
402-
/// A version of the call operator that takes a mutable receiver.
403-
///
404-
/// # Examples
405-
///
406-
/// Closures that mutably capture variables automatically implement this trait,
407-
/// which allows them to be invoked.
408-
///
409-
/// ```
410-
/// let mut x = 5;
411-
/// {
412-
/// let mut square_x = || x *= x;
413-
/// square_x();
414-
/// }
415-
/// assert_eq!(x, 25);
416-
/// ```
417-
///
418-
/// Closures can also be passed to higher-level functions through a `FnMut`
419-
/// parameter (or a `FnOnce` parameter, which is a supertrait of `FnMut`).
420-
///
421-
/// ```
422-
/// fn do_twice<F>(mut func: F)
423-
/// where F: FnMut()
424-
/// {
425-
/// func();
426-
/// func();
427-
/// }
428-
///
429-
/// let mut x: usize = 1;
430-
/// {
431-
/// let add_two_to_x = || x += 2;
432-
/// do_twice(add_two_to_x);
433-
/// }
434-
///
435-
/// assert_eq!(x, 5);
436-
/// ```
437-
#[lang = "fn_mut"]
438-
#[stable(feature = "rust1", since = "1.0.0")]
439-
#[rustc_paren_sugar]
440-
#[fundamental] // so that regex can rely that `&str: !FnMut`
441-
pub trait FnMut<Args> : FnOnce<Args> {
442-
/// This is called when the call operator is used.
443-
#[unstable(feature = "fn_traits", issue = "29625")]
444-
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
445-
}
446-
447-
/// A version of the call operator that takes a by-value receiver.
448-
///
449-
/// # Examples
450-
///
451-
/// By-value closures automatically implement this trait, which allows them to
452-
/// be invoked.
453-
///
454-
/// ```
455-
/// let x = 5;
456-
/// let square_x = move || x * x;
457-
/// assert_eq!(square_x(), 25);
458-
/// ```
459-
///
460-
/// By-value Closures can also be passed to higher-level functions through a
461-
/// `FnOnce` parameter.
462-
///
463-
/// ```
464-
/// fn consume_with_relish<F>(func: F)
465-
/// where F: FnOnce() -> String
466-
/// {
467-
/// // `func` consumes its captured variables, so it cannot be run more
468-
/// // than once
469-
/// println!("Consumed: {}", func());
470-
///
471-
/// println!("Delicious!");
472-
///
473-
/// // Attempting to invoke `func()` again will throw a `use of moved
474-
/// // value` error for `func`
475-
/// }
476-
///
477-
/// let x = String::from("x");
478-
/// let consume_and_return_x = move || x;
479-
/// consume_with_relish(consume_and_return_x);
480-
///
481-
/// // `consume_and_return_x` can no longer be invoked at this point
482-
/// ```
483-
#[lang = "fn_once"]
484-
#[stable(feature = "rust1", since = "1.0.0")]
485-
#[rustc_paren_sugar]
486-
#[fundamental] // so that regex can rely that `&str: !FnMut`
487-
pub trait FnOnce<Args> {
488-
/// The returned type after the call operator is used.
489-
#[stable(feature = "fn_once_output", since = "1.12.0")]
490-
type Output;
491-
492-
/// This is called when the call operator is used.
493-
#[unstable(feature = "fn_traits", issue = "29625")]
494-
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
495-
}
496-
497-
mod impls {
498-
#[stable(feature = "rust1", since = "1.0.0")]
499-
impl<'a,A,F:?Sized> Fn<A> for &'a F
500-
where F : Fn<A>
501-
{
502-
extern "rust-call" fn call(&self, args: A) -> F::Output {
503-
(**self).call(args)
504-
}
505-
}
506-
507-
#[stable(feature = "rust1", since = "1.0.0")]
508-
impl<'a,A,F:?Sized> FnMut<A> for &'a F
509-
where F : Fn<A>
510-
{
511-
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
512-
(**self).call(args)
513-
}
514-
}
515-
516-
#[stable(feature = "rust1", since = "1.0.0")]
517-
impl<'a,A,F:?Sized> FnOnce<A> for &'a F
518-
where F : Fn<A>
519-
{
520-
type Output = F::Output;
521-
522-
extern "rust-call" fn call_once(self, args: A) -> F::Output {
523-
(*self).call(args)
524-
}
525-
}
526-
527-
#[stable(feature = "rust1", since = "1.0.0")]
528-
impl<'a,A,F:?Sized> FnMut<A> for &'a mut F
529-
where F : FnMut<A>
530-
{
531-
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
532-
(*self).call_mut(args)
533-
}
534-
}
535-
536-
#[stable(feature = "rust1", since = "1.0.0")]
537-
impl<'a,A,F:?Sized> FnOnce<A> for &'a mut F
538-
where F : FnMut<A>
539-
{
540-
type Output = F::Output;
541-
extern "rust-call" fn call_once(mut self, args: A) -> F::Output {
542-
(*self).call_mut(args)
543-
}
544-
}
545-
}
546-
547361
/// Trait that indicates that this is a pointer or a wrapper for one,
548362
/// where unsizing can be performed on the pointee.
549363
///
@@ -612,123 +426,6 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
612426
#[unstable(feature = "coerce_unsized", issue = "27732")]
613427
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
614428

615-
/// Both `PLACE <- EXPR` and `box EXPR` desugar into expressions
616-
/// that allocate an intermediate "place" that holds uninitialized
617-
/// state. The desugaring evaluates EXPR, and writes the result at
618-
/// the address returned by the `pointer` method of this trait.
619-
///
620-
/// A `Place` can be thought of as a special representation for a
621-
/// hypothetical `&uninit` reference (which Rust cannot currently
622-
/// express directly). That is, it represents a pointer to
623-
/// uninitialized storage.
624-
///
625-
/// The client is responsible for two steps: First, initializing the
626-
/// payload (it can access its address via `pointer`). Second,
627-
/// converting the agent to an instance of the owning pointer, via the
628-
/// appropriate `finalize` method (see the `InPlace`.
629-
///
630-
/// If evaluating EXPR fails, then it is up to the destructor for the
631-
/// implementation of Place to clean up any intermediate state
632-
/// (e.g. deallocate box storage, pop a stack, etc).
633-
#[unstable(feature = "placement_new_protocol", issue = "27779")]
634-
pub trait Place<Data: ?Sized> {
635-
/// Returns the address where the input value will be written.
636-
/// Note that the data at this address is generally uninitialized,
637-
/// and thus one should use `ptr::write` for initializing it.
638-
fn pointer(&mut self) -> *mut Data;
639-
}
640-
641-
/// Interface to implementations of `PLACE <- EXPR`.
642-
///
643-
/// `PLACE <- EXPR` effectively desugars into:
644-
///
645-
/// ```rust,ignore
646-
/// let p = PLACE;
647-
/// let mut place = Placer::make_place(p);
648-
/// let raw_place = Place::pointer(&mut place);
649-
/// let value = EXPR;
650-
/// unsafe {
651-
/// std::ptr::write(raw_place, value);
652-
/// InPlace::finalize(place)
653-
/// }
654-
/// ```
655-
///
656-
/// The type of `PLACE <- EXPR` is derived from the type of `PLACE`;
657-
/// if the type of `PLACE` is `P`, then the final type of the whole
658-
/// expression is `P::Place::Owner` (see the `InPlace` and `Boxed`
659-
/// traits).
660-
///
661-
/// Values for types implementing this trait usually are transient
662-
/// intermediate values (e.g. the return value of `Vec::emplace_back`)
663-
/// or `Copy`, since the `make_place` method takes `self` by value.
664-
#[unstable(feature = "placement_new_protocol", issue = "27779")]
665-
pub trait Placer<Data: ?Sized> {
666-
/// `Place` is the intermedate agent guarding the
667-
/// uninitialized state for `Data`.
668-
type Place: InPlace<Data>;
669-
670-
/// Creates a fresh place from `self`.
671-
fn make_place(self) -> Self::Place;
672-
}
673-
674-
/// Specialization of `Place` trait supporting `PLACE <- EXPR`.
675-
#[unstable(feature = "placement_new_protocol", issue = "27779")]
676-
pub trait InPlace<Data: ?Sized>: Place<Data> {
677-
/// `Owner` is the type of the end value of `PLACE <- EXPR`
678-
///
679-
/// Note that when `PLACE <- EXPR` is solely used for
680-
/// side-effecting an existing data-structure,
681-
/// e.g. `Vec::emplace_back`, then `Owner` need not carry any
682-
/// information at all (e.g. it can be the unit type `()` in that
683-
/// case).
684-
type Owner;
685-
686-
/// Converts self into the final value, shifting
687-
/// deallocation/cleanup responsibilities (if any remain), over to
688-
/// the returned instance of `Owner` and forgetting self.
689-
unsafe fn finalize(self) -> Self::Owner;
690-
}
691-
692-
/// Core trait for the `box EXPR` form.
693-
///
694-
/// `box EXPR` effectively desugars into:
695-
///
696-
/// ```rust,ignore
697-
/// let mut place = BoxPlace::make_place();
698-
/// let raw_place = Place::pointer(&mut place);
699-
/// let value = EXPR;
700-
/// unsafe {
701-
/// ::std::ptr::write(raw_place, value);
702-
/// Boxed::finalize(place)
703-
/// }
704-
/// ```
705-
///
706-
/// The type of `box EXPR` is supplied from its surrounding
707-
/// context; in the above expansion, the result type `T` is used
708-
/// to determine which implementation of `Boxed` to use, and that
709-
/// `<T as Boxed>` in turn dictates determines which
710-
/// implementation of `BoxPlace` to use, namely:
711-
/// `<<T as Boxed>::Place as BoxPlace>`.
712-
#[unstable(feature = "placement_new_protocol", issue = "27779")]
713-
pub trait Boxed {
714-
/// The kind of data that is stored in this kind of box.
715-
type Data; /* (`Data` unused b/c cannot yet express below bound.) */
716-
/// The place that will negotiate the storage of the data.
717-
type Place: BoxPlace<Self::Data>;
718-
719-
/// Converts filled place into final owning value, shifting
720-
/// deallocation/cleanup responsibilities (if any remain), over to
721-
/// returned instance of `Self` and forgetting `filled`.
722-
unsafe fn finalize(filled: Self::Place) -> Self;
723-
}
724-
725-
/// Specialization of `Place` trait supporting `box EXPR`.
726-
#[unstable(feature = "placement_new_protocol", issue = "27779")]
727-
pub trait BoxPlace<Data: ?Sized> : Place<Data> {
728-
/// Creates a globally fresh place.
729-
fn make_place() -> Self;
730-
}
731-
732429
/// A trait for types which have success and error states and are meant to work
733430
/// with the question mark operator.
734431
/// When the `?` operator is used with a value, whether the value is in the

‎src/libcore/ops/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,19 @@
147147
148148
#![stable(feature = "rust1", since = "1.0.0")]
149149

150+
mod bit;
151+
mod fn;
150152
mod markers;
153+
mod num;
154+
mod place;
155+
mod range;
151156

152-
pub use markers::{Drop, Index, IndexMut, Deref, DerefMut};
153-
pub use markers::{Fn, FnMut, FnOnce, CoerceUnsized};
154-
pub use markers::{Place, InPlace, Boxed, BoxPlace, Carrier};
155-
157+
pub use bit::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign};
158+
pub use bit::{Neg, BitAnd, BitOr, BitXor, Shl, Shr};
159+
pub use fn::{Fn, FnMut, FnOnce};
160+
pub use markers::{Drop, Index, IndexMut, Deref, DerefMut, CoerceUnsized, Carrier};
156161
pub use num::{Add, Sub, Mul, Div, Rem, Neg};
157162
pub use num::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
158-
159-
pub use bit::{Neg, BitAnd, BitOr, BitXor, Shl, Shr};
160-
pub use bit::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign};
161-
163+
pub use place::{Place, InPlace, Boxed, BoxPlace};
162164
pub use range::{RangeFull, Range, RangeFrom, RangeTo};
163165
pub use range::{RangeInclusive, RangeToInclusive};

‎src/libcore/ops/place.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/// Both `PLACE <- EXPR` and `box EXPR` desugar into expressions
2+
/// that allocate an intermediate "place" that holds uninitialized
3+
/// state. The desugaring evaluates EXPR, and writes the result at
4+
/// the address returned by the `pointer` method of this trait.
5+
///
6+
/// A `Place` can be thought of as a special representation for a
7+
/// hypothetical `&uninit` reference (which Rust cannot currently
8+
/// express directly). That is, it represents a pointer to
9+
/// uninitialized storage.
10+
///
11+
/// The client is responsible for two steps: First, initializing the
12+
/// payload (it can access its address via `pointer`). Second,
13+
/// converting the agent to an instance of the owning pointer, via the
14+
/// appropriate `finalize` method (see the `InPlace`.
15+
///
16+
/// If evaluating EXPR fails, then it is up to the destructor for the
17+
/// implementation of Place to clean up any intermediate state
18+
/// (e.g. deallocate box storage, pop a stack, etc).
19+
#[unstable(feature = "placement_new_protocol", issue = "27779")]
20+
pub trait Place<Data: ?Sized> {
21+
/// Returns the address where the input value will be written.
22+
/// Note that the data at this address is generally uninitialized,
23+
/// and thus one should use `ptr::write` for initializing it.
24+
fn pointer(&mut self) -> *mut Data;
25+
}
26+
27+
/// Interface to implementations of `PLACE <- EXPR`.
28+
///
29+
/// `PLACE <- EXPR` effectively desugars into:
30+
///
31+
/// ```rust,ignore
32+
/// let p = PLACE;
33+
/// let mut place = Placer::make_place(p);
34+
/// let raw_place = Place::pointer(&mut place);
35+
/// let value = EXPR;
36+
/// unsafe {
37+
/// std::ptr::write(raw_place, value);
38+
/// InPlace::finalize(place)
39+
/// }
40+
/// ```
41+
///
42+
/// The type of `PLACE <- EXPR` is derived from the type of `PLACE`;
43+
/// if the type of `PLACE` is `P`, then the final type of the whole
44+
/// expression is `P::Place::Owner` (see the `InPlace` and `Boxed`
45+
/// traits).
46+
///
47+
/// Values for types implementing this trait usually are transient
48+
/// intermediate values (e.g. the return value of `Vec::emplace_back`)
49+
/// or `Copy`, since the `make_place` method takes `self` by value.
50+
#[unstable(feature = "placement_new_protocol", issue = "27779")]
51+
pub trait Placer<Data: ?Sized> {
52+
/// `Place` is the intermedate agent guarding the
53+
/// uninitialized state for `Data`.
54+
type Place: InPlace<Data>;
55+
56+
/// Creates a fresh place from `self`.
57+
fn make_place(self) -> Self::Place;
58+
}
59+
60+
/// Specialization of `Place` trait supporting `PLACE <- EXPR`.
61+
#[unstable(feature = "placement_new_protocol", issue = "27779")]
62+
pub trait InPlace<Data: ?Sized>: Place<Data> {
63+
/// `Owner` is the type of the end value of `PLACE <- EXPR`
64+
///
65+
/// Note that when `PLACE <- EXPR` is solely used for
66+
/// side-effecting an existing data-structure,
67+
/// e.g. `Vec::emplace_back`, then `Owner` need not carry any
68+
/// information at all (e.g. it can be the unit type `()` in that
69+
/// case).
70+
type Owner;
71+
72+
/// Converts self into the final value, shifting
73+
/// deallocation/cleanup responsibilities (if any remain), over to
74+
/// the returned instance of `Owner` and forgetting self.
75+
unsafe fn finalize(self) -> Self::Owner;
76+
}
77+
78+
/// Core trait for the `box EXPR` form.
79+
///
80+
/// `box EXPR` effectively desugars into:
81+
///
82+
/// ```rust,ignore
83+
/// let mut place = BoxPlace::make_place();
84+
/// let raw_place = Place::pointer(&mut place);
85+
/// let value = EXPR;
86+
/// unsafe {
87+
/// ::std::ptr::write(raw_place, value);
88+
/// Boxed::finalize(place)
89+
/// }
90+
/// ```
91+
///
92+
/// The type of `box EXPR` is supplied from its surrounding
93+
/// context; in the above expansion, the result type `T` is used
94+
/// to determine which implementation of `Boxed` to use, and that
95+
/// `<T as Boxed>` in turn dictates determines which
96+
/// implementation of `BoxPlace` to use, namely:
97+
/// `<<T as Boxed>::Place as BoxPlace>`.
98+
#[unstable(feature = "placement_new_protocol", issue = "27779")]
99+
pub trait Boxed {
100+
/// The kind of data that is stored in this kind of box.
101+
type Data; /* (`Data` unused b/c cannot yet express below bound.) */
102+
/// The place that will negotiate the storage of the data.
103+
type Place: BoxPlace<Self::Data>;
104+
105+
/// Converts filled place into final owning value, shifting
106+
/// deallocation/cleanup responsibilities (if any remain), over to
107+
/// returned instance of `Self` and forgetting `filled`.
108+
unsafe fn finalize(filled: Self::Place) -> Self;
109+
}
110+
111+
/// Specialization of `Place` trait supporting `box EXPR`.
112+
#[unstable(feature = "placement_new_protocol", issue = "27779")]
113+
pub trait BoxPlace<Data: ?Sized> : Place<Data> {
114+
/// Creates a globally fresh place.
115+
fn make_place() -> Self;
116+
}

‎src/libcore/ops/range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use fmt;
12
use collections::Bound::{self, Excluded, Included, Unbounded};
23

34
/// An unbounded range. Use `..` (two dots) for its shorthand.

0 commit comments

Comments
 (0)
Please sign in to comment.