Skip to content

Commit d6dacac

Browse files
committed
---
yaml --- r: 65476 b: refs/heads/master c: c582e3e h: refs/heads/master v: v3
1 parent b6d95f7 commit d6dacac

File tree

12 files changed

+136
-69
lines changed

12 files changed

+136
-69
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 042618da7b70b30c910377860e7d5cb16001a6a6
2+
refs/heads/master: c582e3eb820feb0e7315054ec229e35c44a34719
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/doc/tutorial-ffi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<T: Owned> Drop for Unique<T> {
188188
unsafe {
189189
let mut x = intrinsics::init(); // dummy value to swap in
190190
// moving the object out is needed to call the destructor
191-
ptr::replace_ptr(self.ptr, x);
191+
util::replace_ptr(self.ptr, x);
192192
free(self.ptr as *c_void)
193193
}
194194
}

trunk/src/libextra/rc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use core::libc::{c_void, size_t, malloc, free};
2828
use core::ptr;
2929
use core::sys;
3030
use core::unstable::intrinsics;
31+
use core::util;
3132

3233
struct RcBox<T> {
3334
value: T,
@@ -72,7 +73,7 @@ impl<T> Drop for Rc<T> {
7273
unsafe {
7374
(*self.ptr).count -= 1;
7475
if (*self.ptr).count == 0 {
75-
ptr::replace_ptr(self.ptr, intrinsics::uninit());
76+
util::replace_ptr(self.ptr, intrinsics::uninit());
7677
free(self.ptr as *c_void)
7778
}
7879
}
@@ -222,7 +223,7 @@ impl<T> Drop for RcMut<T> {
222223
unsafe {
223224
(*self.ptr).count -= 1;
224225
if (*self.ptr).count == 0 {
225-
ptr::replace_ptr(self.ptr, uninit());
226+
util::replace_ptr(self.ptr, uninit());
226227
free(self.ptr as *c_void)
227228
}
228229
}

trunk/src/librustc/back/passes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ pub fn create_standard_passes(level:OptLevel) -> ~[~str] {
134134
passes.push(~"correlated-propagation");
135135
passes.push(~"dse");
136136

137-
passes.push(~"bb-vectorize");
138137
passes.push(~"instcombine");
139138
passes.push(~"early-cse");
140139

trunk/src/librustc/middle/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub fn check_crate(tcx: ty::ctxt,
200200
f = |item_id| {
201201
match tcx.items.find(&item_id) {
202202
Some(&node_item(item, _)) => item.vis != public,
203-
Some(&node_foreign_item(_, _, vis, _)) => vis != public,
203+
Some(&node_foreign_item(*)) => false,
204204
Some(&node_method(method, impl_did, _)) => {
205205
match method.vis {
206206
private => true,

trunk/src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,7 @@ pub impl Resolver {
30793079
self.session.span_err(imports[index].span, "unresolved import");
30803080
} else {
30813081
let err = fmt!("unresolved import (maybe you meant `%s::*`?)",
3082-
sn.slice(0, sn.len() - 1)); // -1 to adjust for semicolon
3082+
sn.slice(0, sn.len()));
30833083
self.session.span_err(imports[index].span, err);
30843084
}
30853085
}

trunk/src/libstd/ptr.rs

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use cast;
1515
#[cfg(stage0)] use libc::{c_void, size_t};
1616
use option::{Option, Some, None};
1717
use sys;
18-
use unstable::intrinsics;
1918

2019
#[cfg(not(test))] use cmp::{Eq, Ord};
2120
use uint;
@@ -72,11 +71,11 @@ pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
7271

7372
/// Create an unsafe null pointer
7473
#[inline(always)]
75-
pub fn null<T>() -> *T { 0 as *T }
74+
pub fn null<T>() -> *T { unsafe { cast::transmute(0u) } }
7675

7776
/// Create an unsafe mutable null pointer
7877
#[inline(always)]
79-
pub fn mut_null<T>() -> *mut T { 0 as *mut T }
78+
pub fn mut_null<T>() -> *mut T { unsafe { cast::transmute(0u) } }
8079

8180
/// Returns true if the pointer is equal to the null pointer.
8281
#[inline(always)]
@@ -208,57 +207,47 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
208207
}
209208

210209
/**
211-
* Swap the values at two mutable locations of the same type, without
212-
* deinitialising or copying either one.
213-
*/
214-
#[inline]
215-
pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
216-
// Give ourselves some scratch space to work with
217-
let mut tmp: T = intrinsics::uninit();
218-
let t: *mut T = &mut tmp;
219-
220-
// Perform the swap
221-
copy_memory(t, x, 1);
222-
copy_memory(x, y, 1);
223-
copy_memory(y, t, 1);
224-
225-
// y and t now point to the same thing, but we need to completely forget `tmp`
226-
// because it's no longer relevant.
227-
cast::forget(tmp);
228-
}
229-
230-
/**
231-
* Replace the value at a mutable location with a new one, returning the old
232-
* value, without deinitialising or copying either one.
233-
*/
234-
#[inline(always)]
235-
pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
236-
swap_ptr(dest, &mut src);
237-
src
238-
}
239-
240-
/// Transform a region pointer - &T - to an unsafe pointer - *T.
210+
Transform a region pointer - &T - to an unsafe pointer - *T.
211+
This is safe, but is implemented with an unsafe block due to
212+
transmute.
213+
*/
241214
#[inline(always)]
242215
pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
243-
thing as *T
216+
unsafe { cast::transmute(thing) }
244217
}
245218

246-
/// Transform a const region pointer - &const T - to a const unsafe pointer - *const T.
219+
/**
220+
Transform a const region pointer - &const T - to a const unsafe pointer -
221+
*const T. This is safe, but is implemented with an unsafe block due to
222+
transmute.
223+
*/
247224
#[inline(always)]
248225
pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
249-
thing as *const T
226+
unsafe { cast::transmute(thing) }
250227
}
251228

252-
/// Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T.
229+
/**
230+
Transform a mutable region pointer - &mut T - to a mutable unsafe pointer -
231+
*mut T. This is safe, but is implemented with an unsafe block due to
232+
transmute.
233+
*/
253234
#[inline(always)]
254235
pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
255-
thing as *mut T
236+
unsafe { cast::transmute(thing) }
256237
}
257238

258-
/// Cast a region pointer - &T - to a uint.
239+
/**
240+
Cast a region pointer - &T - to a uint.
241+
This is safe, but is implemented with an unsafe block due to
242+
transmute.
243+
244+
(I couldn't think of a cutesy name for this one.)
245+
*/
259246
#[inline(always)]
260247
pub fn to_uint<T>(thing: &T) -> uint {
261-
thing as *T as uint
248+
unsafe {
249+
cast::transmute(thing)
250+
}
262251
}
263252

264253
/// Determine if two borrowed pointers point to the same thing.
@@ -384,30 +373,50 @@ impl<T> Ptr<T> for *mut T {
384373
impl<T> Eq for *const T {
385374
#[inline(always)]
386375
fn eq(&self, other: &*const T) -> bool {
387-
(*self as uint) == (*other as uint)
376+
unsafe {
377+
let a: uint = cast::transmute(*self);
378+
let b: uint = cast::transmute(*other);
379+
return a == b;
380+
}
388381
}
389382
#[inline(always)]
390-
fn ne(&self, other: &*const T) -> bool { !self.eq(other) }
383+
fn ne(&self, other: &*const T) -> bool { !(*self).eq(other) }
391384
}
392385

393386
// Comparison for pointers
394387
#[cfg(not(test))]
395388
impl<T> Ord for *const T {
396389
#[inline(always)]
397390
fn lt(&self, other: &*const T) -> bool {
398-
(*self as uint) < (*other as uint)
391+
unsafe {
392+
let a: uint = cast::transmute(*self);
393+
let b: uint = cast::transmute(*other);
394+
return a < b;
395+
}
399396
}
400397
#[inline(always)]
401398
fn le(&self, other: &*const T) -> bool {
402-
(*self as uint) <= (*other as uint)
399+
unsafe {
400+
let a: uint = cast::transmute(*self);
401+
let b: uint = cast::transmute(*other);
402+
return a <= b;
403+
}
403404
}
404405
#[inline(always)]
405406
fn ge(&self, other: &*const T) -> bool {
406-
(*self as uint) >= (*other as uint)
407+
unsafe {
408+
let a: uint = cast::transmute(*self);
409+
let b: uint = cast::transmute(*other);
410+
return a >= b;
411+
}
407412
}
408413
#[inline(always)]
409414
fn gt(&self, other: &*const T) -> bool {
410-
(*self as uint) > (*other as uint)
415+
unsafe {
416+
let a: uint = cast::transmute(*self);
417+
let b: uint = cast::transmute(*other);
418+
return a > b;
419+
}
411420
}
412421
}
413422

@@ -416,11 +425,11 @@ impl<T> Ord for *const T {
416425
impl<'self,T:Eq> Eq for &'self T {
417426
#[inline(always)]
418427
fn eq(&self, other: & &'self T) -> bool {
419-
*(*self) == *(*other)
428+
return *(*self) == *(*other);
420429
}
421430
#[inline(always)]
422431
fn ne(&self, other: & &'self T) -> bool {
423-
*(*self) != *(*other)
432+
return *(*self) != *(*other);
424433
}
425434
}
426435

trunk/src/libstd/util.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
6464
}
6565
}
6666

67+
/**
68+
* Swap the values at two mutable locations of the same type, without
69+
* deinitialising or copying either one.
70+
*/
71+
#[inline]
72+
pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
73+
// Give ourselves some scratch space to work with
74+
let mut tmp: T = intrinsics::uninit();
75+
let t: *mut T = &mut tmp;
76+
77+
// Perform the swap
78+
ptr::copy_memory(t, x, 1);
79+
ptr::copy_memory(x, y, 1);
80+
ptr::copy_memory(y, t, 1);
81+
82+
// y and t now point to the same thing, but we need to completely forget `tmp`
83+
// because it's no longer relevant.
84+
cast::forget(tmp);
85+
}
86+
6787
/**
6888
* Replace the value at a mutable location with a new one, returning the old
6989
* value, without deinitialising or copying either one.
@@ -74,6 +94,16 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
7494
src
7595
}
7696

97+
/**
98+
* Replace the value at a mutable location with a new one, returning the old
99+
* value, without deinitialising or copying either one.
100+
*/
101+
#[inline(always)]
102+
pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
103+
swap_ptr(dest, ptr::to_mut_unsafe_ptr(&mut src));
104+
src
105+
}
106+
77107
/// A non-copyable dummy type.
78108
pub struct NonCopyable {
79109
priv i: (),

trunk/src/libstd/vec.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub fn shift<T>(v: &mut ~[T]) -> T {
506506
let vp = raw::to_mut_ptr(*v);
507507
let vp = ptr::mut_offset(vp, next_ln - 1);
508508

509-
ptr::replace_ptr(vp, work_elt)
509+
util::replace_ptr(vp, work_elt)
510510
}
511511
}
512512

@@ -570,7 +570,7 @@ pub fn consume<T>(mut v: ~[T], f: &fn(uint, v: T)) {
570570
// elements during unwinding
571571
let x = intrinsics::init();
572572
let p = ptr::mut_offset(p, i);
573-
f(i, ptr::replace_ptr(p, x));
573+
f(i, util::replace_ptr(p, x));
574574
}
575575
}
576576

@@ -597,7 +597,7 @@ pub fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T)) {
597597
// elements during unwinding
598598
let x = intrinsics::init();
599599
let p = ptr::mut_offset(p, i);
600-
f(i, ptr::replace_ptr(p, x));
600+
f(i, util::replace_ptr(p, x));
601601
}
602602
}
603603

@@ -613,7 +613,7 @@ pub fn pop<T>(v: &mut ~[T]) -> T {
613613
}
614614
let valptr = ptr::to_mut_unsafe_ptr(&mut v[ln - 1u]);
615615
unsafe {
616-
let val = ptr::replace_ptr(valptr, intrinsics::init());
616+
let val = util::replace_ptr(valptr, intrinsics::init());
617617
raw::set_len(v, ln - 1u);
618618
val
619619
}
@@ -707,8 +707,8 @@ pub fn push_all_move<T>(v: &mut ~[T], mut rhs: ~[T]) {
707707
unsafe {
708708
do as_mut_buf(rhs) |p, len| {
709709
for uint::range(0, len) |i| {
710-
let x = ptr::replace_ptr(ptr::mut_offset(p, i),
711-
intrinsics::uninit());
710+
let x = util::replace_ptr(ptr::mut_offset(p, i),
711+
intrinsics::uninit());
712712
push(&mut *v, x);
713713
}
714714
}
@@ -723,7 +723,7 @@ pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
723723
unsafe {
724724
// This loop is optimized out for non-drop types.
725725
for uint::range(newlen, oldlen) |i| {
726-
ptr::replace_ptr(ptr::mut_offset(p, i), intrinsics::uninit());
726+
util::replace_ptr(ptr::mut_offset(p, i), intrinsics::uninit());
727727
}
728728
}
729729
}
@@ -747,14 +747,14 @@ pub fn dedup<T:Eq>(v: &mut ~[T]) {
747747
// last_written < next_to_read < ln
748748
if *ptr::mut_offset(p, next_to_read) ==
749749
*ptr::mut_offset(p, last_written) {
750-
ptr::replace_ptr(ptr::mut_offset(p, next_to_read),
751-
intrinsics::uninit());
750+
util::replace_ptr(ptr::mut_offset(p, next_to_read),
751+
intrinsics::uninit());
752752
} else {
753753
last_written += 1;
754754
// last_written <= next_to_read < ln
755755
if next_to_read != last_written {
756-
ptr::swap_ptr(ptr::mut_offset(p, last_written),
757-
ptr::mut_offset(p, next_to_read));
756+
util::swap_ptr(ptr::mut_offset(p, last_written),
757+
ptr::mut_offset(p, next_to_read));
758758
}
759759
}
760760
// last_written <= next_to_read < ln
@@ -1398,7 +1398,7 @@ pub fn swap<T>(v: &mut [T], a: uint, b: uint) {
13981398
// them to their raw pointers to do the swap
13991399
let pa: *mut T = ptr::to_mut_unsafe_ptr(&mut v[a]);
14001400
let pb: *mut T = ptr::to_mut_unsafe_ptr(&mut v[b]);
1401-
ptr::swap_ptr(pa, pb);
1401+
util::swap_ptr(pa, pb);
14021402
}
14031403
}
14041404

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern mod extra;
12+
use extra; //~ ERROR unresolved import (maybe you meant `extra::*`?)
13+
14+
fn main() {}

0 commit comments

Comments
 (0)