Skip to content
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

Bitv Constructors #3351

Closed
wants to merge 13 commits into from
4 changes: 2 additions & 2 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2211,14 +2211,14 @@ fn main() {
~~~~

Multiple match patterns may be joined with the `|` operator. A
range of values may be specified with `to`. For example:
range of values may be specified with `..`. For example:

~~~~
# let x = 2;

let message = match x {
0 | 1 => ~"not many",
2 to 9 => ~"a few",
2 .. 9 => ~"a few",
_ => ~"lots"
};
~~~~
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,8 @@ fn print_pkg(s: source, p: package) {
fn print_source(s: source) {
info(s.name + ~" (" + s.url + ~")");

let pks = sort::merge_sort(sys::shape_lt, copy s.packages);
let unsorted_pks = s.packages; // to prevent illegal borrow?
let pks = sort::merge_sort(sys::shape_lt, unsorted_pks);
let l = vec::len(pks);

print(io::with_str_writer(|writer| {
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern mod rusti {
pure fn capacity<T>(&&v: @[const T]) -> uint {
unsafe {
let repr: **unsafe::VecRepr =
::unsafe::reinterpret_cast(addr_of(v));
::unsafe::reinterpret_cast(&addr_of(v));
(**repr).alloc / sys::size_of::<T>()
}
}
Expand Down Expand Up @@ -154,13 +154,13 @@ mod unsafe {
*/
#[inline(always)]
unsafe fn set_len<T>(&&v: @[const T], new_len: uint) {
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
(**repr).fill = new_len * sys::size_of::<T>();
}

#[inline(always)]
unsafe fn push<T>(&v: @[const T], +initval: T) {
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
let fill = (**repr).fill;
if (**repr).alloc > fill {
push_fast(v, initval);
Expand All @@ -172,7 +172,7 @@ mod unsafe {
// This doesn't bother to make sure we have space.
#[inline(always)] // really pretty please
unsafe fn push_fast<T>(&v: @[const T], +initval: T) {
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
let fill = (**repr).fill;
(**repr).fill += sys::size_of::<T>();
let p = ptr::addr_of((**repr).data);
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ pure fn is_digit(c: char) -> bool {
*/
pure fn to_digit(c: char, radix: uint) -> Option<uint> {
let val = match c {
'0' to '9' => c as uint - ('0' as uint),
'a' to 'z' => c as uint + 10u - ('a' as uint),
'A' to 'Z' => c as uint + 10u - ('A' as uint),
'0' .. '9' => c as uint - ('0' as uint),
'a' .. 'z' => c as uint + 10u - ('a' as uint),
'A' .. 'Z' => c as uint + 10u - ('A' as uint),
_ => return None
};
if val < radix { Some(val) }
Expand Down Expand Up @@ -171,7 +171,7 @@ fn escape_default(c: char) -> ~str {
'\\' => ~"\\\\",
'\'' => ~"\\'",
'"' => ~"\\\"",
'\x20' to '\x7e' => str::from_char(c),
'\x20' .. '\x7e' => str::from_char(c),
_ => escape_unicode(c)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/dvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn unwrap<A>(+d: DVec<A>) -> ~[mut A] {
priv impl<A> DVec<A> {
pure fn check_not_borrowed() {
unsafe {
let data: *() = unsafe::reinterpret_cast(self.data);
let data: *() = unsafe::reinterpret_cast(&self.data);
if data.is_null() {
fail ~"Recursive use of dvec";
}
Expand All @@ -91,9 +91,9 @@ priv impl<A> DVec<A> {
#[inline(always)]
fn check_out<B>(f: fn(-~[mut A]) -> B) -> B {
unsafe {
let mut data = unsafe::reinterpret_cast(null::<()>());
let mut data = unsafe::reinterpret_cast(&null::<()>());
data <-> self.data;
let data_ptr: *() = unsafe::reinterpret_cast(data);
let data_ptr: *() = unsafe::reinterpret_cast(&data);
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
return f(data);
}
Expand Down Expand Up @@ -156,9 +156,9 @@ impl<A> DVec<A> {
/// Insert a single item at the front of the list
fn unshift(-t: A) {
unsafe {
let mut data = unsafe::reinterpret_cast(null::<()>());
let mut data = unsafe::reinterpret_cast(&null::<()>());
data <-> self.data;
let data_ptr: *() = unsafe::reinterpret_cast(data);
let data_ptr: *() = unsafe::reinterpret_cast(&data);
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
log(error, ~"a");
self.data <- ~[mut t];
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fn from_str(num: &str) -> Option<float> {

//The string must start with one of the following characters.
match str::char_at(num, 0u) {
'-' | '+' | '0' to '9' | '.' => (),
'-' | '+' | '0' .. '9' | '.' => (),
_ => return None
}

Expand All @@ -286,7 +286,7 @@ fn from_str(num: &str) -> Option<float> {
c = char_range.ch;
pos = char_range.next;
match c {
'0' to '9' => {
'0' .. '9' => {
total = total * 10f;
total += ((c as int) - ('0' as int)) as float;
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ mod global_env {
fn getenv(n: &str) -> Option<~str> {
unsafe {
let s = str::as_c_str(n, libc::getenv);
return if ptr::null::<u8>() == unsafe::reinterpret_cast(s) {
return if ptr::null::<u8>() == unsafe::reinterpret_cast(&s) {
option::None::<~str>
} else {
let s = unsafe::reinterpret_cast(s);
let s = unsafe::reinterpret_cast(&s);
option::Some::<~str>(str::unsafe::from_buf(s))
};
}
Expand Down Expand Up @@ -595,7 +595,7 @@ fn make_dir(p: &Path, mode: c_int) -> bool {
import win32::*;
// FIXME: turn mode into something useful? #2623
do as_utf16_p(p.to_str()) |buf| {
CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(0) })
CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(&0) })
!= (0 as BOOL)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ struct PacketHeader {
// thing. You'll proobably want to forget them when you're done.
unsafe fn buf_header() -> ~BufferHeader {
assert self.buffer.is_not_null();
reinterpret_cast(self.buffer)
reinterpret_cast(&self.buffer)
}

fn set_buffer<T: send>(b: ~Buffer<T>) unsafe {
self.buffer = reinterpret_cast(b);
self.buffer = reinterpret_cast(&b);
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
};

unsafe {
b.data.header.buffer = reinterpret_cast(b);
b.data.header.buffer = reinterpret_cast(&b);
}

b
Expand All @@ -274,7 +274,7 @@ fn entangle_buffer<T: send, Tstart: send>(
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
{
let p = init(unsafe { reinterpret_cast(buffer) }, &buffer.data);
let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);
unsafe { forget(buffer) }
(SendPacketBuffered(p), RecvPacketBuffered(p))
}
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ unsafe fn chan_from_global_ptr<T: send>(
// This is the proposed global channel
let ch = comm::recv(setup_po);
// 0 is our sentinal value. It is not a valid channel
assert unsafe::reinterpret_cast(ch) != 0u;
assert unsafe::reinterpret_cast(&ch) != 0u;

// Install the channel
log(debug,~"BEFORE COMPARE AND SWAP");
let swapped = compare_and_swap(
global, 0u, unsafe::reinterpret_cast(ch));
global, 0u, unsafe::reinterpret_cast(&ch));
log(debug,fmt!("AFTER .. swapped? %?", swapped));

if swapped {
Expand All @@ -78,11 +78,11 @@ unsafe fn chan_from_global_ptr<T: send>(
} else {
// Somebody else got in before we did
comm::send(setup_ch, Abort);
unsafe::reinterpret_cast(*global)
unsafe::reinterpret_cast(&*global)
}
} else {
log(debug, ~"global != 0");
unsafe::reinterpret_cast(*global)
unsafe::reinterpret_cast(&*global)
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
let po = comm::Port();
let ch = comm::Chan(po);
unsafe {
rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch));
rustrt::rust_task_weaken(unsafe::reinterpret_cast(&ch));
}
let _unweaken = Unweaken(ch);
f(po);
Expand All @@ -198,7 +198,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
let ch: comm::Chan<()>;
new(ch: comm::Chan<()>) { self.ch = ch; }
drop unsafe {
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch));
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(&self.ch));
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pure fn addr_of<T>(val: T) -> *T { unchecked { rusti::addr_of(val) } }
#[inline(always)]
pure fn mut_addr_of<T>(val: T) -> *mut T {
unsafe {
unsafe::reinterpret_cast(rusti::addr_of(val))
unsafe::reinterpret_cast(&rusti::addr_of(val))
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {

/// Create an unsafe null pointer
#[inline(always)]
pure fn null<T>() -> *T { unsafe { unsafe::reinterpret_cast(0u) } }
pure fn null<T>() -> *T { unsafe { unsafe::reinterpret_cast(&0u) } }

/// Returns true if the pointer is equal to the null pointer.
pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
Expand Down Expand Up @@ -137,7 +137,7 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
*/
#[inline(always)]
fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
unsafe::reinterpret_cast(thing)
unsafe::reinterpret_cast(&thing)
}

/**
Expand All @@ -149,7 +149,7 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
*/
#[inline(always)]
fn to_uint<T>(thing: &T) -> uint unsafe {
unsafe::reinterpret_cast(thing)
unsafe::reinterpret_cast(&thing)
}

/// Determine if two borrowed pointers point to the same thing.
Expand All @@ -175,32 +175,32 @@ impl<T> *T: Ptr {
// Equality for pointers
impl<T> *const T : Eq {
pure fn eq(&&other: *const T) -> bool unsafe {
let a: uint = unsafe::reinterpret_cast(self);
let b: uint = unsafe::reinterpret_cast(other);
let a: uint = unsafe::reinterpret_cast(&self);
let b: uint = unsafe::reinterpret_cast(&other);
return a == b;
}
}

// Comparison for pointers
impl<T> *const T : Ord {
pure fn lt(&&other: *const T) -> bool unsafe {
let a: uint = unsafe::reinterpret_cast(self);
let b: uint = unsafe::reinterpret_cast(other);
let a: uint = unsafe::reinterpret_cast(&self);
let b: uint = unsafe::reinterpret_cast(&other);
return a < b;
}
pure fn le(&&other: *const T) -> bool unsafe {
let a: uint = unsafe::reinterpret_cast(self);
let b: uint = unsafe::reinterpret_cast(other);
let a: uint = unsafe::reinterpret_cast(&self);
let b: uint = unsafe::reinterpret_cast(&other);
return a <= b;
}
pure fn ge(&&other: *const T) -> bool unsafe {
let a: uint = unsafe::reinterpret_cast(self);
let b: uint = unsafe::reinterpret_cast(other);
let a: uint = unsafe::reinterpret_cast(&self);
let b: uint = unsafe::reinterpret_cast(&other);
return a >= b;
}
pure fn gt(&&other: *const T) -> bool unsafe {
let a: uint = unsafe::reinterpret_cast(self);
let b: uint = unsafe::reinterpret_cast(other);
let a: uint = unsafe::reinterpret_cast(&self);
let b: uint = unsafe::reinterpret_cast(&other);
return a > b;
}
}
Expand All @@ -226,7 +226,7 @@ fn test() {
type Pair = {mut fst: int, mut snd: int};
let p = {mut fst: 10, mut snd: 20};
let pptr: *mut Pair = mut_addr_of(p);
let iptr: *mut int = unsafe::reinterpret_cast(pptr);
let iptr: *mut int = unsafe::reinterpret_cast(&pptr);
assert (*iptr == 10);;
*iptr = 30;
assert (*iptr == 30);
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
}
vec::push(ptrs, ptr::null());
vec::as_buf(ptrs, |p, _len|
unsafe { cb(::unsafe::reinterpret_cast(p)) }
unsafe { cb(::unsafe::reinterpret_cast(&p)) }
)
}
_ => cb(ptr::null())
Expand All @@ -133,12 +133,12 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
for vec::each(es) |e| {
let (k,v) = e;
let t = fmt!("%s=%s", k, v);
let mut v : ~[u8] = ::unsafe::reinterpret_cast(t);
let mut v : ~[u8] = ::unsafe::reinterpret_cast(&t);
blk += v;
::unsafe::forget(v);
}
blk += ~[0_u8];
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(p)))
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(&p)))
}
_ => cb(ptr::null())
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/stackwalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ fn walk_stack(visit: fn(Frame) -> bool) {

do frame_address |frame_pointer| {
let mut frame_address: *Word = unsafe {
reinterpret_cast(frame_pointer)
reinterpret_cast(&frame_pointer)
};
loop {
let fr = Frame(frame_address);

debug!("frame: %x", unsafe { reinterpret_cast(fr.fp) });
debug!("frame: %x", unsafe { reinterpret_cast(&fr.fp) });
visit(fr);

unsafe {
let next_fp: **Word = reinterpret_cast(frame_address);
let next_fp: **Word = reinterpret_cast(&frame_address);
frame_address = *next_fp;
if *frame_address == 0u {
debug!("encountered task_start_wrapper. ending walk");
Expand Down
Loading