cleanup: replace as[_mut]_slice() calls with deref coercions

This commit is contained in:
Jorge Aparicio 2015-02-01 21:53:25 -05:00
parent 2c05354211
commit 17bc7d8d5b
289 changed files with 1372 additions and 1406 deletions

View file

@ -38,7 +38,7 @@ impl TTMacroExpander for Expander {
let attr = ecx.attribute(sp, self.args.clone());
let src = pprust::attribute_to_string(&attr);
let interned = token::intern_and_get_ident(src.as_slice());
let interned = token::intern_and_get_ident(&src);
MacExpr::new(ecx.expr_str(sp, interned))
}
}

View file

@ -46,7 +46,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
}
};
let mut text = text.as_slice();
let mut text = &*text;
let mut total = 0u;
while !text.is_empty() {
match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {

View file

@ -25,7 +25,7 @@ impl read for int {
impl read for bool {
fn readMaybe(s: String) -> Option<bool> {
match s.as_slice() {
match &*s {
"true" => Some(true),
"false" => Some(false),
_ => None

View file

@ -102,7 +102,7 @@ fn vector<M: MutableMap>(map: &mut M, n_keys: uint, dist: &[uint]) {
fn main() {
let args = os::args();
let args = args.as_slice();
let args = args;
let n_keys = {
if args.len() == 2 {
args[1].parse::<uint>().unwrap()
@ -143,7 +143,7 @@ fn main() {
{
println!(" Random integers:");
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
vector(&mut map, n_keys, rand.as_slice());
vector(&mut map, n_keys, &rand);
}
// FIXME: #9970
@ -162,6 +162,6 @@ fn main() {
{
println!(" Random integers:");
let mut map: HashMap<uint,uint> = HashMap::new();
vector(&mut map, n_keys, rand.as_slice());
vector(&mut map, n_keys, &rand);
}
}

View file

@ -180,7 +180,7 @@ fn empty_results() -> Results {
fn main() {
let args = os::args();
let args = args.as_slice();
let args = args;
let num_keys = {
if args.len() == 2 {
args[1].parse::<uint>().unwrap()

View file

@ -29,7 +29,7 @@ fn main() {
macro_rules! bench {
($id:ident) =>
(maybe_run_test(argv.as_slice(),
(maybe_run_test(&argv,
stringify!($id).to_string(),
$id))
}
@ -94,7 +94,7 @@ fn vec_plus() {
v.extend(rv.into_iter());
} else {
let mut rv = rv.clone();
rv.push_all(v.as_slice());
rv.push_all(&v);
v = rv;
}
i += 1;
@ -110,12 +110,12 @@ fn vec_append() {
let rv = repeat(i).take(r.gen_range(0u, i + 1)).collect::<Vec<_>>();
if r.gen() {
let mut t = v.clone();
t.push_all(rv.as_slice());
t.push_all(&rv);
v = t;
}
else {
let mut t = rv.clone();
t.push_all(v.as_slice());
t.push_all(&v);
v = t;
}
i += 1;
@ -129,11 +129,11 @@ fn vec_push_all() {
for i in 0u..1500 {
let mut rv = repeat(i).take(r.gen_range(0u, i + 1)).collect::<Vec<_>>();
if r.gen() {
v.push_all(rv.as_slice());
v.push_all(&rv);
}
else {
swap(&mut v, &mut rv);
v.push_all(rv.as_slice());
v.push_all(&rv);
}
}
}
@ -142,7 +142,7 @@ fn is_utf8_ascii() {
let mut v : Vec<u8> = Vec::new();
for _ in 0u..20000 {
v.push('b' as u8);
if str::from_utf8(v.as_slice()).is_err() {
if str::from_utf8(&v).is_err() {
panic!("from_utf8 panicked");
}
}
@ -153,7 +153,7 @@ fn is_utf8_multibyte() {
let mut v : Vec<u8> = Vec::new();
for _ in 0u..5000 {
v.push_all(s.as_bytes());
if str::from_utf8(v.as_slice()).is_err() {
if str::from_utf8(&v).is_err() {
panic!("from_utf8 panicked");
}
}

View file

@ -103,5 +103,5 @@ fn main() {
};
println!("{:?}", args);
run(args.as_slice());
run(&args);
}

View file

@ -110,5 +110,5 @@ fn main() {
};
println!("{:?}", args);
run(args.as_slice());
run(&args);
}

View file

@ -65,7 +65,7 @@ fn ping_pong_bench(n: uint, m: uint) {
fn main() {
let args = os::args();
let args = args.as_slice();
let args = args;
let n = if args.len() == 3 {
args[1].parse::<uint>().unwrap()
} else {

View file

@ -32,7 +32,7 @@ fn parfib(n: uint) -> uint {
fn main() {
let args = os::args();
let args = args.as_slice();
let args = args;
let n = if args.len() == 2 {
args[1].parse::<uint>().unwrap()
} else {

View file

@ -85,7 +85,7 @@ fn inner(depth: i32, iterations: i32) -> String {
fn main() {
let args = std::os::args();
let args = args.as_slice();
let args = args;
let n = if std::os::getenv("RUST_BENCH").is_some() {
17
} else if args.len() <= 1u {

View file

@ -82,7 +82,7 @@ fn show_color_list(set: Vec<Color>) -> String {
let mut out = String::new();
for col in &set {
out.push(' ');
out.push_str(format!("{:?}", col).as_slice());
out.push_str(&format!("{:?}", col));
}
out
}
@ -230,7 +230,7 @@ fn main() {
let nn = if std::os::getenv("RUST_BENCH").is_some() {
200000
} else {
std::os::args().as_slice()
std::os::args()
.get(1)
.and_then(|arg| arg.parse().ok())
.unwrap_or(600u)

View file

@ -180,7 +180,7 @@ fn fannkuch(n: i32) -> (i32, i32) {
}
fn main() {
let n = std::os::args().as_slice()
let n = std::os::args()
.get(1)
.and_then(|arg| arg.parse().ok())
.unwrap_or(2i32);

View file

@ -124,7 +124,7 @@ impl<'a, W: Writer> RepeatFasta<'a, W> {
let mut buf = repeat(0u8).take(alu_len + LINE_LEN).collect::<Vec<_>>();
let alu: &[u8] = self.alu.as_bytes();
copy_memory(buf.as_mut_slice(), alu);
copy_memory(&mut buf, alu);
let buf_len = buf.len();
copy_memory(&mut buf[alu_len..buf_len],
&alu[..LINE_LEN]);
@ -209,7 +209,7 @@ impl<'a, W: Writer> RandomFasta<'a, W> {
fn main() {
let args = os::args();
let args = args.as_slice();
let args = args;
let n = if args.len() > 1 {
args[1].parse::<uint>().unwrap()
} else {
@ -226,12 +226,12 @@ fn main() {
out.write_line(">TWO IUB ambiguity codes").unwrap();
let iub = sum_and_scale(&IUB);
let mut random = RandomFasta::new(&mut out, iub.as_slice());
let mut random = RandomFasta::new(&mut out, &iub);
random.make(n * 3).unwrap();
random.out.write_line(">THREE Homo sapiens frequency").unwrap();
let homo_sapiens = sum_and_scale(&HOMO_SAPIENS);
random.lookup = make_lookup(homo_sapiens.as_slice());
random.lookup = make_lookup(&homo_sapiens);
random.make(n * 5).unwrap();
random.out.write_str("\n").unwrap();

View file

@ -104,7 +104,7 @@ fn make_fasta<W: Writer, I: Iterator<Item=u8>>(
fn run<W: Writer>(writer: &mut W) -> std::old_io::IoResult<()> {
let args = os::args();
let args = args.as_slice();
let args = args;
let n = if os::getenv("RUST_BENCH").is_some() {
25000000
} else if args.len() <= 1u {

View file

@ -64,9 +64,9 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> String {
let mut buffer = String::new();
for &(ref k, v) in &pairs_sorted {
buffer.push_str(format!("{:?} {:0.3}\n",
k.to_ascii_uppercase(),
v).as_slice());
buffer.push_str(&format!("{:?} {:0.3}\n",
k.to_ascii_uppercase(),
v));
}
return buffer
@ -122,8 +122,8 @@ fn make_sequence_processor(sz: uint,
line = from_parent.recv().unwrap();
if line == Vec::new() { break; }
carry.push_all(line.as_slice());
carry = windows_with_carry(carry.as_slice(), sz, |window| {
carry.push_all(&line);
carry = windows_with_carry(&carry, sz, |window| {
update_freq(&mut freqs, window);
total += 1u;
});

View file

@ -261,7 +261,7 @@ fn print_frequencies(frequencies: &Table, frame: uint) {
for entry in frequencies.iter() {
vector.push((entry.count, entry.code));
}
vector.as_mut_slice().sort();
vector.sort();
let mut total_count = 0;
for &(count, _) in &vector {
@ -270,7 +270,7 @@ fn print_frequencies(frequencies: &Table, frame: uint) {
for &(count, key) in vector.iter().rev() {
println!("{} {:.3}",
key.unpack(frame).as_slice(),
key.unpack(frame),
(count as f32 * 100.0) / (total_count as f32));
}
println!("");
@ -301,11 +301,11 @@ fn main() {
let nb_freqs: Vec<_> = (1u..3).map(|i| {
let input = input.clone();
(i, Thread::scoped(move|| generate_frequencies(input.as_slice(), i)))
(i, Thread::scoped(move|| generate_frequencies(&input, i)))
}).collect();
let occ_freqs: Vec<_> = OCCURRENCES.iter().map(|&occ| {
let input = input.clone();
Thread::scoped(move|| generate_frequencies(input.as_slice(), occ.len()))
Thread::scoped(move|| generate_frequencies(&input, occ.len()))
}).collect();
for (i, freq) in nb_freqs {

View file

@ -124,7 +124,7 @@ fn mandelbrot<W: old_io::Writer>(w: usize, mut out: W) -> old_io::IoResult<()> {
Thread::scoped(move|| {
let mut res: Vec<u8> = Vec::with_capacity((chunk_size * w) / 8);
let init_r_slice = vec_init_r.as_slice();
let init_r_slice = vec_init_r;
let start = i * chunk_size;
let end = if i == (WORKERS - 1) {
@ -134,7 +134,7 @@ fn mandelbrot<W: old_io::Writer>(w: usize, mut out: W) -> old_io::IoResult<()> {
};
for &init_i in &vec_init_i[start..end] {
write_line(init_i, init_r_slice, &mut res);
write_line(init_i, &init_r_slice, &mut res);
}
res
@ -143,7 +143,7 @@ fn mandelbrot<W: old_io::Writer>(w: usize, mut out: W) -> old_io::IoResult<()> {
try!(writeln!(&mut out as &mut Writer, "P4\n{} {}", w, h));
for res in data {
try!(out.write(res.join().ok().unwrap().as_slice()));
try!(out.write(&res.join().ok().unwrap()));
}
out.flush()
}

View file

@ -103,7 +103,7 @@ struct Planet {
fn advance(bodies: &mut [Planet;N_BODIES], dt: f64, steps: int) {
for _ in 0..steps {
let mut b_slice = bodies.as_mut_slice();
let mut b_slice: &mut [_] = bodies;
loop {
let bi = match shift_mut_ref(&mut b_slice) {
Some(bi) => bi,

View file

@ -57,7 +57,7 @@ fn parse_opts(argv: Vec<String> ) -> Config {
let argv = argv.iter().map(|x| x.to_string()).collect::<Vec<_>>();
let opt_args = &argv[1..argv.len()];
match getopts::getopts(opt_args, opts.as_slice()) {
match getopts::getopts(opt_args, &opts) {
Ok(ref m) => {
return Config {stress: m.opt_present("stress")}
}

View file

@ -251,6 +251,6 @@ fn parallel<'a, I, T, F>(iter: I, f: F)
fn main() {
let mut data = read_to_end(&mut stdin_raw()).unwrap();
let tables = &Tables::new();
parallel(mut_dna_seqs(data.as_mut_slice()), |seq| reverse_complement(seq, tables));
stdout_raw().write(data.as_mut_slice()).unwrap();
parallel(mut_dna_seqs(&mut data), |seq| reverse_complement(seq, tables));
stdout_raw().write(&data).unwrap();
}

View file

@ -69,10 +69,10 @@ fn spectralnorm(n: uint) -> f64 {
let mut v = u.clone();
let mut tmp = v.clone();
for _ in 0u..10 {
mult_AtAv(u.as_slice(), v.as_mut_slice(), tmp.as_mut_slice());
mult_AtAv(v.as_slice(), u.as_mut_slice(), tmp.as_mut_slice());
mult_AtAv(&u, &mut v, &mut tmp);
mult_AtAv(&v, &mut u, &mut tmp);
}
(dot(u.as_slice(), v.as_slice()) / dot(v.as_slice(), v.as_slice())).sqrt()
(dot(&u, &v) / dot(&v, &v)).sqrt()
}
fn mult_AtAv(v: &[f64], out: &mut [f64], tmp: &mut [f64]) {

View file

@ -63,7 +63,7 @@ impl Sudoku {
.take(10).collect::<Vec<_>>();
for line in reader.lines() {
let line = line.unwrap();
let comps: Vec<&str> = line.as_slice()
let comps: Vec<&str> = line
.trim()
.split(',')
.collect();

View file

@ -33,7 +33,7 @@ fn b() {
let mut p = vec!(1);
borrow(
p.as_slice(),
&p,
|| p[0] = 5); //~ ERROR cannot borrow `p` as mutable
}
@ -41,7 +41,7 @@ fn c() {
// Legal because the scope of the borrow does not include the
// modification:
let mut p = vec!(1);
borrow(p.as_slice(), ||{});
borrow(&p, ||{});
p[0] = 5;
}

View file

@ -30,7 +30,7 @@ fn defer<'r>(x: &'r [&'r str]) -> defer<'r> {
}
fn main() {
let x = defer(vec!("Goodbye", "world!").as_slice());
let x = defer(&vec!("Goodbye", "world!"));
//~^ ERROR borrowed value does not live long enough
x.x[0];
}

View file

@ -21,7 +21,7 @@ pub fn main() {
Foo { string: "bar".to_string() },
Foo { string: "baz".to_string() }
);
let x: &[Foo] = x.as_slice();
let x: &[Foo] = &x;
match x {
[_, tail..] => {
match tail {

View file

@ -14,5 +14,5 @@ fn write(v: &mut [isize]) {
fn main() {
let v = vec!(1, 2, 3);
write(v.as_mut_slice()); //~ ERROR cannot borrow
write(&mut v); //~ ERROR cannot borrow
}

View file

@ -22,7 +22,7 @@ impl Index<String> for Foo {
type Output = isize;
fn index<'a>(&'a self, z: &String) -> &'a isize {
if z.as_slice() == "x" {
if *z == "x" {
&self.x
} else {
&self.y
@ -34,7 +34,7 @@ impl IndexMut<String> for Foo {
type Output = isize;
fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize {
if z.as_slice() == "x" {
if *z == "x" {
&mut self.x
} else {
&mut self.y

View file

@ -19,7 +19,7 @@ impl Index<String> for Foo {
type Output = isize;
fn index<'a>(&'a self, z: &String) -> &'a isize {
if z.as_slice() == "x" {
if *z == "x" {
&self.x
} else {
&self.y
@ -31,7 +31,7 @@ impl IndexMut<String> for Foo {
type Output = isize;
fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize {
if z.as_slice() == "x" {
if *z == "x" {
&mut self.x
} else {
&mut self.y

View file

@ -12,7 +12,7 @@
fn a<'a>() -> &'a [isize] {
let vec = vec!(1, 2, 3, 4);
let vec: &[isize] = vec.as_slice(); //~ ERROR does not live long enough
let vec: &[isize] = &vec; //~ ERROR does not live long enough
let tail = match vec {
[_, tail..] => tail,
_ => panic!("a")
@ -22,7 +22,7 @@ fn a<'a>() -> &'a [isize] {
fn b<'a>() -> &'a [isize] {
let vec = vec!(1, 2, 3, 4);
let vec: &[isize] = vec.as_slice(); //~ ERROR does not live long enough
let vec: &[isize] = &vec; //~ ERROR does not live long enough
let init = match vec {
[init.., _] => init,
_ => panic!("b")
@ -32,7 +32,7 @@ fn b<'a>() -> &'a [isize] {
fn c<'a>() -> &'a [isize] {
let vec = vec!(1, 2, 3, 4);
let vec: &[isize] = vec.as_slice(); //~ ERROR does not live long enough
let vec: &[isize] = &vec; //~ ERROR does not live long enough
let slice = match vec {
[_, slice.., _] => slice,
_ => panic!("c")

View file

@ -10,7 +10,7 @@
fn a() {
let mut v = vec!(1, 2, 3);
let vb: &mut [isize] = v.as_mut_slice();
let vb: &mut [isize] = &mut v;
match vb {
[_a, tail..] => {
v.push(tail[0] + tail[1]); //~ ERROR cannot borrow

View file

@ -22,7 +22,7 @@ fn a() {
fn b() {
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<isize>] = vec.as_mut_slice();
let vec: &mut [Box<isize>] = &mut vec;
match vec {
[_b..] => {
vec[0] = box 4; //~ ERROR cannot assign
@ -32,7 +32,7 @@ fn b() {
fn c() {
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<isize>] = vec.as_mut_slice();
let vec: &mut [Box<isize>] = &mut vec;
match vec {
[_a, //~ ERROR cannot move out
_b..] => { //~^ NOTE attempting to move value to here
@ -50,7 +50,7 @@ fn c() {
fn d() {
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<isize>] = vec.as_mut_slice();
let vec: &mut [Box<isize>] = &mut vec;
match vec {
[_a.., //~ ERROR cannot move out
_b] => {} //~ NOTE attempting to move value to here
@ -61,7 +61,7 @@ fn d() {
fn e() {
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<isize>] = vec.as_mut_slice();
let vec: &mut [Box<isize>] = &mut vec;
match vec {
[_a, _b, _c] => {} //~ ERROR cannot move out
//~^ NOTE attempting to move value to here

View file

@ -10,7 +10,7 @@
fn a<'a>() -> &'a isize {
let vec = vec!(1, 2, 3, 4);
let vec: &[isize] = vec.as_slice(); //~ ERROR `vec` does not live long enough
let vec: &[isize] = &vec; //~ ERROR `vec` does not live long enough
let tail = match vec {
[_a, tail..] => &tail[0],
_ => panic!("foo")

View file

@ -13,12 +13,12 @@ fn wants_slice(x: &str) { }
fn has_uniq(x: String) {
wants_uniq(x);
wants_slice(x.as_slice());
wants_slice(&*x);
}
fn has_slice(x: &str) {
wants_uniq(x); //~ ERROR mismatched types
wants_slice(x);
wants_slice(x.as_slice());
}
fn main() {

View file

@ -11,15 +11,15 @@
pub fn main() {
let v: Vec<isize> = vec!(0, 1, 2, 3, 4, 5);
let s: String = "abcdef".to_string();
v.as_slice()[3us];
v.as_slice()[3];
v.as_slice()[3u8]; //~ERROR the trait `core::ops::Index<u8>` is not implemented
v[3us];
v[3];
v[3u8]; //~ERROR the trait `core::ops::Index<u8>` is not implemented
//~^ ERROR the trait `core::ops::Index<u8>` is not implemented
v.as_slice()[3i8]; //~ERROR the trait `core::ops::Index<i8>` is not implemented
v[3i8]; //~ERROR the trait `core::ops::Index<i8>` is not implemented
//~^ ERROR the trait `core::ops::Index<i8>` is not implemented
v.as_slice()[3u32]; //~ERROR the trait `core::ops::Index<u32>` is not implemented
v[3u32]; //~ERROR the trait `core::ops::Index<u32>` is not implemented
//~^ ERROR the trait `core::ops::Index<u32>` is not implemented
v.as_slice()[3i32]; //~ERROR the trait `core::ops::Index<i32>` is not implemented
v[3i32]; //~ERROR the trait `core::ops::Index<i32>` is not implemented
//~^ ERROR the trait `core::ops::Index<i32>` is not implemented
s.as_bytes()[3us];
s.as_bytes()[3];

View file

@ -33,5 +33,5 @@ pub fn for_stdin<'a>() -> Container<'a> {
fn main() {
let mut c = for_stdin();
let mut v = Vec::new();
c.read_to(v.as_mut_slice());
c.read_to(v);
}

View file

@ -10,7 +10,7 @@
fn main() {
let sl = vec![1,2,3];
let v: isize = match sl.as_slice() {
let v: isize = match &*sl {
[] => 0,
[a,b,c] => 3,
[a, rest..] => a,

View file

@ -14,7 +14,7 @@ pub fn foo(params: Option<&[&str]>) -> usize {
fn main() {
let name = "Foo";
let x = Some(&[name.as_slice()]);
let x = Some(&[name]);
let msg = foo(x);
//~^ ERROR mismatched types
//~| expected `core::option::Option<&[&str]>`

View file

@ -100,7 +100,7 @@ impl TraversesWorld for Player {
impl Debug for Player {
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
formatter.write_str("Player{ name:");
formatter.write_str(self.name.as_slice());
formatter.write_str(&self.name);
formatter.write_str(" }");
Ok(())
}

View file

@ -16,14 +16,14 @@ pub fn opt_str0<'a>(maybestr: &'a Option<String>) -> &'a str {
if maybestr.is_none() {
"(none)"
} else {
let s: &'a str = maybestr.as_ref().unwrap().as_slice();
let s: &'a str = maybestr.as_ref().unwrap();
s
}
}
pub fn opt_str1<'a>(maybestr: &'a Option<String>) -> &'a str {
if maybestr.is_some() {
let s: &'a str = maybestr.as_ref().unwrap().as_slice();
let s: &'a str = maybestr.as_ref().unwrap();
s
} else {
"(none)"
@ -34,14 +34,14 @@ pub fn opt_str2<'a>(maybestr: &'a Option<String>) -> &'static str {
if maybestr.is_none() {
"(none)"
} else {
let s: &'a str = maybestr.as_ref().unwrap().as_slice();
let s: &'a str = maybestr.as_ref().unwrap();
s //~ ERROR cannot infer an appropriate lifetime for automatic coercion due to conflicting
}
}
pub fn opt_str3<'a>(maybestr: &'a Option<String>) -> &'static str {
if maybestr.is_some() {
let s: &'a str = maybestr.as_ref().unwrap().as_slice();
let s: &'a str = maybestr.as_ref().unwrap();
s //~ ERROR cannot infer an appropriate lifetime for automatic coercion due to conflicting
} else {
"(none)"

View file

@ -15,7 +15,7 @@
pub fn opt_str0<'a>(maybestr: &'a Option<String>) -> &'a str {
match *maybestr {
Some(ref s) => {
let s: &'a str = s.as_slice();
let s: &'a str = s;
s
}
None => "(none)",
@ -26,7 +26,7 @@ pub fn opt_str1<'a>(maybestr: &'a Option<String>) -> &'a str {
match *maybestr {
None => "(none)",
Some(ref s) => {
let s: &'a str = s.as_slice();
let s: &'a str = s;
s
}
}
@ -36,7 +36,7 @@ pub fn opt_str2<'a>(maybestr: &'a Option<String>) -> &'static str {
match *maybestr {
None => "(none)",
Some(ref s) => {
let s: &'a str = s.as_slice();
let s: &'a str = s;
s
//~^ ERROR cannot infer an appropriate lifetime
}
@ -46,7 +46,7 @@ pub fn opt_str2<'a>(maybestr: &'a Option<String>) -> &'static str {
pub fn opt_str3<'a>(maybestr: &'a Option<String>) -> &'static str {
match *maybestr {
Some(ref s) => {
let s: &'a str = s.as_slice();
let s: &'a str = s;
s
//~^ ERROR cannot infer an appropriate lifetime
}

View file

@ -11,7 +11,7 @@
fn main() {
let x: Vec<(isize, isize)> = Vec::new();
let x: &[(isize, isize)] = x.as_slice();
let x: &[(isize, isize)] = &x;
match x {
[a, (2, 3), _] => (),
[(1, 2), (2, 3), b] => (), //~ ERROR unreachable pattern
@ -21,7 +21,7 @@ fn main() {
let x: Vec<String> = vec!["foo".to_string(),
"bar".to_string(),
"baz".to_string()];
let x: &[String] = x.as_slice();
let x: &[String] = &x;
match x {
[a, _, _, ..] => { println!("{}", a); }
[_, _, _, _, _] => { } //~ ERROR unreachable pattern
@ -29,7 +29,7 @@ fn main() {
}
let x: Vec<char> = vec!('a', 'b', 'c');
let x: &[char] = x.as_slice();
let x: &[char] = &x;
match x {
['a', 'b', 'c', _tail..] => {}
['a', 'b', 'c'] => {} //~ ERROR unreachable pattern

View file

@ -95,7 +95,7 @@ fn f110() {
fn f120() {
let mut x = vec!("hi".to_string(), "ho".to_string());
x.as_mut_slice().swap(0, 1);
x.swap(0, 1);
touch(&x[0]);
touch(&x[1]);
}

View file

@ -36,20 +36,20 @@ fn main() {
(t::b, t::b) => {}
}
let vec = vec!(Some(42), None, Some(21));
let vec: &[Option<isize>] = vec.as_slice();
let vec: &[Option<isize>] = &vec;
match vec { //~ ERROR non-exhaustive patterns: `[]` not covered
[Some(..), None, tail..] => {}
[Some(..), Some(..), tail..] => {}
[None] => {}
}
let vec = vec!(1);
let vec: &[isize] = vec.as_slice();
let vec: &[isize] = &vec;
match vec {
[_, tail..] => (),
[] => ()
}
let vec = vec!(0.5f32);
let vec: &[f32] = vec.as_slice();
let vec: &[f32] = &vec;
match vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered
[0.1, 0.2, 0.3] => (),
[0.1, 0.2] => (),
@ -57,7 +57,7 @@ fn main() {
[] => ()
}
let vec = vec!(Some(42), None, Some(21));
let vec: &[Option<isize>] = vec.as_slice();
let vec: &[Option<isize>] = &vec;
match vec {
[Some(..), None, tail..] => {}
[Some(..), Some(..), tail..] => {}

View file

@ -35,5 +35,5 @@ mod argparse {
fn main () {
let f : argparse::Flag = argparse::flag("flag", "My flag");
let updated_flag = f.set_desc("My new flag");
assert_eq!(updated_flag.desc.as_slice(), "My new flag");
assert_eq!(updated_flag.desc, "My new flag");
}

View file

@ -12,7 +12,7 @@ fn assert_send<T: Send>(_t: T) {}
fn main() {
let line = String::new();
match [line.as_slice()] { //~ ERROR `line` does not live long enough
match [&*line] { //~ ERROR `line` does not live long enough
[ word ] => { assert_send(word); }
}
}

View file

@ -26,7 +26,7 @@ impl Trait<&'static str> for Struct {
fn main() {
let person = "Fred".to_string();
let person: &str = person.as_slice(); //~ ERROR `person` does not live long enough
let person: &str = &person; //~ ERROR `person` does not live long enough
let s: Box<Trait<&'static str>> = box Struct { person: person };
}

View file

@ -283,9 +283,9 @@ fn main() {
let fixed_size_vec2 = ([0u, 1u, 2u], 0i16);
let vec1 = vec![0u, 2u, 3u];
let slice1 = vec1.as_slice();
let slice1 = &*vec1;
let vec2 = vec![Mod1::Variant2_2(Struct1)];
let slice2 = vec2.as_slice();
let slice2 = &*vec2;
// Trait Objects
let box_trait = (box 0) as Box<Trait1>;

View file

@ -29,12 +29,12 @@ fn main() {
idx as uint);
// This should panic.
println!("ov3 0x%x", x.as_slice()[idx]);
println!("ov3 0x%x", x[idx]);
}
#[cfg(any(target_arch="x86_64", target_arch = "aarch64"))]
fn main() {
// This version just panics anyways, for symmetry on 64-bit hosts.
let x = vec!(1u,2u,3u);
error!("ov3 0x%x", x.as_slice()[200]);
error!("ov3 0x%x", x[200]);
}

View file

@ -17,8 +17,8 @@ use std::old_io::{File, Command};
fn main() {
let args = os::args();
let rustc = args[1].as_slice();
let tmpdir = Path::new(args[2].as_slice());
let rustc = &args[1];
let tmpdir = Path::new(&args[2]);
let main_file = tmpdir.join("broken.rs");
let _ = File::create(&main_file).unwrap()
@ -31,12 +31,12 @@ fn main() {
// can't exec it directly
let result = Command::new("sh")
.arg("-c")
.arg(format!("{} {}",
rustc,
main_file.as_str()
.unwrap()).as_slice())
.arg(&format!("{} {}",
rustc,
main_file.as_str()
.unwrap()))
.output().unwrap();
let err = String::from_utf8_lossy(result.error.as_slice());
let err = String::from_utf8_lossy(&result.error);
// positive test so that this test will be updated when the
// compiler changes.

View file

@ -28,9 +28,9 @@ fn main() {
panic!("expected rustc path");
}
let tmpdir = Path::new(args[1].as_slice());
let tmpdir = Path::new(&args[1]);
let mut sysroot = Path::new(args[3].as_slice());
let mut sysroot = Path::new(&args[3]);
sysroot.pop();
sysroot.pop();

View file

@ -106,7 +106,7 @@ trait SomeTrait: SuperTrait {
fn Method(&self, x: u32) -> u32;
fn prov(&self, x: u32) -> u32 {
println(x.to_string().as_slice());
println(&x.to_string());
42
}
fn provided_method(&self) -> u32 {
@ -122,7 +122,7 @@ trait SubTrait: SomeTrait {
impl SomeTrait for some_fields {
fn Method(&self, x: u32) -> u32 {
println(x.to_string().as_slice());
println(&x.to_string());
self.field1
}
}
@ -134,7 +134,7 @@ impl SubTrait for some_fields {}
impl some_fields {
fn stat(x: u32) -> u32 {
println(x.to_string().as_slice());
println(&x.to_string());
42
}
fn stat2(x: &some_fields) -> u32 {
@ -194,20 +194,20 @@ enum SomeStructEnum {
fn matchSomeEnum(val: SomeEnum) {
match val {
SomeEnum::Ints(int1, int2) => { println((int1+int2).to_string().as_slice()); }
SomeEnum::Floats(float1, float2) => { println((float2*float1).to_string().as_slice()); }
SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); }
SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); }
SomeEnum::Strings(_, _, s3) => { println(s3); }
SomeEnum::MyTypes(mt1, mt2) => {
println((mt1.field1 - mt2.field1).to_string().as_slice());
println(&(mt1.field1 - mt2.field1).to_string());
}
}
}
fn matchSomeStructEnum(se: SomeStructEnum) {
match se {
SomeStructEnum::EnumStruct{a:a, ..} => println(a.to_string().as_slice()),
SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(f_2.field1.to_string().as_slice()),
SomeStructEnum::EnumStruct3{f1, ..} => println(f1.field1.to_string().as_slice()),
SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()),
SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()),
SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()),
}
}
@ -215,9 +215,9 @@ fn matchSomeStructEnum(se: SomeStructEnum) {
fn matchSomeStructEnum2(se: SomeStructEnum) {
use SomeStructEnum::*;
match se {
EnumStruct{a: ref aaa, ..} => println(aaa.to_string().as_slice()),
EnumStruct2{f1, f2: f2} => println(f1.field1.to_string().as_slice()),
EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println(f1.field1.to_string().as_slice()),
EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()),
EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()),
EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println(&f1.field1.to_string()),
_ => {},
}
}
@ -233,12 +233,12 @@ fn matchSomeOtherEnum(val: SomeOtherEnum) {
fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
SameDir2::hello(43);
println(yy.to_string().as_slice());
println(&yy.to_string());
let (x, y): (u32, u32) = (5, 3);
println(x.to_string().as_slice());
println(z.to_string().as_slice());
println(&x.to_string());
println(&z.to_string());
let x: u32 = x;
println(x.to_string().as_slice());
println(&x.to_string());
let x = "hello";
println(x);
@ -311,7 +311,7 @@ fn main() { // foo
let s3: some_fields = some_fields{ field1: 55};
let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55};
let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55};
println(s2.field1.to_string().as_slice());
println(&s2.field1.to_string());
let s5: MyType = box some_fields{ field1: 55};
let s = SameDir::SameStruct{name: "Bob".to_string()};
let s = SubDir::SubStruct{name:"Bob".to_string()};

View file

@ -34,8 +34,8 @@ fn random_char() -> char {
fn main() {
let args = os::args();
let rustc = args[1].as_slice();
let tmpdir = Path::new(args[2].as_slice());
let rustc = &args[1];
let tmpdir = Path::new(&args[2]);
let main_file = tmpdir.join("unicode_input_multiple_files_main.rs");
{
@ -56,12 +56,12 @@ fn main() {
// can't exec it directly
let result = Command::new("sh")
.arg("-c")
.arg(format!("{} {}",
rustc,
main_file.as_str()
.unwrap()).as_slice())
.arg(&format!("{} {}",
rustc,
main_file.as_str()
.unwrap()))
.output().unwrap();
let err = String::from_utf8_lossy(result.error.as_slice());
let err = String::from_utf8_lossy(&result.error);
// positive test so that this test will be updated when the
// compiler changes.

View file

@ -34,8 +34,8 @@ fn random_char() -> char {
fn main() {
let args = os::args();
let rustc = args[1].as_slice();
let tmpdir = Path::new(args[2].as_slice());
let rustc = &args[1];
let tmpdir = Path::new(&args[2]);
let main_file = tmpdir.join("span_main.rs");
for _ in 0u..100 {
@ -52,18 +52,18 @@ fn main() {
// can't exec it directly
let result = Command::new("sh")
.arg("-c")
.arg(format!("{} {}",
rustc,
main_file.as_str()
.unwrap()).as_slice())
.arg(&format!("{} {}",
rustc,
main_file.as_str()
.unwrap()))
.output().unwrap();
let err = String::from_utf8_lossy(result.error.as_slice());
let err = String::from_utf8_lossy(&result.error);
// the span should end the line (e.g no extra ~'s)
let expected_span = format!("^{}\n", repeat("~").take(n - 1)
.collect::<String>());
assert!(err.contains(expected_span.as_slice()));
assert!(err.contains(&expected_span));
}
// Test multi-column characters and tabs

View file

@ -47,7 +47,7 @@ pub fn main() {
assert_eq!(length(x.clone()), x.len());
// Call a parameterized function, with type arguments that require
// a borrow
assert_eq!(length::<int, &[int]>(x.as_slice()), x.len());
assert_eq!(length::<int, &[int]>(&*x), x.len());
// Now try it with a type that *needs* to be borrowed
let z = [0,1,2,3];

View file

@ -36,7 +36,7 @@ impl<'a, A, B, Lhs> MyEq<[B; 0]> for Lhs
where A: MyEq<B>, Lhs: Deref<Target=[A]>
{
fn eq(&self, other: &[B; 0]) -> bool {
MyEq::eq(&**self, other.as_slice())
MyEq::eq(&**self, other)
}
}

View file

@ -48,7 +48,7 @@ fn runtest(me: &str) {
let p = template.clone().arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(out.error.as_slice()).unwrap();
let s = str::from_utf8(&out.error).unwrap();
assert!(s.contains("stack backtrace") && s.contains("foo::h"),
"bad output: {}", s);
@ -56,7 +56,7 @@ fn runtest(me: &str) {
let p = template.clone().arg("fail").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(out.error.as_slice()).unwrap();
let s = str::from_utf8(&out.error).unwrap();
assert!(!s.contains("stack backtrace") && !s.contains("foo::h"),
"bad output2: {}", s);
@ -64,7 +64,7 @@ fn runtest(me: &str) {
let p = template.clone().arg("double-fail").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(out.error.as_slice()).unwrap();
let s = str::from_utf8(&out.error).unwrap();
// loosened the following from double::h to double:: due to
// spurious failures on mac, 32bit, optimized
assert!(s.contains("stack backtrace") && s.contains("double::"),
@ -75,7 +75,7 @@ fn runtest(me: &str) {
.env("RUST_BACKTRACE", "1").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(out.error.as_slice()).unwrap();
let s = str::from_utf8(&out.error).unwrap();
let mut i = 0;
for _ in 0..2 {
i += s[i + 10..].find_str("stack backtrace").unwrap() + 10;
@ -86,12 +86,12 @@ fn runtest(me: &str) {
fn main() {
let args = os::args();
let args = args.as_slice();
if args.len() >= 2 && args[1].as_slice() == "fail" {
let args = args;
if args.len() >= 2 && args[1] == "fail" {
foo();
} else if args.len() >= 2 && args[1].as_slice() == "double-fail" {
} else if args.len() >= 2 && args[1] == "double-fail" {
double();
} else {
runtest(args[0].as_slice());
runtest(&args[0]);
}
}

View file

@ -26,13 +26,13 @@ fn call_g<G:FnMut(String,String) -> String>(mut g: G, x: String, y: String)
}
fn g(mut x: String, y: String) -> String {
x.push_str(y.as_slice());
x.push_str(&y);
x
}
fn main() {
call_f(f);
assert_eq!(call_g(g, "foo".to_string(), "bar".to_string()).as_slice(),
assert_eq!(call_g(g, "foo".to_string(), "bar".to_string()),
"foobar");
}

View file

@ -53,9 +53,9 @@ fn main() {
assert_eq!(!false, true);
let s = false.to_string();
assert_eq!(s.as_slice(), "false");
assert_eq!(s, "false");
let s = true.to_string();
assert_eq!(s.as_slice(), "true");
assert_eq!(s, "true");
assert!(true > false);
assert!(!(false > true));

View file

@ -19,7 +19,7 @@ pub fn main() {
match x {
F {f: ref mut v} => {
impure(v.as_slice());
impure(v);
}
}
}

View file

@ -16,7 +16,7 @@ fn want_slice(v: &[int]) -> int {
}
fn has_mut_vec(v: Vec<int> ) -> int {
want_slice(v.as_slice())
want_slice(&v)
}
pub fn main() {

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn foo(s: &String) -> bool {
match s.as_slice() {
match &**s {
"kitty" => true,
_ => false
}

View file

@ -44,7 +44,7 @@ fn get_bar(x: uint) -> Vec<uint> { vec!(x * 2) }
pub fn fails() {
let x = 2;
let mut y = Vec::new();
y.push(box Conzabble::Bickwick(do_it(get_bar(x).as_slice())));
y.push(box Conzabble::Bickwick(do_it(&get_bar(x))));
}
pub fn main() {

View file

@ -24,7 +24,7 @@ use std::os;
pub fn main() {
let args = os::args();
let args = args.as_slice();
let args = args;
// Here, the rvalue `"signal".to_string()` requires cleanup. Older versions
// of the code had a problem that the cleanup scope for this
@ -32,7 +32,7 @@ pub fn main() {
// expression was never evaluated, we wound up trying to clean
// uninitialized memory.
if args.len() >= 2 && args[1].as_slice() == "signal" {
if args.len() >= 2 && args[1] == "signal" {
// Raise a segfault.
unsafe { *(0 as *mut int) = 0; }
}

View file

@ -19,6 +19,6 @@ fn bip(v: &[uint]) -> Vec<uint> {
pub fn main() {
let mut the_vec = vec!(1u, 2, 3, 100);
assert_eq!(the_vec.clone(), bar(the_vec.as_mut_slice()));
assert_eq!(the_vec.clone(), bip(the_vec.as_slice()));
assert_eq!(the_vec.clone(), bar(&mut the_vec));
assert_eq!(the_vec.clone(), bip(&the_vec));
}

View file

@ -21,6 +21,6 @@ fn bar(v: &mut [uint]) {
pub fn main() {
let mut the_vec = vec!(1, 2, 3, 100);
bar(the_vec.as_mut_slice());
bar(&mut the_vec);
assert_eq!(the_vec, vec!(100, 3, 2, 1));
}

View file

@ -17,6 +17,6 @@ fn bar(v: &mut [uint]) {
pub fn main() {
let mut the_vec = vec!(1, 2, 3, 100);
bar(the_vec.as_mut_slice());
bar(&mut the_vec);
assert_eq!(the_vec, vec!(100, 3, 2, 1));
}

View file

@ -25,6 +25,6 @@ struct A {
fn main() {
let obj = A { foo: box [true, false] };
let s = json::encode(&obj).unwrap();
let obj2: A = json::decode(s.as_slice()).unwrap();
let obj2: A = json::decode(&s).unwrap();
assert!(obj.foo == obj2.foo);
}

View file

@ -36,7 +36,7 @@ fn main() {
bar: RefCell::new( A { baz: 2 } )
};
let s = json::encode(&obj).unwrap();
let obj2: B = json::decode(s.as_slice()).unwrap();
let obj2: B = json::decode(&s).unwrap();
assert!(obj.foo.get() == obj2.foo.get());
assert!(obj.bar.borrow().baz == obj2.bar.borrow().baz);
}

View file

@ -16,7 +16,7 @@ pub fn main() {
let args = Vec::new();
let opts = vec!(optopt("b", "", "something", "SMTHNG"));
match getopts(args.as_slice(), opts.as_slice()) {
match getopts(&args, &opts) {
Ok(ref m) =>
assert!(!m.opt_present("b")),
Err(ref f) => panic!("{}", *f)

View file

@ -84,8 +84,7 @@ mod map_reduce {
ctrl_proto::mapper_done => { num_mappers -= 1; }
ctrl_proto::find_reducer(k, cc) => {
let mut c;
match reducers.get(&str::from_utf8(
k.as_slice()).unwrap().to_string()) {
match reducers.get(&str::from_utf8(&k).unwrap().to_string()) {
Some(&_c) => { c = _c; }
None => { c = 0; }
}

View file

@ -50,7 +50,7 @@ pub fn main() {
} else if let Foo::Two(_x) = foo {
panic!("bad pattern match");
} else if let Foo::Three(s, _) = foo {
assert_eq!(s.as_slice(), "three");
assert_eq!(s, "three");
} else {
panic!("bad else");
}

View file

@ -39,7 +39,7 @@ impl fmt::Display for C {
}
macro_rules! t {
($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) }
($a:expr, $b:expr) => { assert_eq!($a, $b) }
}
pub fn main() {

View file

@ -15,7 +15,7 @@ fn bad(a: &str, b: &str) {
}
fn good(a: &str, b: &str) {
foo(&[a.as_slice(), b.as_slice()]);
foo(&[a, b]);
}
fn main() {}

View file

@ -17,8 +17,8 @@ use std::old_io::process;
pub fn main () {
let args = os::args();
let args = args.as_slice();
if args.len() > 1 && args[1].as_slice() == "child" {
let args = args;
if args.len() > 1 && args[1] == "child" {
for _ in 0..1000 {
println!("hello?");
}
@ -28,7 +28,7 @@ pub fn main () {
return;
}
let mut p = process::Command::new(args[0].as_slice());
let mut p = process::Command::new(&args[0]);
p.arg("child").stdout(process::Ignored).stderr(process::Ignored);
println!("{:?}", p.spawn().unwrap().wait());
}

View file

@ -13,7 +13,7 @@ use std::ascii::AsciiExt;
static NAME: &'static str = "hello world";
fn main() {
match NAME.to_ascii_lowercase().as_slice() {
match &*NAME.to_ascii_lowercase() {
"foo" => {}
_ => {}
}

View file

@ -13,7 +13,7 @@ struct A {
}
fn borrow<'a>(binding: &'a A) -> &'a str {
match binding.a.as_slice() {
match &*binding.a {
"in" => "in_",
"ref" => "ref_",
ident => ident

View file

@ -179,7 +179,7 @@ fn misc() {
// This test basically mimics how trace_macros! macro is implemented,
// which is a rare combination of vector patterns, multiple wild-card
// patterns and guard functions.
let r = match [Foo::Bar(0, false)].as_slice() {
let r = match [Foo::Bar(0, false)] {
[Foo::Bar(_, pred)] if pred => 1,
[Foo::Bar(_, pred)] if !pred => 2,
_ => 0,

View file

@ -16,8 +16,8 @@ use std::str;
fn main() {
let args = os::args();
let args = args.as_slice();
if args.len() > 1 && args[1].as_slice() == "child" {
let args = args;
if args.len() > 1 && args[1] == "child" {
child();
} else {
parent();
@ -26,13 +26,13 @@ fn main() {
fn parent() {
let args = os::args();
let args = args.as_slice();
let mut p = old_io::process::Command::new(args[0].as_slice())
let args = args;
let mut p = old_io::process::Command::new(&args[0])
.arg("child").spawn().unwrap();
p.stdin.as_mut().unwrap().write_str("test1\ntest2\ntest3").unwrap();
let out = p.wait_with_output().unwrap();
assert!(out.status.success());
let s = str::from_utf8(out.output.as_slice()).unwrap();
let s = str::from_utf8(&out.output).unwrap();
assert_eq!(s, "test1\n\ntest2\n\ntest3\n");
}

View file

@ -21,7 +21,7 @@ impl StrWrap {
}
fn get_s<'a>(&'a self) -> &'a str {
self.s.as_slice()
&self.s
}
}

View file

@ -22,7 +22,7 @@ pub fn main() {
let obj = UnitLikeStruct;
let json_str: String = json::encode(&obj).unwrap();
let json_object = json::from_str(json_str.as_slice());
let json_object = json::from_str(&json_str);
let mut decoder = json::Decoder::new(json_object.unwrap());
let mut decoded_obj: UnitLikeStruct = Decodable::decode(&mut decoder).unwrap();

View file

@ -16,7 +16,7 @@ use std::os;
fn main() {
let args = os::args();
if args.len() > 1 && args[1].as_slice() == "child" {
if args.len() > 1 && args[1] == "child" {
return child()
}
@ -32,7 +32,7 @@ fn child() {
fn test() {
let args = os::args();
let mut p = Command::new(args[0].as_slice()).arg("child")
let mut p = Command::new(&args[0]).arg("child")
.stdin(process::Ignored)
.stdout(process::Ignored)
.stderr(process::Ignored)

View file

@ -31,7 +31,7 @@ macro_rules! demo {
}
assert_eq!((x,y), (1,1));
let b: &[_] = &["out", "in"];
assert_eq!(history.as_slice(), b);
assert_eq!(history, b);
}
}
}

View file

@ -17,7 +17,7 @@ fn main() {
let mut out = stdio::stdout();
out.write(&['a' as u8; 128 * 1024]).unwrap();
} else {
let out = Command::new(args[0].as_slice()).arg("child").output();
let out = Command::new(&args[0]).arg("child").output();
let out = out.unwrap();
assert!(out.status.success());
}

View file

@ -17,7 +17,7 @@ use std::rand::random;
fn main() {
// If we're the child, make sure we were invoked correctly
let args = os::args();
if args.len() > 1 && args[1].as_slice() == "child" {
if args.len() > 1 && args[1] == "child" {
// FIXME: This should check the whole `args[0]` instead of just
// checking that it ends_with the executable name. This
// is needed because of Windows, which has a different behavior.
@ -45,9 +45,9 @@ fn test() {
// Append the new directory to our own PATH.
let mut path = os::split_paths(os::getenv("PATH").unwrap_or(String::new()));
path.push(child_dir.clone());
let path = os::join_paths(path.as_slice()).unwrap();
let path = os::join_paths(&path).unwrap();
let child_output = Command::new("mytest").env("PATH", path.as_slice())
let child_output = Command::new("mytest").env("PATH", path)
.arg("child")
.output().unwrap();

View file

@ -10,5 +10,5 @@
pub fn main() {
let x = [1, 2, 3];
let y = x.as_slice();
let y = x;
}

View file

@ -21,6 +21,6 @@ fn main() {
// There is currently no safe way to construct a `Box<str>`, so improvise
let box_arr: Box<[u8]> = box ['h' as u8, 'e' as u8, 'l' as u8, 'l' as u8, 'o' as u8];
let box_str: Box<str> = unsafe { std::mem::transmute(box_arr) };
assert_eq!(box_str.as_slice(), "hello");
assert_eq!(&*box_str, "hello");
f(box_str);
}

View file

@ -11,7 +11,7 @@
const X: &'static str = "12345";
fn test(s: String) -> bool {
match s.as_slice() {
match &*s {
X => true,
_ => false
}

View file

@ -24,6 +24,6 @@ pub fn main() {
let mut table = HashMap::new();
table.insert("one".to_string(), 1);
table.insert("two".to_string(), 2);
assert!(check_strs(format!("{:?}", table).as_slice(), "HashMap {\"one\": 1, \"two\": 2}") ||
check_strs(format!("{:?}", table).as_slice(), "HashMap {\"two\": 2, \"one\": 1}"));
assert!(check_strs(&format!("{:?}", table), "HashMap {\"one\": 1, \"two\": 2}") ||
check_strs(&format!("{:?}", table), "HashMap {\"two\": 2, \"one\": 1}"));
}

View file

@ -162,7 +162,7 @@ pub fn check_strs(actual: &str, expected: &str) -> bool {
fn test_ascii_art_ctor() {
let art = AsciiArt(3, 3, '*');
assert!(check_strs(art.to_string().as_slice(), "...\n...\n..."));
assert!(check_strs(&art.to_string(), "...\n...\n..."));
}
@ -171,7 +171,7 @@ fn test_add_pt() {
art.add_pt(0, 0);
art.add_pt(0, -10);
art.add_pt(1, 2);
assert!(check_strs(art.to_string().as_slice(), "*..\n...\n.*."));
assert!(check_strs(&art.to_string(), "*..\n...\n.*."));
}
@ -179,7 +179,7 @@ fn test_shapes() {
let mut art = AsciiArt(4, 4, '*');
art.add_rect(Rect {top_left: Point {x: 0, y: 0}, size: Size {width: 4, height: 4}});
art.add_point(Point {x: 2, y: 2});
assert!(check_strs(art.to_string().as_slice(), "****\n*..*\n*.**\n****"));
assert!(check_strs(&art.to_string(), "****\n*..*\n*.**\n****"));
}
pub fn main() {

View file

@ -10,11 +10,11 @@
fn parse_args() -> String {
let args = ::std::os::args();
let args = args.as_slice();
let args = args;
let mut n = 0;
while n < args.len() {
match args[n].as_slice() {
match &*args[n] {
"-v" => (),
s => {
return s.to_string();

View file

@ -12,6 +12,6 @@
pub fn main() {
let s: String = "foobar".to_string();
let mut t: &str = s.as_slice();
let mut t: &str = &s;
t = &t[0..3]; // for master: str::view(t, 0, 3) maybe
}

View file

@ -19,5 +19,5 @@ pub fn main() {
a: &["test".to_string()],
b: Some(b),
};
assert_eq!(a.b.as_ref().unwrap()[0].as_slice(), "foo");
assert_eq!(a.b.as_ref().unwrap()[0], "foo");
}

View file

@ -34,7 +34,7 @@ pub fn main() {
bar: box 32,
};
Thing1 {
baz: Vec::new().as_slice(),
baz: &Vec::new(),
bar: box 32,
};
let _t2_fixed = Thing2 {
@ -42,7 +42,7 @@ pub fn main() {
bar: 32,
};
Thing2 {
baz: Vec::new().as_slice(),
baz: &Vec::new(),
bar: 32,
};
}

View file

@ -37,19 +37,19 @@ fn test_heap_log() {
fn test_append() {
let mut s = String::new();
s.push_str("a");
assert_eq!(s.as_slice(), "a");
assert_eq!(s, "a");
let mut s = String::from_str("a");
s.push_str("b");
println!("{}", s.clone());
assert_eq!(s.as_slice(), "ab");
assert_eq!(s, "ab");
let mut s = String::from_str("c");
s.push_str("offee");
assert!(s.as_slice() == "coffee");
assert!(s == "coffee");
s.push_str("&tea");
assert!(s.as_slice() == "coffee&tea");
assert!(s == "coffee&tea");
}
pub fn main() {

View file

@ -17,6 +17,6 @@ struct Refs { refs: Vec<int> , n: int }
pub fn main() {
let mut e = Refs{refs: vec!(), n: 0};
let _f = || println!("{}", e.n);
let x: &[int] = e.refs.as_slice();
let x: &[int] = &e.refs;
assert_eq!(x.len(), 0);
}

View file

@ -21,18 +21,18 @@ use std::str;
fn main() {
let args = os::args();
let args = args.as_slice();
if args.len() > 1 && args[1].as_slice() == "child" {
let args = args;
if args.len() > 1 && args[1] == "child" {
debug!("foo");
debug!("bar");
return
}
let p = Command::new(args[0].as_slice())
let p = Command::new(&args[0])
.arg("child")
.spawn().unwrap().wait_with_output().unwrap();
assert!(p.status.success());
let mut lines = str::from_utf8(p.error.as_slice()).unwrap().lines();
let mut lines = str::from_utf8(&p.error).unwrap().lines();
assert!(lines.next().unwrap().contains("foo"));
assert!(lines.next().unwrap().contains("bar"));
}

View file

@ -18,8 +18,8 @@ pub fn main() {
match t::tag1("test".to_string()) {
t::tag2 => panic!(),
t::tag1(ref s) if "test" != s.as_slice() => panic!(),
t::tag1(ref s) if "test" == s.as_slice() => (),
t::tag1(ref s) if "test" != &**s => panic!(),
t::tag1(ref s) if "test" == &**s => (),
_ => panic!()
}

View file

@ -41,7 +41,7 @@ fn main() {
let mut buf = [0_u8; 6];
{
let mut writer = buf.as_mut_slice();
let mut writer: &mut [_] = &mut buf;
writer.my_write(&[0, 1, 2]).unwrap();
writer.my_write(&[3, 4, 5]).unwrap();
}

View file

@ -31,5 +31,5 @@ pub fn main() {
sb.append("Hello, ");
sb.append("World!");
let str = to_string(sb);
assert_eq!(str.as_slice(), "Hello, World!");
assert_eq!(str, "Hello, World!");
}

Some files were not shown because too many files have changed in this diff Show more