fix tests

This commit is contained in:
Oliver Schneider 2015-03-13 13:09:34 +01:00
parent 6584ae5491
commit 85080fa81d
2 changed files with 12 additions and 11 deletions

View File

@ -26,8 +26,8 @@ impl<'a> MyWriter for &'a mut [u8] {
let write_len = buf.len();
unsafe {
*self = slice::from_raw_parts(
self.as_ptr().offset(write_len as int),
*self = slice::from_raw_parts_mut(
self.as_mut_ptr().offset(write_len as isize),
self.len() - write_len
);
}

View File

@ -15,31 +15,32 @@
use std::mem;
use std::raw;
use std::slice;
struct Foo<T> {
f: [T],
}
struct Bar {
f1: uint,
f2: [uint],
f1: usize,
f2: [usize],
}
struct Baz {
f1: uint,
f1: usize,
f2: str,
}
trait Tr {
fn foo(&self) -> uint;
fn foo(&self) -> usize;
}
struct St {
f: uint
f: usize
}
impl Tr for St {
fn foo(&self) -> uint {
fn foo(&self) -> usize {
self.f
}
}
@ -67,18 +68,18 @@ pub fn main() {
}
let data: Box<Foo_<i32>> = box Foo_{f: [1, 2, 3] };
let x: &Foo<i32> = slice::from_raw_parts(&*data, 3);
let x: &Foo<i32> = mem::transmute(slice::from_raw_parts(&*data, 3));
assert!(x.f.len() == 3);
assert!(x.f[0] == 1);
struct Baz_ {
f1: uint,
f1: usize,
f2: [u8; 5],
}
let data: Box<_> = box Baz_ {
f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] };
let x: &Baz = slice::from_raw_parts(&*data, 5);
let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5));
assert!(x.f1 == 42);
let chs: Vec<char> = x.f2.chars().collect();
assert!(chs.len() == 5);