Skip to content

librustc: Make labels take '. #6084

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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,7 @@ A loop expression denotes an infinite loop;
see [Continue expressions](#continue-expressions) for continue expressions.

~~~~~~~~{.ebnf .gram}
loop_expr : "loop" [ ident ':' ] '{' block '}';
loop_expr : [ lifetime ':' ] "loop" '{' block '}';
~~~~~~~~

A `loop` expression may optionally have a _label_.
Expand All @@ -2198,7 +2198,7 @@ See [Break expressions](#break-expressions).
### Break expressions

~~~~~~~~{.ebnf .gram}
break_expr : "break" [ ident ];
break_expr : "break" [ lifetime ];
~~~~~~~~

A `break` expression has an optional `label`.
Expand All @@ -2211,7 +2211,7 @@ but must enclose it.
### Continue expressions

~~~~~~~~{.ebnf .gram}
continue_expr : "loop" [ ident ];
continue_expr : "loop" [ lifetime ];
~~~~~~~~

A continue expression, written `loop`, also has an optional `label`.
Expand Down
18 changes: 7 additions & 11 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use cast::transmute;
use kinds::Copy;
use iter;
use option::Option;
use ptr::addr_of;
use sys;
use uint;
use vec;
Expand All @@ -40,8 +39,7 @@ pub mod rustrt {
#[inline(always)]
pub fn capacity<T>(v: @[T]) -> uint {
unsafe {
let repr: **raw::VecRepr =
::cast::transmute(addr_of(&v));
let repr: **raw::VecRepr = transmute(&v);
(**repr).unboxed.alloc / sys::size_of::<T>()
}
}
Expand Down Expand Up @@ -187,13 +185,12 @@ pub mod traits {}

pub mod raw {
use at_vec::{capacity, rustrt};
use cast::transmute;
use cast::{transmute, transmute_copy};
use libc;
use unstable::intrinsics::{move_val_init};
use ptr::addr_of;
use ptr;
use sys;
use uint;
use unstable::intrinsics::{move_val_init};
use vec;

pub type VecRepr = vec::raw::VecRepr;
Expand All @@ -208,18 +205,17 @@ pub mod raw {
*/
#[inline(always)]
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
let repr: **mut VecRepr = ::cast::transmute(addr_of(&v));
let repr: **mut VecRepr = transmute(&v);
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
}

#[inline(always)]
pub unsafe fn push<T>(v: &mut @[T], initval: T) {
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
let repr: **VecRepr = transmute_copy(&v);
let fill = (**repr).unboxed.fill;
if (**repr).unboxed.alloc > fill {
push_fast(v, initval);
}
else {
} else {
push_slow(v, initval);
}
}
Expand All @@ -229,7 +225,7 @@ pub mod raw {
let repr: **mut VecRepr = ::cast::transmute(v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
let p = addr_of(&((**repr).unboxed.data));
let p = &((**repr).unboxed.data);
let p = ptr::offset(p, fill) as *mut T;
move_val_init(&mut(*p), initval);
}
Expand Down
61 changes: 57 additions & 4 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,56 @@

//! Unsafe casting functions

use sys;
use unstable;

pub mod rusti {
#[abi = "rust-intrinsic"]
#[link_name = "rusti"]
pub extern "rust-intrinsic" {
fn forget<T>(+x: T);

#[cfg(stage0)]
fn reinterpret_cast<T, U>(&&e: T) -> U;

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn transmute<T,U>(e: T) -> U;
}
}

/// Casts the value at `src` to U. The two types must have the same length.
#[inline(always)]
#[cfg(stage0)]
pub unsafe fn reinterpret_cast<T, U>(src: &T) -> U {
rusti::reinterpret_cast(*src)
}

/// Unsafely copies and casts the value at `src` to U, even if the value is
/// noncopyable. The two types must have the same length.
#[inline(always)]
#[cfg(stage0)]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
rusti::reinterpret_cast(*src)
}

#[inline(always)]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
let mut dest: U = unstable::intrinsics::init();
{
let dest_ptr: *mut u8 = rusti::transmute(&mut dest);
let src_ptr: *u8 = rusti::transmute(src);
unstable::intrinsics::memmove64(dest_ptr,
src_ptr,
sys::size_of::<U>() as u64);
}
dest
}

/**
* Move a thing into the void
*
Expand Down Expand Up @@ -53,12 +88,21 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
* assert!(transmute("L") == ~[76u8, 0u8]);
*/
#[inline(always)]
#[cfg(stage0)]
pub unsafe fn transmute<L, G>(thing: L) -> G {
let newthing: G = reinterpret_cast(&thing);
forget(thing);
newthing
}

#[inline(always)]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
pub unsafe fn transmute<L, G>(thing: L) -> G {
rusti::transmute(thing)
}

/// Coerce an immutable reference to be mutable.
#[inline(always)]
pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
Expand Down Expand Up @@ -112,11 +156,20 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {

#[cfg(test)]
mod tests {
use cast::{bump_box_refcount, reinterpret_cast, transmute};
use cast::{bump_box_refcount, transmute};

#[test]
#[cfg(stage0)]
fn test_reinterpret_cast() {
assert!(1u == unsafe { reinterpret_cast(&1) });
assert!(1u == unsafe { ::cast::reinterpret_cast(&1) });
}

#[test]
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn test_transmute_copy() {
assert!(1u == unsafe { ::cast::transmute_copy(&1) });
}

#[test]
Expand All @@ -125,8 +178,8 @@ mod tests {
let box = @~"box box box"; // refcount 1
bump_box_refcount(box); // refcount 2
let ptr: *int = transmute(box); // refcount 2
let _box1: @~str = reinterpret_cast(&ptr);
let _box2: @~str = reinterpret_cast(&ptr);
let _box1: @~str = ::cast::transmute_copy(&ptr);
let _box2: @~str = ::cast::transmute_copy(&ptr);
assert!(*_box1 == ~"box box box");
assert!(*_box2 == ~"box box box");
// Will destroy _box1 and _box2. Without the bump, this would
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ impl<T: Owned> ::clone::Clone for SharedChan<T> {
#[allow(non_camel_case_types)]
pub mod oneshot {
priv use core::kinds::Owned;
use ptr::to_unsafe_ptr;

pub fn init<T: Owned>() -> (client::Oneshot<T>, server::Oneshot<T>) {
pub use core::pipes::HasBuffer;
Expand All @@ -341,7 +342,7 @@ pub mod oneshot {
do ::core::pipes::entangle_buffer(buffer) |buffer, data| {
{
data.Oneshot.set_buffer(buffer);
::ptr::addr_of(&(data.Oneshot))
to_unsafe_ptr(&data.Oneshot)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
let res =
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
len as size_t,
ptr::addr_of(&outsz),
&outsz,
lz_norm);
assert!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8,
Expand All @@ -71,7 +71,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
let res =
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
len as size_t,
ptr::addr_of(&outsz),
&outsz,
0);
assert!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8,
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ pub fn cleanup_stack_for_failure() {
// own stack roots on the stack anyway.
let sentinel_box = ~0;
let sentinel: **Word = if expect_sentinel() {
cast::transmute(ptr::addr_of(&sentinel_box))
cast::transmute(&sentinel_box)
} else {
ptr::null()
};
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn resize_at(capacity: uint) -> uint {
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
initial_capacity: uint) -> HashMap<K, V> {
let r = rand::task_rng();
linear_map_with_capacity_and_keys(r.gen(), r.gen(),
linear_map_with_capacity_and_keys((*r).gen_u64(), (*r).gen_u64(),
initial_capacity)
}

Expand Down
8 changes: 5 additions & 3 deletions src/libcore/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! Operations on managed box types

use ptr;
use ptr::to_unsafe_ptr;

#[cfg(notest)] use cmp::{Eq, Ord};

Expand Down Expand Up @@ -38,13 +38,15 @@ pub mod raw {
#[inline(always)]
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
//! Determine if two shared boxes point to the same object
ptr::addr_of(&(*a)) == ptr::addr_of(&(*b))
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
a_ptr == b_ptr
}

#[inline(always)]
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
//! Determine if two mutable shared boxes point to the same object
ptr::addr_of(&(*a)) == ptr::addr_of(&(*b))
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
a_ptr == b_ptr
}

#[cfg(notest)]
Expand Down
15 changes: 8 additions & 7 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use num::Zero;
use iter::{BaseIter, MutableIter, ExtendedIter};
use iter;

#[cfg(test)] use ptr;
#[cfg(test)] use str;

/// The option type
Expand Down Expand Up @@ -481,12 +480,14 @@ pub impl<T:Copy + Zero> Option<T> {

#[test]
fn test_unwrap_ptr() {
let x = ~0;
let addr_x = ptr::addr_of(&(*x));
let opt = Some(x);
let y = opt.unwrap();
let addr_y = ptr::addr_of(&(*y));
assert!(addr_x == addr_y);
unsafe {
let x = ~0;
let addr_x: *int = ::cast::transmute(&*x);
let opt = Some(x);
let y = opt.unwrap();
let addr_y: *int = ::cast::transmute(&*y);
assert!(addr_x == addr_y);
}
}

#[test]
Expand Down
Loading