Skip to content

Commit bc1dde4

Browse files
committed
Compiler and trait changes to make indexing by value.
1 parent 809a554 commit bc1dde4

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/libcollections/bit.rs

+12
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ pub struct BitVec {
169169
impl Index<usize> for BitVec {
170170
type Output = bool;
171171

172+
173+
#[cfg(stage0)]
172174
#[inline]
173175
fn index(&self, i: &usize) -> &bool {
174176
if self.get(*i).expect("index out of bounds") {
@@ -177,6 +179,16 @@ impl Index<usize> for BitVec {
177179
&FALSE
178180
}
179181
}
182+
183+
#[cfg(not(stage0))]
184+
#[inline]
185+
fn index(&self, i: usize) -> &bool {
186+
if self.get(i).expect("index out of bounds") {
187+
&TRUE
188+
} else {
189+
&FALSE
190+
}
191+
}
180192
}
181193

182194
/// Computes how many blocks are needed to store that many bits

src/libcore/ops.rs

+12
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,14 @@ pub trait Index<Idx: ?Sized> {
917917
type Output: ?Sized;
918918

919919
/// The method for the indexing (`Foo[Bar]`) operation
920+
#[cfg(stage0)]
920921
#[stable(feature = "rust1", since = "1.0.0")]
921922
fn index<'a>(&'a self, index: &Idx) -> &'a Self::Output;
923+
924+
/// The method for the indexing (`Foo[Bar]`) operation
925+
#[cfg(not(stage0))]
926+
#[stable(feature = "rust1", since = "1.0.0")]
927+
fn index<'a>(&'a self, index: Idx) -> &'a Self::Output;
922928
}
923929

924930
/// The `IndexMut` trait is used to specify the functionality of indexing
@@ -960,8 +966,14 @@ pub trait Index<Idx: ?Sized> {
960966
#[stable(feature = "rust1", since = "1.0.0")]
961967
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
962968
/// The method for the indexing (`Foo[Bar]`) operation
969+
#[cfg(stage0)]
963970
#[stable(feature = "rust1", since = "1.0.0")]
964971
fn index_mut<'a>(&'a mut self, index: &Idx) -> &'a mut Self::Output;
972+
973+
/// The method for the indexing (`Foo[Bar]`) operation
974+
#[cfg(not(stage0))]
975+
#[stable(feature = "rust1", since = "1.0.0")]
976+
fn index_mut<'a>(&'a mut self, index: Idx) -> &'a mut Self::Output;
965977
}
966978

967979
/// An unbounded range.

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
442442
if !self.walk_overloaded_operator(expr,
443443
&**lhs,
444444
vec![&**rhs],
445-
PassArgs::ByRef) {
445+
PassArgs::ByValue) {
446446
self.select_from_expr(&**lhs);
447447
self.consume_expr(&**rhs);
448448
}

src/librustc_trans/trans/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
843843
base_datum,
844844
vec![(ix_datum, idx.id)],
845845
Some(SaveIn(scratch.val)),
846-
true));
846+
false));
847847
let datum = scratch.to_expr_datum();
848848
if type_is_sized(bcx.tcx(), elt_ty) {
849849
Datum::new(datum.to_llscalarish(bcx), elt_ty, LvalueExpr)

0 commit comments

Comments
 (0)