@@ -717,6 +717,15 @@ macro_rules! shr_impl {
717
717
718
718
shr_impl ! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
719
719
720
+ // NOTE(stage0) remove trait after a snapshot
721
+ #[ cfg( stage0) ]
722
+ #[ allow( missing_docs) ]
723
+ #[ lang="index" ]
724
+ pub trait Index < Sized ? Index , Sized ? Result > for Sized ? {
725
+ /// The method for the indexing (`Foo[Bar]`) operation
726
+ fn index < ' a > ( & ' a self , index : & Index ) -> & ' a Result ;
727
+ }
728
+
720
729
/// The `Index` trait is used to specify the functionality of indexing operations
721
730
/// like `arr[idx]` when used in an immutable context.
722
731
///
@@ -726,12 +735,16 @@ shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
726
735
/// calling `index`, and therefore, `main` prints `Indexing!`.
727
736
///
728
737
/// ```
738
+ /// #![feature(associated_types)]
739
+ ///
729
740
/// use std::ops::Index;
730
741
///
731
742
/// #[deriving(Copy)]
732
743
/// struct Foo;
733
744
///
734
- /// impl Index<Foo, Foo> for Foo {
745
+ /// impl Index<Foo> for Foo {
746
+ /// type Output = Foo;
747
+ ///
735
748
/// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo {
736
749
/// println!("Indexing!");
737
750
/// self
@@ -742,10 +755,22 @@ shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
742
755
/// Foo[Foo];
743
756
/// }
744
757
/// ```
758
+ #[ cfg( not( stage0) ) ] // NOTE(stage0) remove cfg after a snapshot
745
759
#[ lang="index" ]
746
- pub trait Index < Sized ? Index , Sized ? Result > for Sized ? {
760
+ pub trait Index <Sized ? Index > for Sized ? {
761
+ type Sized ? Output ;
762
+
747
763
/// The method for the indexing (`Foo[Bar]`) operation
748
- fn index < ' a > ( & ' a self , index : & Index ) -> & ' a Result ;
764
+ fn index < ' a > ( & ' a self , index : & Index ) -> & ' a Self :: Output ;
765
+ }
766
+
767
+ // NOTE(stage0) remove trait after a snapshot
768
+ #[ cfg( stage0) ]
769
+ #[ allow( missing_docs) ]
770
+ #[ lang="index_mut" ]
771
+ pub trait IndexMut < Sized ? Index , Sized ? Result > for Sized ? {
772
+ /// The method for the indexing (`Foo[Bar]`) operation
773
+ fn index_mut < ' a > ( & ' a mut self , index : & Index ) -> & ' a mut Result ;
749
774
}
750
775
751
776
/// The `IndexMut` trait is used to specify the functionality of indexing
@@ -757,12 +782,16 @@ pub trait Index<Sized? Index, Sized? Result> for Sized? {
757
782
/// calling `index_mut`, and therefore, `main` prints `Indexing!`.
758
783
///
759
784
/// ```
785
+ /// #![feature(associated_types)]
786
+ ///
760
787
/// use std::ops::IndexMut;
761
788
///
762
789
/// #[deriving(Copy)]
763
790
/// struct Foo;
764
791
///
765
- /// impl IndexMut<Foo, Foo> for Foo {
792
+ /// impl IndexMut<Foo> for Foo {
793
+ /// type Output = Foo;
794
+ ///
766
795
/// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo {
767
796
/// println!("Indexing!");
768
797
/// self
@@ -773,10 +802,13 @@ pub trait Index<Sized? Index, Sized? Result> for Sized? {
773
802
/// &mut Foo[Foo];
774
803
/// }
775
804
/// ```
805
+ #[ cfg( not( stage0) ) ] // NOTE(stage0) remove cfg after a snapshot
776
806
#[ lang="index_mut" ]
777
- pub trait IndexMut < Sized ? Index , Sized ? Result > for Sized ? {
807
+ pub trait IndexMut <Sized ? Index > for Sized ? {
808
+ type Sized ? Output ;
809
+
778
810
/// The method for the indexing (`Foo[Bar]`) operation
779
- fn index_mut < ' a > ( & ' a mut self , index : & Index ) -> & ' a mut Result ;
811
+ fn index_mut < ' a > ( & ' a mut self , index : & Index ) -> & ' a mut Self :: Output ;
780
812
}
781
813
782
814
/// The `Slice` trait is used to specify the functionality of slicing operations
0 commit comments