Use temp vars for implicit coercion to ^[T]

This commit is contained in:
Nick Cameron 2014-08-04 14:19:02 +02:00
parent 34d607f9c9
commit 37a94b80f2
31 changed files with 381 additions and 215 deletions

View file

@ -100,7 +100,8 @@ fn main() {
let mut rand = Vec::with_capacity(n_keys);
{
let mut rng: IsaacRng = SeedableRng::from_seed(&[1, 1, 1, 1, 1, 1, 1]);
let seed: &[_] = &[1, 1, 1, 1, 1, 1, 1];
let mut rng: IsaacRng = SeedableRng::from_seed(seed);
let mut set = HashSet::new();
while set.len() != n_keys {
let next = rng.gen();

View file

@ -164,7 +164,7 @@ fn main() {
}
};
let seed = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let max = 200000;
{

View file

@ -37,13 +37,16 @@ pub fn main() {
_ => fail!()
}
assert_eq!(b"a\n\r\t\\\'\"\0\xF0",
&[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8]);
let expected: &[_] = &[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8];
assert_eq!(b"a\n\r\t\\\'\"\0\xF0", expected);
let expected: &[_] = &[97u8, 98u8];
assert_eq!(b"a\
b", &[97u8, 98u8]);
assert_eq!(BAR, &[97u8, 240u8, 9u8]);
b", expected);
let expected: &[_] = &[97u8, 240u8, 9u8];
assert_eq!(BAR, expected);
match &[97u8, 10u8] {
let val: &[_] = &[97u8, 10u8];
match val {
b"a\n" => {},
_ => fail!(),
}
@ -55,9 +58,12 @@ pub fn main() {
_ => 3u
}, 2);
assert_eq!(BAZ, &[97u8, 92u8, 110u8]);
assert_eq!(br"a\n", &[97u8, 92u8, 110u8]);
let expected: &[_] = &[97u8, 92u8, 110u8];
assert_eq!(BAZ, expected);
let expected: &[_] = &[97u8, 92u8, 110u8];
assert_eq!(br"a\n", expected);
assert_eq!(br"a\n", b"a\\n");
assert_eq!(br###"a"##b"###, &[97u8, 34u8, 35u8, 35u8, 98u8]);
let expected: &[_] = &[97u8, 34u8, 35u8, 35u8, 98u8];
assert_eq!(br###"a"##b"###, expected);
assert_eq!(br###"a"##b"###, b"a\"##b");
}

View file

@ -43,14 +43,22 @@ fn main() {
let args = os::args();
let me = args.get(0).as_slice();
pass(Command::new(me).arg(&[1u8]).output().unwrap());
pass(Command::new(me).arg(&[2u8]).output().unwrap());
pass(Command::new(me).arg(&[3u8]).output().unwrap());
pass(Command::new(me).arg(&[4u8]).output().unwrap());
pass(Command::new(me).arg(&[5u8]).output().unwrap());
pass(Command::new(me).arg(&[6u8]).output().unwrap());
pass(Command::new(me).arg(&[7u8]).output().unwrap());
pass(Command::new(me).arg(&[8u8]).output().unwrap());
let x: &[u8] = &[1u8];
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[2u8];
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[3u8];
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[4u8];
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[5u8];
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[6u8];
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[7u8];
pass(Command::new(me).arg(x).output().unwrap());
let x: &[u8] = &[8u8];
pass(Command::new(me).arg(x).output().unwrap());
}
fn pass(output: ProcessOutput) {

View file

@ -12,13 +12,17 @@ static static_vec: &'static [u8] = bytes!("abc", 0xFF, '!');
pub fn main() {
let vec = bytes!("abc");
assert_eq!(vec, &[97_u8, 98_u8, 99_u8]);
let expected: &[u8] = &[97_u8, 98_u8, 99_u8];
assert_eq!(vec, expected);
let vec = bytes!("null", 0);
assert_eq!(vec, &[110_u8, 117_u8, 108_u8, 108_u8, 0_u8]);
let expected: &[u8] = &[110_u8, 117_u8, 108_u8, 108_u8, 0_u8];
assert_eq!(vec, expected);
let vec = bytes!(' ', " ", 32, 32u8);
assert_eq!(vec, &[32_u8, 32_u8, 32_u8, 32_u8]);
let expected: &[u8] = &[32_u8, 32_u8, 32_u8, 32_u8];
assert_eq!(vec, expected);
assert_eq!(static_vec, &[97_u8, 98_u8, 99_u8, 255_u8, 33_u8]);
let expected: &[u8] = &[97_u8, 98_u8, 99_u8, 255_u8, 33_u8];
assert_eq!(static_vec, expected);
}

View file

@ -15,10 +15,11 @@ static CONSTEXPR: *const int = &413 as *const _;
pub fn main() {
let x: Vec<_> = range(0u, 5).collect();
assert_eq!(x.as_slice(), &[0u,1,2,3,4]);
let expected: &[uint] = &[0,1,2,3,4];
assert_eq!(x.as_slice(), expected);
let x = range(0u, 5).collect::<Vec<_>>();
assert_eq!(x.as_slice(), &[0u,1,2,3,4]);
assert_eq!(x.as_slice(), expected);
let y: _ = "hello";
assert_eq!(y.len(), 5);

View file

@ -10,6 +10,7 @@
pub fn main() {
let x = &[1i, 2, 3, 4, 5];
let x: &[int] = &[1, 2, 3, 4, 5];
if !x.is_empty() {
let el = match x {
[1, ..ref tail] => &tail[0],

View file

@ -23,12 +23,14 @@ fn b() {
[a, b, ..c] => {
assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(c, &[3]);
let expected: &[_] = &[3];
assert_eq!(c, expected);
}
}
match x {
[..a, b, c] => {
assert_eq!(a, &[1]);
let expected: &[_] = &[1];
assert_eq!(a, expected);
assert_eq!(b, 2);
assert_eq!(c, 3);
}
@ -36,7 +38,8 @@ fn b() {
match x {
[a, ..b, c] => {
assert_eq!(a, 1);
assert_eq!(b, &[2]);
let expected: &[_] = &[2];
assert_eq!(b, expected);
assert_eq!(c, 3);
}
}

View file

@ -9,11 +9,10 @@
// except according to those terms.
pub fn main() {
assert_eq!((vec!(0i, 1)).to_string(), "[0, 1]".to_string());
assert_eq!((&[1i, 2]).to_string(), "[1, 2]".to_string());
assert_eq!((vec!(0, 1)).to_string(), "[0, 1]".to_string());
let foo = vec!(3i, 4);
let bar = &[4i, 5];
let foo = vec!(3, 4);
let bar: &[int] = &[4, 5];
assert_eq!(foo.to_string(), "[3, 4]".to_string());
assert_eq!(bar.to_string(), "[4, 5]".to_string());