|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -use fmt; |
12 | 11 | use marker::Unsize;
|
13 | 12 |
|
14 | 13 | /// 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 {
|
359 | 358 | fn deref_mut(&mut self) -> &mut T { *self }
|
360 | 359 | }
|
361 | 360 |
|
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 |
| - |
547 | 361 | /// Trait that indicates that this is a pointer or a wrapper for one,
|
548 | 362 | /// where unsizing can be performed on the pointee.
|
549 | 363 | ///
|
@@ -612,123 +426,6 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
|
612 | 426 | #[unstable(feature = "coerce_unsized", issue = "27732")]
|
613 | 427 | impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
|
614 | 428 |
|
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 |
| - |
732 | 429 | /// A trait for types which have success and error states and are meant to work
|
733 | 430 | /// with the question mark operator.
|
734 | 431 | /// When the `?` operator is used with a value, whether the value is in the
|
|
0 commit comments