]> git.lizzy.rs Git - rust.git/commitdiff
Compiler and trait changes to make indexing by value.
authorNiko Matsakis <niko@alum.mit.edu>
Sat, 21 Mar 2015 23:30:06 +0000 (19:30 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 23 Mar 2015 20:54:28 +0000 (16:54 -0400)
src/libcollections/bit.rs
src/libcore/ops.rs
src/librustc/middle/expr_use_visitor.rs
src/librustc_trans/trans/expr.rs

index 90fbe04d3482f9f73fbcea9d4c1d90bea4cb4207..e494527b6a67c921af62f1992a9595c7dab35124 100644 (file)
@@ -169,6 +169,8 @@ pub struct BitVec {
 impl Index<usize> for BitVec {
     type Output = bool;
 
+
+    #[cfg(stage0)]
     #[inline]
     fn index(&self, i: &usize) -> &bool {
         if self.get(*i).expect("index out of bounds") {
@@ -177,6 +179,16 @@ fn index(&self, i: &usize) -> &bool {
             &FALSE
         }
     }
+
+    #[cfg(not(stage0))]
+    #[inline]
+    fn index(&self, i: usize) -> &bool {
+        if self.get(i).expect("index out of bounds") {
+            &TRUE
+        } else {
+            &FALSE
+        }
+    }
 }
 
 /// Computes how many blocks are needed to store that many bits
index 6324e8fa874439bf54d850809716a54146753534..e1e352b5b640cd1b562039fd5cfc5806f2a26c61 100644 (file)
@@ -917,8 +917,14 @@ pub trait Index<Idx: ?Sized> {
     type Output: ?Sized;
 
     /// The method for the indexing (`Foo[Bar]`) operation
+    #[cfg(stage0)]
     #[stable(feature = "rust1", since = "1.0.0")]
     fn index<'a>(&'a self, index: &Idx) -> &'a Self::Output;
+
+    /// The method for the indexing (`Foo[Bar]`) operation
+    #[cfg(not(stage0))]
+    #[stable(feature = "rust1", since = "1.0.0")]
+    fn index<'a>(&'a self, index: Idx) -> &'a Self::Output;
 }
 
 /// The `IndexMut` trait is used to specify the functionality of indexing
@@ -960,8 +966,14 @@ pub trait Index<Idx: ?Sized> {
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
     /// The method for the indexing (`Foo[Bar]`) operation
+    #[cfg(stage0)]
     #[stable(feature = "rust1", since = "1.0.0")]
     fn index_mut<'a>(&'a mut self, index: &Idx) -> &'a mut Self::Output;
+
+    /// The method for the indexing (`Foo[Bar]`) operation
+    #[cfg(not(stage0))]
+    #[stable(feature = "rust1", since = "1.0.0")]
+    fn index_mut<'a>(&'a mut self, index: Idx) -> &'a mut Self::Output;
 }
 
 /// An unbounded range.
index 6d2392054f9d578efd6786583c204d89302d00c0..975bf01fdef6f52f790a1aea0039a7e18b91734c 100644 (file)
@@ -442,7 +442,7 @@ pub fn walk_expr(&mut self, expr: &ast::Expr) {
                 if !self.walk_overloaded_operator(expr,
                                                   &**lhs,
                                                   vec![&**rhs],
-                                                  PassArgs::ByRef) {
+                                                  PassArgs::ByValue) {
                     self.select_from_expr(&**lhs);
                     self.consume_expr(&**rhs);
                 }
index 4653ef2980a78e6db183b24f76aa7d8c46086fa9..4aff28122bbb3670293da3334bb01a23464f4814 100644 (file)
@@ -843,7 +843,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                                                base_datum,
                                                vec![(ix_datum, idx.id)],
                                                Some(SaveIn(scratch.val)),
-                                               true));
+                                               false));
             let datum = scratch.to_expr_datum();
             if type_is_sized(bcx.tcx(), elt_ty) {
                 Datum::new(datum.to_llscalarish(bcx), elt_ty, LvalueExpr)