Skip to content

Commit f1ddb8d

Browse files
committed
auto merge of #6080 : pcwalton/rust/demode-everything, r=pcwalton
r? @brson
2 parents dbcc3fe + 78f3343 commit f1ddb8d

File tree

152 files changed

+1567
-1966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+1567
-1966
lines changed

doc/rust.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,7 +2187,7 @@ A loop expression denotes an infinite loop;
21872187
see [Continue expressions](#continue-expressions) for continue expressions.
21882188

21892189
~~~~~~~~{.ebnf .gram}
2190-
loop_expr : "loop" [ ident ':' ] '{' block '}';
2190+
loop_expr : [ lifetime ':' ] "loop" '{' block '}';
21912191
~~~~~~~~
21922192

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

22002200
~~~~~~~~{.ebnf .gram}
2201-
break_expr : "break" [ ident ];
2201+
break_expr : "break" [ lifetime ];
22022202
~~~~~~~~
22032203

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

22132213
~~~~~~~~{.ebnf .gram}
2214-
continue_expr : "loop" [ ident ];
2214+
continue_expr : "loop" [ lifetime ];
22152215
~~~~~~~~
22162216

22172217
A continue expression, written `loop`, also has an optional `label`.
@@ -2393,7 +2393,7 @@ variables in the arm's block, and control enters the block.
23932393
An example of an `match` expression:
23942394

23952395

2396-
~~~~
2396+
~~~~ {.xfail-test}
23972397
# fn process_pair(a: int, b: int) { }
23982398
# fn process_ten() { }
23992399

src/libcore/at_vec.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use cast::transmute;
1414
use kinds::Copy;
1515
use old_iter;
1616
use option::Option;
17-
use ptr::addr_of;
1817
use sys;
1918
use uint;
2019
use vec;
@@ -40,8 +39,7 @@ pub mod rustrt {
4039
#[inline(always)]
4140
pub fn capacity<T>(v: @[T]) -> uint {
4241
unsafe {
43-
let repr: **raw::VecRepr =
44-
::cast::transmute(addr_of(&v));
42+
let repr: **raw::VecRepr = transmute(&v);
4543
(**repr).unboxed.alloc / sys::size_of::<T>()
4644
}
4745
}
@@ -187,13 +185,12 @@ pub mod traits {}
187185

188186
pub mod raw {
189187
use at_vec::{capacity, rustrt};
190-
use cast::transmute;
188+
use cast::{transmute, transmute_copy};
191189
use libc;
192-
use unstable::intrinsics::{move_val_init};
193-
use ptr::addr_of;
194190
use ptr;
195191
use sys;
196192
use uint;
193+
use unstable::intrinsics::{move_val_init};
197194
use vec;
198195

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

215212
#[inline(always)]
216213
pub unsafe fn push<T>(v: &mut @[T], initval: T) {
217-
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
214+
let repr: **VecRepr = transmute_copy(&v);
218215
let fill = (**repr).unboxed.fill;
219216
if (**repr).unboxed.alloc > fill {
220217
push_fast(v, initval);
221-
}
222-
else {
218+
} else {
223219
push_slow(v, initval);
224220
}
225221
}
@@ -229,7 +225,7 @@ pub mod raw {
229225
let repr: **mut VecRepr = ::cast::transmute(v);
230226
let fill = (**repr).unboxed.fill;
231227
(**repr).unboxed.fill += sys::size_of::<T>();
232-
let p = addr_of(&((**repr).unboxed.data));
228+
let p = &((**repr).unboxed.data);
233229
let p = ptr::offset(p, fill) as *mut T;
234230
move_val_init(&mut(*p), initval);
235231
}

src/libcore/cast.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,56 @@
1010

1111
//! Unsafe casting functions
1212
13+
use sys;
14+
use unstable;
15+
1316
pub mod rusti {
1417
#[abi = "rust-intrinsic"]
1518
#[link_name = "rusti"]
1619
pub extern "rust-intrinsic" {
1720
fn forget<T>(+x: T);
21+
22+
#[cfg(stage0)]
1823
fn reinterpret_cast<T, U>(&&e: T) -> U;
24+
25+
#[cfg(stage1)]
26+
#[cfg(stage2)]
27+
#[cfg(stage3)]
28+
fn transmute<T,U>(e: T) -> U;
1929
}
2030
}
2131

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

39+
/// Unsafely copies and casts the value at `src` to U, even if the value is
40+
/// noncopyable. The two types must have the same length.
41+
#[inline(always)]
42+
#[cfg(stage0)]
43+
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
44+
rusti::reinterpret_cast(*src)
45+
}
46+
47+
#[inline(always)]
48+
#[cfg(stage1)]
49+
#[cfg(stage2)]
50+
#[cfg(stage3)]
51+
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
52+
let mut dest: U = unstable::intrinsics::init();
53+
{
54+
let dest_ptr: *mut u8 = rusti::transmute(&mut dest);
55+
let src_ptr: *u8 = rusti::transmute(src);
56+
unstable::intrinsics::memmove64(dest_ptr,
57+
src_ptr,
58+
sys::size_of::<U>() as u64);
59+
}
60+
dest
61+
}
62+
2863
/**
2964
* Move a thing into the void
3065
*
@@ -53,12 +88,21 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
5388
* assert!(transmute("L") == ~[76u8, 0u8]);
5489
*/
5590
#[inline(always)]
91+
#[cfg(stage0)]
5692
pub unsafe fn transmute<L, G>(thing: L) -> G {
5793
let newthing: G = reinterpret_cast(&thing);
5894
forget(thing);
5995
newthing
6096
}
6197

98+
#[inline(always)]
99+
#[cfg(stage1)]
100+
#[cfg(stage2)]
101+
#[cfg(stage3)]
102+
pub unsafe fn transmute<L, G>(thing: L) -> G {
103+
rusti::transmute(thing)
104+
}
105+
62106
/// Coerce an immutable reference to be mutable.
63107
#[inline(always)]
64108
pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
@@ -112,11 +156,20 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
112156

113157
#[cfg(test)]
114158
mod tests {
115-
use cast::{bump_box_refcount, reinterpret_cast, transmute};
159+
use cast::{bump_box_refcount, transmute};
116160

117161
#[test]
162+
#[cfg(stage0)]
118163
fn test_reinterpret_cast() {
119-
assert!(1u == unsafe { reinterpret_cast(&1) });
164+
assert!(1u == unsafe { ::cast::reinterpret_cast(&1) });
165+
}
166+
167+
#[test]
168+
#[cfg(stage1)]
169+
#[cfg(stage2)]
170+
#[cfg(stage3)]
171+
fn test_transmute_copy() {
172+
assert!(1u == unsafe { ::cast::transmute_copy(&1) });
120173
}
121174

122175
#[test]
@@ -125,8 +178,8 @@ mod tests {
125178
let box = @~"box box box"; // refcount 1
126179
bump_box_refcount(box); // refcount 2
127180
let ptr: *int = transmute(box); // refcount 2
128-
let _box1: @~str = reinterpret_cast(&ptr);
129-
let _box2: @~str = reinterpret_cast(&ptr);
181+
let _box1: @~str = ::cast::transmute_copy(&ptr);
182+
let _box2: @~str = ::cast::transmute_copy(&ptr);
130183
assert!(*_box1 == ~"box box box");
131184
assert!(*_box2 == ~"box box box");
132185
// Will destroy _box1 and _box2. Without the bump, this would

src/libcore/comm.rs

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ impl<T: Owned> ::clone::Clone for SharedChan<T> {
327327
#[allow(non_camel_case_types)]
328328
pub mod oneshot {
329329
priv use core::kinds::Owned;
330+
use ptr::to_unsafe_ptr;
330331
331332
pub fn init<T: Owned>() -> (client::Oneshot<T>, server::Oneshot<T>) {
332333
pub use core::pipes::HasBuffer;
@@ -341,7 +342,7 @@ pub mod oneshot {
341342
do ::core::pipes::entangle_buffer(buffer) |buffer, data| {
342343
{
343344
data.Oneshot.set_buffer(buffer);
344-
::ptr::addr_of(&(data.Oneshot))
345+
to_unsafe_ptr(&data.Oneshot)
345346
}
346347
}
347348
}
@@ -394,58 +395,103 @@ pub mod oneshot {
394395
}
395396
396397
/// The send end of a oneshot pipe.
397-
pub type ChanOne<T> = oneshot::client::Oneshot<T>;
398+
pub struct ChanOne<T> {
399+
contents: oneshot::client::Oneshot<T>
400+
}
401+
402+
impl<T> ChanOne<T> {
403+
pub fn new(contents: oneshot::client::Oneshot<T>) -> ChanOne<T> {
404+
ChanOne {
405+
contents: contents
406+
}
407+
}
408+
}
409+
398410
/// The receive end of a oneshot pipe.
399-
pub type PortOne<T> = oneshot::server::Oneshot<T>;
411+
pub struct PortOne<T> {
412+
contents: oneshot::server::Oneshot<T>
413+
}
414+
415+
impl<T> PortOne<T> {
416+
pub fn new(contents: oneshot::server::Oneshot<T>) -> PortOne<T> {
417+
PortOne {
418+
contents: contents
419+
}
420+
}
421+
}
400422
401423
/// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
402424
pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {
403425
let (chan, port) = oneshot::init();
404-
(port, chan)
426+
(PortOne::new(port), ChanOne::new(chan))
405427
}
406428
407429
pub impl<T: Owned> PortOne<T> {
408430
fn recv(self) -> T { recv_one(self) }
409431
fn try_recv(self) -> Option<T> { try_recv_one(self) }
432+
fn unwrap(self) -> oneshot::server::Oneshot<T> {
433+
match self {
434+
PortOne { contents: s } => s
435+
}
436+
}
410437
}
411438
412439
pub impl<T: Owned> ChanOne<T> {
413440
fn send(self, data: T) { send_one(self, data) }
414441
fn try_send(self, data: T) -> bool { try_send_one(self, data) }
442+
fn unwrap(self) -> oneshot::client::Oneshot<T> {
443+
match self {
444+
ChanOne { contents: s } => s
445+
}
446+
}
415447
}
416448
417449
/**
418450
* Receive a message from a oneshot pipe, failing if the connection was
419451
* closed.
420452
*/
421453
pub fn recv_one<T: Owned>(port: PortOne<T>) -> T {
422-
let oneshot::send(message) = recv(port);
423-
message
454+
match port {
455+
PortOne { contents: port } => {
456+
let oneshot::send(message) = recv(port);
457+
message
458+
}
459+
}
424460
}
425461
426462
/// Receive a message from a oneshot pipe unless the connection was closed.
427463
pub fn try_recv_one<T: Owned> (port: PortOne<T>) -> Option<T> {
428-
let message = try_recv(port);
429-
430-
if message.is_none() { None }
431-
else {
432-
let oneshot::send(message) = message.unwrap();
433-
Some(message)
464+
match port {
465+
PortOne { contents: port } => {
466+
let message = try_recv(port);
467+
468+
if message.is_none() {
469+
None
470+
} else {
471+
let oneshot::send(message) = message.unwrap();
472+
Some(message)
473+
}
474+
}
434475
}
435476
}
436477
437478
/// Send a message on a oneshot pipe, failing if the connection was closed.
438479
pub fn send_one<T: Owned>(chan: ChanOne<T>, data: T) {
439-
oneshot::client::send(chan, data);
480+
match chan {
481+
ChanOne { contents: chan } => oneshot::client::send(chan, data),
482+
}
440483
}
441484
442485
/**
443486
* Send a message on a oneshot pipe, or return false if the connection was
444487
* closed.
445488
*/
446-
pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
447-
-> bool {
448-
oneshot::client::try_send(chan, data).is_some()
489+
pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T) -> bool {
490+
match chan {
491+
ChanOne { contents: chan } => {
492+
oneshot::client::try_send(chan, data).is_some()
493+
}
494+
}
449495
}
450496
451497
@@ -519,11 +565,11 @@ mod test {
519565

520566
#[test]
521567
fn test_oneshot() {
522-
let (c, p) = oneshot::init();
568+
let (p, c) = oneshot();
523569

524-
oneshot::client::send(c, ());
570+
c.send(());
525571

526-
recv_one(p)
572+
p.recv()
527573
}
528574

529575
#[test]

src/libcore/flate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
5353
let res =
5454
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
5555
len as size_t,
56-
ptr::addr_of(&outsz),
56+
&outsz,
5757
lz_norm);
5858
assert!(res as int != 0);
5959
let out = vec::raw::from_buf_raw(res as *u8,
@@ -71,7 +71,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
7171
let res =
7272
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
7373
len as size_t,
74-
ptr::addr_of(&outsz),
74+
&outsz,
7575
0);
7676
assert!(res as int != 0);
7777
let out = vec::raw::from_buf_raw(res as *u8,

src/libcore/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub fn cleanup_stack_for_failure() {
338338
// own stack roots on the stack anyway.
339339
let sentinel_box = ~0;
340340
let sentinel: **Word = if expect_sentinel() {
341-
cast::transmute(ptr::addr_of(&sentinel_box))
341+
cast::transmute(&sentinel_box)
342342
} else {
343343
ptr::null()
344344
};

0 commit comments

Comments
 (0)