@@ -542,12 +542,16 @@ rem_float_impl! { f64, fmod }
542
542
/// -Foo;
543
543
/// }
544
544
/// ```
545
+ // NOTE(stage0): Remove trait after a snapshot
546
+ #[ cfg( stage0) ]
545
547
#[ lang="neg" ]
546
548
pub trait Neg < Result > for Sized ? {
547
549
/// The method for the unary `-` operator
548
550
fn neg ( & self ) -> Result ;
549
551
}
550
552
553
+ // NOTE(stage0): Remove macro after a snapshot
554
+ #[ cfg( stage0) ]
551
555
macro_rules! neg_impl {
552
556
( $( $t: ty) * ) => ( $(
553
557
impl Neg <$t> for $t {
@@ -557,6 +561,8 @@ macro_rules! neg_impl {
557
561
) * )
558
562
}
559
563
564
+ // NOTE(stage0): Remove macro after a snapshot
565
+ #[ cfg( stage0) ]
560
566
macro_rules! neg_uint_impl {
561
567
( $t: ty, $t_signed: ty) => {
562
568
impl Neg <$t> for $t {
@@ -566,6 +572,56 @@ macro_rules! neg_uint_impl {
566
572
}
567
573
}
568
574
575
+ /// The `Neg` trait is used to specify the functionality of unary `-`.
576
+ ///
577
+ /// # Example
578
+ ///
579
+ /// A trivial implementation of `Neg`. When `-Foo` happens, it ends up calling
580
+ /// `neg`, and therefore, `main` prints `Negating!`.
581
+ ///
582
+ /// ```
583
+ /// struct Foo;
584
+ ///
585
+ /// impl Copy for Foo {}
586
+ ///
587
+ /// impl Neg<Foo> for Foo {
588
+ /// fn neg(self) -> Foo {
589
+ /// println!("Negating!");
590
+ /// self
591
+ /// }
592
+ /// }
593
+ ///
594
+ /// fn main() {
595
+ /// -Foo;
596
+ /// }
597
+ /// ```
598
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
599
+ #[ lang="neg" ]
600
+ pub trait Neg < Result > {
601
+ /// The method for the unary `-` operator
602
+ fn neg ( self ) -> Result ;
603
+ }
604
+
605
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
606
+ macro_rules! neg_impl {
607
+ ( $( $t: ty) * ) => ( $(
608
+ impl Neg <$t> for $t {
609
+ #[ inline]
610
+ fn neg( self ) -> $t { -self }
611
+ }
612
+ ) * )
613
+ }
614
+
615
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
616
+ macro_rules! neg_uint_impl {
617
+ ( $t: ty, $t_signed: ty) => {
618
+ impl Neg <$t> for $t {
619
+ #[ inline]
620
+ fn neg( self ) -> $t { -( self as $t_signed) as $t }
621
+ }
622
+ }
623
+ }
624
+
569
625
neg_impl ! { int i8 i16 i32 i64 f32 f64 }
570
626
571
627
neg_uint_impl ! { uint, int }
@@ -598,13 +654,17 @@ neg_uint_impl! { u64, i64 }
598
654
/// !Foo;
599
655
/// }
600
656
/// ```
657
+ // NOTE(stage0): Remove macro after a snapshot
658
+ #[ cfg( stage0) ]
601
659
#[ lang="not" ]
602
660
pub trait Not < Result > for Sized ? {
603
661
/// The method for the unary `!` operator
604
662
fn not ( & self ) -> Result ;
605
663
}
606
664
607
665
666
+ // NOTE(stage0): Remove macro after a snapshot
667
+ #[ cfg( stage0) ]
608
668
macro_rules! not_impl {
609
669
( $( $t: ty) * ) => ( $(
610
670
impl Not <$t> for $t {
@@ -614,6 +674,46 @@ macro_rules! not_impl {
614
674
) * )
615
675
}
616
676
677
+ /// The `Not` trait is used to specify the functionality of unary `!`.
678
+ ///
679
+ /// # Example
680
+ ///
681
+ /// A trivial implementation of `Not`. When `!Foo` happens, it ends up calling
682
+ /// `not`, and therefore, `main` prints `Not-ing!`.
683
+ ///
684
+ /// ```
685
+ /// struct Foo;
686
+ ///
687
+ /// impl Copy for Foo {}
688
+ ///
689
+ /// impl Not<Foo> for Foo {
690
+ /// fn not(self) -> Foo {
691
+ /// println!("Not-ing!");
692
+ /// self
693
+ /// }
694
+ /// }
695
+ ///
696
+ /// fn main() {
697
+ /// !Foo;
698
+ /// }
699
+ /// ```
700
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
701
+ #[ lang="not" ]
702
+ pub trait Not < Result > {
703
+ /// The method for the unary `!` operator
704
+ fn not ( self ) -> Result ;
705
+ }
706
+
707
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
708
+ macro_rules! not_impl {
709
+ ( $( $t: ty) * ) => ( $(
710
+ impl Not <$t> for $t {
711
+ #[ inline]
712
+ fn not( self ) -> $t { !self }
713
+ }
714
+ ) * )
715
+ }
716
+
617
717
not_impl ! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
618
718
619
719
/// The `BitAnd` trait is used to specify the functionality of `&`.
0 commit comments