Compiler and trait changes to make indexing by value.

This commit is contained in:
Niko Matsakis 2015-03-21 19:30:06 -04:00
parent 809a554fca
commit bc1dde468c
4 changed files with 26 additions and 2 deletions

View 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 @@ impl Index<usize> for BitVec {
&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

View 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.

View File

@ -442,7 +442,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
if !self.walk_overloaded_operator(expr,
&**lhs,
vec![&**rhs],
PassArgs::ByRef) {
PassArgs::ByValue) {
self.select_from_expr(&**lhs);
self.consume_expr(&**rhs);
}

View 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)