auto merge of #17807 : nick29581/rust/slice6, r=aturon

r? @aturon
This commit is contained in:
bors 2014-10-07 06:17:11 +00:00
commit e62ef37cfa
123 changed files with 663 additions and 405 deletions

View file

@ -38,6 +38,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#![feature(slicing_syntax)]
use std::{cmp, iter, mem};
use std::sync::Future;
@ -50,7 +52,7 @@ fn rotate(x: &mut [i32]) {
fn next_permutation(perm: &mut [i32], count: &mut [i32]) {
for i in range(1, perm.len()) {
rotate(perm.slice_to_mut(i + 1));
rotate(perm[mut ..i + 1]);
let count_i = &mut count[i];
if *count_i >= i as i32 {
*count_i = 0;
@ -99,7 +101,7 @@ impl Perm {
let d = idx / self.fact[i] as i32;
self.cnt[i] = d;
idx %= self.fact[i] as i32;
for (place, val) in pp.iter_mut().zip(self.perm.p.slice_to(i + 1).iter()) {
for (place, val) in pp.iter_mut().zip(self.perm.p[..i+1].iter()) {
*place = (*val) as u8
}
@ -125,7 +127,7 @@ impl Perm {
fn reverse(tperm: &mut [i32], mut k: uint) {
tperm.slice_to_mut(k).reverse()
tperm[mut ..k].reverse()
}
fn work(mut perm: Perm, n: uint, max: uint) -> (i32, i32) {

View file

@ -38,6 +38,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#![feature(slicing_syntax)]
use std::cmp::min;
use std::io::{stdout, IoResult};
use std::os;
@ -124,8 +126,8 @@ impl<'a, W: Writer> RepeatFasta<'a, W> {
copy_memory(buf.as_mut_slice(), alu);
let buf_len = buf.len();
copy_memory(buf.slice_mut(alu_len, buf_len),
alu.slice_to(LINE_LEN));
copy_memory(buf[mut alu_len..buf_len],
alu[..LINE_LEN]);
let mut pos = 0;
let mut bytes;
@ -201,7 +203,7 @@ impl<'a, W: Writer> RandomFasta<'a, W> {
for i in range(0u, chars_left) {
buf[i] = self.nextc();
}
self.out.write(buf.slice_to(chars_left))
self.out.write(buf[..chars_left])
}
}

View file

@ -38,6 +38,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#![feature(slicing_syntax)]
use std::io;
use std::io::{BufferedWriter, File};
use std::cmp::min;
@ -93,7 +95,7 @@ fn make_fasta<W: Writer, I: Iterator<u8>>(
}
n -= nb;
line[nb] = '\n' as u8;
wr.write(line.slice_to(nb + 1));
wr.write(line[..nb+1]);
}
}

View file

@ -13,6 +13,8 @@
// multi tasking k-nucleotide
#![feature(slicing_syntax)]
extern crate collections;
use std::collections::HashMap;
@ -97,11 +99,11 @@ fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> Vec<u8> {
let len = bb.len();
while ii < len - (nn - 1u) {
it(bb.slice(ii, ii+nn));
it(bb[ii..ii+nn]);
ii += 1u;
}
return Vec::from_slice(bb.slice(len - (nn - 1u), len));
return Vec::from_slice(bb[len - (nn - 1u)..len]);
}
fn make_sequence_processor(sz: uint,

View file

@ -40,6 +40,8 @@
// ignore-android see #10393 #13206
#![feature(slicing_syntax)]
use std::string::String;
use std::slice;
use std::sync::{Arc, Future};
@ -240,14 +242,14 @@ fn generate_frequencies(mut input: &[u8], frame: uint) -> Table {
// Pull first frame.
for _ in range(0, frame) {
code = code.push_char(input[0]);
input = input.slice_from(1);
input = input[1..];
}
frequencies.lookup(code, BumpCallback);
while input.len() != 0 && input[0] != ('>' as u8) {
code = code.rotate(input[0], frame);
frequencies.lookup(code, BumpCallback);
input = input.slice_from(1);
input = input[1..];
}
frequencies
}

View file

@ -41,7 +41,7 @@
// ignore-stage1
// ignore-cross-compile #12102
#![feature(macro_rules, phase)]
#![feature(macro_rules, phase, slicing_syntax)]
extern crate regex;
#[phase(plugin)]extern crate regex_macros;

View file

@ -41,6 +41,8 @@
// ignore-pretty very bad with line comments
// ignore-android doesn't terminate?
#![feature(slicing_syntax)]
use std::iter::range_step;
use std::io::{stdin, stdout, File};
@ -81,7 +83,7 @@ fn main() {
Some(c) => c
};
let len = seq.len();
let seq = seq.slice_mut(begin + 1, len - 1);
let seq = seq[mut begin+1..len-1];
// arrange line breaks
let len = seq.len();

View file

@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(slicing_syntax)]
fn main() {
let mut array = [1, 2, 3];
//~^ ERROR cannot determine a type for this local variable: cannot determine the type of this integ
let pie_slice = array.slice(1, 2);
let pie_slice = array[1..2];
}

View file

@ -10,6 +10,8 @@
// Test that slicing syntax gives errors if we have not implemented the trait.
#![feature(slicing_syntax)]
struct Foo;
fn main() {

View file

@ -10,6 +10,8 @@
// Test slicing expressions doesn't defeat the borrow checker.
#![feature(slicing_syntax)]
fn main() {
let y;
{

View file

@ -10,6 +10,8 @@
// Test mutability and slicing syntax.
#![feature(slicing_syntax)]
fn main() {
let x: &[int] = &[1, 2, 3, 4, 5];
// Can't mutably slice an immutable slice

View file

@ -10,6 +10,8 @@
// Test mutability and slicing syntax.
#![feature(slicing_syntax)]
fn main() {
let x: &[int] = &[1, 2, 3, 4, 5];
// Immutable slices are not mutable.

View file

@ -80,6 +80,7 @@
// lldb-check:[...]$5 = &[AStruct { x: 10, y: 11, z: 12 }, AStruct { x: 13, y: 14, z: 15 }]
#![allow(unused_variable)]
#![feature(slicing_syntax)]
struct AStruct {
x: i16,
@ -94,7 +95,7 @@ fn main() {
let empty: &[i64] = &[];
let singleton: &[i64] = &[1];
let multiple: &[i64] = &[2, 3, 4, 5];
let slice_of_slice = multiple.slice(1,3);
let slice_of_slice = multiple[1..3];
let padded_tuple: &[(i32, i16)] = &[(6, 7), (8, 9)];

View file

@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(slicing_syntax)]
fn vec_peek<'r, T>(v: &'r [T]) -> &'r [T] {
v.slice(1, 5)
v[1..5]
}
pub fn main() {}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn broken(v: &[u8], i: uint, j: uint) -> &[u8] { v.slice(i, j) }
#![feature(slicing_syntax)]
fn broken(v: &[u8], i: uint, j: uint) -> &[u8] { v[i..j] }
pub fn main() {}

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(slicing_syntax)]
extern crate debug;
@ -19,7 +20,7 @@ pub fn main() {
let abc = [1i, 2, 3];
let tf = [true, false];
let x = [(), ()];
let slice = x.slice(0, 1);
let slice = x[0..1];
assert_repr_eq(abc, "[1, 2, 3]".to_string());
assert_repr_eq(tf, "[true, false]".to_string());

View file

@ -10,6 +10,8 @@
// Test slicing expressions on slices and Vecs.
#![feature(slicing_syntax)]
fn main() {
let x: &[int] = &[1, 2, 3, 4, 5];
let cmp: &[int] = &[1, 2, 3, 4, 5];

View file

@ -10,6 +10,8 @@
// Test that is a slicing expr[..] fails, the correct cleanups happen.
#![feature(slicing_syntax)]
use std::task;
struct Foo;

View file

@ -10,6 +10,8 @@
// Test that is a slicing expr[..] fails, the correct cleanups happen.
#![feature(slicing_syntax)]
use std::task;
struct Foo;

View file

@ -10,6 +10,8 @@
// Test slicing sugar.
#![feature(slicing_syntax)]
extern crate core;
use core::ops::{Slice,SliceMut};
@ -22,15 +24,15 @@ impl Slice<Foo, Foo> for Foo {
unsafe { COUNT += 1; }
self
}
fn slice_from_<'a>(&'a self, _from: &Foo) -> &'a Foo {
fn slice_from_or_fail<'a>(&'a self, _from: &Foo) -> &'a Foo {
unsafe { COUNT += 1; }
self
}
fn slice_to_<'a>(&'a self, _to: &Foo) -> &'a Foo {
fn slice_to_or_fail<'a>(&'a self, _to: &Foo) -> &'a Foo {
unsafe { COUNT += 1; }
self
}
fn slice_<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
fn slice_or_fail<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
unsafe { COUNT += 1; }
self
}
@ -41,15 +43,15 @@ impl SliceMut<Foo, Foo> for Foo {
unsafe { COUNT += 1; }
self
}
fn slice_from_mut_<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
fn slice_from_or_fail_mut<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
unsafe { COUNT += 1; }
self
}
fn slice_to_mut_<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
fn slice_to_or_fail_mut<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
unsafe { COUNT += 1; }
self
}
fn slice_mut_<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
fn slice_or_fail_mut<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
unsafe { COUNT += 1; }
self
}