Skip to content

Remove ExprSlice #20160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl<T> RingBuf<T> {

if contiguous {
let (empty, buf) = buf.split_at_mut(0);
(buf[mut tail..head], empty)
(buf.slice_mut(tail, head), empty)
} else {
let (mid, right) = buf.split_at_mut(tail);
let (left, _) = mid.split_at_mut(head);
Expand Down
14 changes: 7 additions & 7 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use core::iter::{range_step, MultiplicativeIterator};
use core::kinds::Sized;
use core::mem::size_of;
use core::mem;
use core::ops::FnMut;
use core::ops::{FnMut,SliceMut};
use core::prelude::{Clone, Greater, Iterator, IteratorExt, Less, None, Option};
use core::prelude::{Ord, Ordering, RawPtr, Some, range};
use core::ptr;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ impl<T> SliceExt<T> for [T] {

#[inline]
fn move_from(&mut self, mut src: Vec<T>, start: uint, end: uint) -> uint {
for (a, b) in self.iter_mut().zip(src[mut start..end].iter_mut()) {
for (a, b) in self.iter_mut().zip(src.slice_mut(start, end).iter_mut()) {
mem::swap(a, b);
}
cmp::min(self.len(), end-start)
Expand Down Expand Up @@ -1326,7 +1326,7 @@ impl<T> BorrowFrom<Vec<T>> for [T] {

#[unstable = "trait is unstable"]
impl<T> BorrowFromMut<Vec<T>> for [T] {
fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { owned[mut] }
fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { owned.as_mut_slice_() }
}

#[unstable = "trait is unstable"]
Expand Down Expand Up @@ -2491,14 +2491,14 @@ mod tests {
assert!(a == [7i,2,3,4]);
let mut a = [1i,2,3,4,5];
let b = vec![5i,6,7,8,9,0];
assert_eq!(a[mut 2..4].move_from(b,1,6), 2);
assert_eq!(a.slice_mut(2, 4).move_from(b,1,6), 2);
assert!(a == [1i,2,6,7,5]);
}

#[test]
fn test_reverse_part() {
let mut values = [1i,2,3,4,5];
values[mut 1..4].reverse();
values.slice_mut(1, 4).reverse();
assert!(values == [1,4,3,2,5]);
}

Expand Down Expand Up @@ -2545,9 +2545,9 @@ mod tests {
fn test_bytes_set_memory() {
use slice::bytes::MutableByteVector;
let mut values = [1u8,2,3,4,5];
values[mut 0..5].set_memory(0xAB);
values.slice_mut(0, 5).set_memory(0xAB);
assert!(values == [0xAB, 0xAB, 0xAB, 0xAB, 0xAB]);
values[mut 2..4].set_memory(0xFF);
values.slice_mut(2, 4).set_memory(0xFF);
assert!(values == [0xAB, 0xAB, 0xFF, 0xFF, 0xAB]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
_ => ()
}

buf[mut ..end].reverse();
buf.slice_to_mut(end).reverse();

// Remember start of the fractional digits.
// Points one beyond end of buf if none get generated,
Expand Down Expand Up @@ -316,7 +316,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(

impl<'a> fmt::FormatWriter for Filler<'a> {
fn write(&mut self, bytes: &[u8]) -> fmt::Result {
slice::bytes::copy_memory(self.buf[mut *self.end..],
slice::bytes::copy_memory(self.buf.slice_from_mut(*self.end),
bytes);
*self.end += bytes.len();
Ok(())
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,14 @@ impl<Idx: Clone + Step> Iterator<Idx> for RangeFrom<Idx> {
}
}

/// A range which is only bounded above.
#[deriving(Copy)]
#[lang="range_to"]
pub struct RangeTo<Idx> {
/// The upper bound of the range (exclusive).
pub end: Idx,
}


/// The `Deref` trait is used to specify the functionality of dereferencing
/// operations like `*v`.
Expand Down
23 changes: 12 additions & 11 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,26 @@ impl<T> SliceExt<T> for [T] {
fn as_mut_slice(&mut self) -> &mut [T] { self }

fn slice_mut(&mut self, start: uint, end: uint) -> &mut [T] {
self[mut start..end]
ops::SliceMut::slice_or_fail_mut(self, &start, &end)
}

#[inline]
fn slice_from_mut(&mut self, start: uint) -> &mut [T] {
self[mut start..]
ops::SliceMut::slice_from_or_fail_mut(self, &start)
}

#[inline]
fn slice_to_mut(&mut self, end: uint) -> &mut [T] {
self[mut ..end]
ops::SliceMut::slice_to_or_fail_mut(self, &end)
}

#[inline]
fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
unsafe {
let self2: &mut [T] = mem::transmute_copy(&self);
(self[mut ..mid], self2[mut mid..])

(ops::SliceMut::slice_to_or_fail_mut(self, &mid),
ops::SliceMut::slice_from_or_fail_mut(self2, &mid))
}
}

Expand Down Expand Up @@ -315,14 +317,13 @@ impl<T> SliceExt<T> for [T] {

#[inline]
fn tail_mut(&mut self) -> &mut [T] {
let len = self.len();
self[mut 1..len]
self.slice_from_mut(1)
}

#[inline]
fn init_mut(&mut self) -> &mut [T] {
let len = self.len();
self[mut 0..len - 1]
self.slice_to_mut(len-1)
}

#[inline]
Expand Down Expand Up @@ -560,7 +561,7 @@ impl<T: Ord> OrdSliceExt<T> for [T] {
self.swap(j, i-1);

// Step 4: Reverse the (previously) weakly decreasing part
self[mut i..].reverse();
self.slice_from_mut(i).reverse();

true
}
Expand All @@ -582,7 +583,7 @@ impl<T: Ord> OrdSliceExt<T> for [T] {
}

// Step 2: Reverse the weakly increasing part
self[mut i..].reverse();
self.slice_from_mut(i).reverse();

// Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
let mut j = self.len() - 1;
Expand Down Expand Up @@ -990,7 +991,7 @@ impl<'a, T, P> Iterator<&'a mut [T]> for MutSplits<'a, T, P> where P: FnMut(&T)
Some(idx) => {
let tmp = mem::replace(&mut self.v, &mut []);
let (head, tail) = tmp.split_at_mut(idx);
self.v = tail[mut 1..];
self.v = tail.slice_from_mut(1);
Some(head)
}
}
Expand Down Expand Up @@ -1026,7 +1027,7 @@ impl<'a, T, P> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T, P> where
let tmp = mem::replace(&mut self.v, &mut []);
let (head, tail) = tmp.split_at_mut(idx);
self.v = head;
Some(tail[mut 1..])
Some(tail.slice_from_mut(1))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ impl<'a> Iterator<&'a str> for SplitStr<'a> {
}
}


/*
Section: Comparing strings
*/
Expand Down
8 changes: 7 additions & 1 deletion src/libcoretest/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use test::Bencher;
use core::ops::{Range, FullRange, RangeFrom};
use core::ops::{Range, FullRange, RangeFrom, RangeTo};

// Overhead of dtors

Expand Down Expand Up @@ -55,6 +55,12 @@ fn test_range_from() {
assert!(count == 10);
}

#[test]
fn test_range_to() {
// Not much to test.
let _ = RangeTo { end: 42u };
}

#[test]
fn test_full_range() {
// Not much to test.
Expand Down
4 changes: 2 additions & 2 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ mod tests {
fn test_input(g: LabelledGraph) -> IoResult<String> {
let mut writer = Vec::new();
render(&g, &mut writer).unwrap();
(&mut writer[]).read_to_string()
(&mut writer.as_slice()).read_to_string()
}

// All of the tests use raw-strings as the format for the expected outputs,
Expand Down Expand Up @@ -847,7 +847,7 @@ r#"digraph hasse_diagram {
edge(1, 3, ";"), edge(2, 3, ";" )));

render(&g, &mut writer).unwrap();
let r = (&mut writer[]).read_to_string();
let r = (&mut writer.as_slice()).read_to_string();

assert_eq!(r.unwrap(),
r#"digraph syntax_tree {
Expand Down
2 changes: 1 addition & 1 deletion src/librbml/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Writer for SeekableMemWriter {

// Do the necessary writes
if left.len() > 0 {
slice::bytes::copy_memory(self.buf[mut self.pos..], left);
slice::bytes::copy_memory(self.buf.slice_from_mut(self.pos), left);
}
if right.len() > 0 {
self.buf.push_all(right);
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.call(expr, pred, &**l, Some(&**r).into_iter())
}

ast::ExprSlice(ref base, ref start, ref end, _) => {
self.call(expr,
pred,
&**base,
start.iter().chain(end.iter()).map(|x| &**x))
}

ast::ExprRange(ref start, ref end) => {
let fields = Some(&**start).into_iter()
let fields = start.as_ref().map(|e| &**e).into_iter()
.chain(end.as_ref().map(|e| &**e).into_iter());
self.straightline(expr, pred, fields)
}
Expand Down
39 changes: 23 additions & 16 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,26 +431,33 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
}

ast::ExprIndex(ref lhs, ref rhs) => { // lhs[rhs]
if !self.walk_overloaded_operator(expr, &**lhs, vec![&**rhs], PassArgs::ByRef) {
self.select_from_expr(&**lhs);
self.consume_expr(&**rhs);
match rhs.node {
ast::ExprRange(ref start, ref end) => {
// Hacked slicing syntax (KILLME).
let args = match (start, end) {
(&Some(ref e1), &Some(ref e2)) => vec![&**e1, &**e2],
(&Some(ref e), &None) => vec![&**e],
(&None, &Some(ref e)) => vec![&**e],
(&None, &None) => Vec::new()
};
let overloaded =
self.walk_overloaded_operator(expr, &**lhs, args, PassArgs::ByRef);
assert!(overloaded);
}
_ => {
if !self.walk_overloaded_operator(expr,
&**lhs,
vec![&**rhs],
PassArgs::ByRef) {
self.select_from_expr(&**lhs);
self.consume_expr(&**rhs);
}
}
}
}

ast::ExprSlice(ref base, ref start, ref end, _) => { // base[start..end]
let args = match (start, end) {
(&Some(ref e1), &Some(ref e2)) => vec![&**e1, &**e2],
(&Some(ref e), &None) => vec![&**e],
(&None, &Some(ref e)) => vec![&**e],
(&None, &None) => Vec::new()
};
let overloaded =
self.walk_overloaded_operator(expr, &**base, args, PassArgs::ByRef);
assert!(overloaded);
}

ast::ExprRange(ref start, ref end) => {
self.consume_expr(&**start);
start.as_ref().map(|e| self.consume_expr(&**e));
end.as_ref().map(|e| self.consume_expr(&**e));
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ lets_do_this! {
SliceMutTraitLangItem, "slice_mut", slice_mut_trait;
RangeStructLangItem, "range", range_struct;
RangeFromStructLangItem, "range_from", range_from_struct;
RangeToStructLangItem, "range_to", range_to_struct;
FullRangeStructLangItem, "full_range", full_range_struct;

UnsafeTypeLangItem, "unsafe", unsafe_type;
Expand Down
12 changes: 3 additions & 9 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
ast::ExprBlock(..) | ast::ExprAssign(..) | ast::ExprAssignOp(..) |
ast::ExprMac(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) |
ast::ExprParen(..) | ast::ExprInlineAsm(..) | ast::ExprBox(..) |
ast::ExprSlice(..) | ast::ExprRange(..) => {
ast::ExprRange(..) => {
visit::walk_expr(ir, expr);
}
}
Expand Down Expand Up @@ -1191,15 +1191,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**l, r_succ)
}

ast::ExprSlice(ref e1, ref e2, ref e3, _) => {
let succ = e3.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ));
let succ = e2.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ));
self.propagate_through_expr(&**e1, succ)
}

ast::ExprRange(ref e1, ref e2) => {
let succ = e2.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ));
self.propagate_through_expr(&**e1, succ)
e1.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ))
}

ast::ExprBox(None, ref e) |
Expand Down Expand Up @@ -1495,7 +1489,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
ast::ExprClosure(..) | ast::ExprPath(..) | ast::ExprBox(..) |
ast::ExprSlice(..) | ast::ExprRange(..) => {
ast::ExprRange(..) => {
visit::walk_expr(this, expr);
}
ast::ExprIfLet(..) => {
Expand Down
Loading