Skip to content

Commit 1af9d21

Browse files
committed
---
yaml --- r: 102349 b: refs/heads/master c: 4cdc6ce h: refs/heads/master i: 102347: 0764910 v: v3
1 parent e4f68c2 commit 1af9d21

File tree

20 files changed

+161
-99
lines changed

20 files changed

+161
-99
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: dcb24f5450c88ef17d47304685d2a1a0d82b2dbd
2+
refs/heads/master: 4cdc6ce3374f934b6c8cab986d3b0c83119fed6f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/libgreen/simple.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! A small module implementing a simple "runtime" used for bootstrapping a rust
1212
//! scheduler pool and then interacting with it.
1313
14-
use std::any::Any;
1514
use std::cast;
1615
use std::rt::Runtime;
1716
use std::rt::local::Local;

trunk/src/libgreen/task.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
//! contains the rust task itself in order to juggle around ownership of the
1919
//! values.
2020
21-
use std::any::Any;
2221
use std::cast;
2322
use std::rt::env;
2423
use std::rt::Runtime;

trunk/src/libnative/task.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//! by rust tasks. This implements the necessary API traits laid out by std::rt
1515
//! in order to spawn new tasks and deschedule the current task.
1616
17-
use std::any::Any;
1817
use std::cast;
1918
use std::rt::env;
2019
use std::rt::local::Local;

trunk/src/librustc/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ This API is completely unstable and subject to change.
2727
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2828
html_root_url = "http://static.rust-lang.org/doc/master")];
2929

30-
#[allow(deprecated)];
3130
#[feature(macro_rules, globs, struct_variant, managed_boxes)];
3231
#[feature(quote)];
3332

@@ -47,7 +46,6 @@ use middle::lint;
4746

4847
use d = driver::driver;
4948

50-
use std::any::AnyRefExt;
5149
use std::cmp;
5250
use std::io;
5351
use std::os;

trunk/src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,10 @@ impl CStore {
154154
.collect()
155155
}
156156

157-
pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind)
158-
-> bool {
157+
pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind) {
159158
assert!(!lib.is_empty());
160159
let mut used_libraries = self.used_libraries.borrow_mut();
161-
if used_libraries.get().iter().any(|&(ref x, _)| x == &lib) {
162-
return false;
163-
}
164160
used_libraries.get().push((lib, kind));
165-
true
166161
}
167162

168163
pub fn get_used_libraries<'a>(&'a self)

trunk/src/libserialize/json.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,6 @@ mod tests {
22292229
B(~str)
22302230
}
22312231
fn check_err<T: Decodable<Decoder>>(to_parse: &'static str, expected_error: &str) {
2232-
use std::any::AnyRefExt;
22332232
use std::task;
22342233
let res = task::try(proc() {
22352234
// either fails in `decode` (which is what we want), or

trunk/src/libstd/any.rs

Lines changed: 117 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
//! value. `~Any` adds the `move` method, which will unwrap a `~T` from the object. See the
2121
//! extension traits (`*Ext`) for the full details.
2222
23-
use cast::{transmute, transmute_copy};
23+
use cast::transmute;
2424
use fmt;
2525
use option::{Option, Some, None};
26-
use raw::TraitObject;
2726
use result::{Result, Ok, Err};
2827
use intrinsics::TypeId;
2928
use intrinsics;
@@ -40,18 +39,34 @@ pub enum Void { }
4039
pub trait Any {
4140
/// Get the `TypeId` of `self`
4241
fn get_type_id(&self) -> TypeId;
42+
43+
/// Get a void pointer to `self`
44+
fn as_void_ptr(&self) -> *Void;
45+
46+
/// Get a mutable void pointer to `self`
47+
fn as_mut_void_ptr(&mut self) -> *mut Void;
4348
}
4449

4550
impl<T: 'static> Any for T {
4651
/// Get the `TypeId` of `self`
4752
fn get_type_id(&self) -> TypeId {
4853
TypeId::of::<T>()
4954
}
55+
56+
/// Get a void pointer to `self`
57+
fn as_void_ptr(&self) -> *Void {
58+
self as *T as *Void
59+
}
60+
61+
/// Get a mutable void pointer to `self`
62+
fn as_mut_void_ptr(&mut self) -> *mut Void {
63+
self as *mut T as *mut Void
64+
}
5065
}
5166

5267
///////////////////////////////////////////////////////////////////////////////
5368
// Extension methods for Any trait objects.
54-
// Implemented as three extension traits so that the methods can be generic.
69+
// Implemented as three extension traits so that generics work.
5570
///////////////////////////////////////////////////////////////////////////////
5671

5772
/// Extension methods for a referenced `Any` trait object
@@ -80,13 +95,7 @@ impl<'a> AnyRefExt<'a> for &'a Any {
8095
#[inline]
8196
fn as_ref<T: 'static>(self) -> Option<&'a T> {
8297
if self.is::<T>() {
83-
unsafe {
84-
// Get the raw representation of the trait object
85-
let to: TraitObject = transmute_copy(&self);
86-
87-
// Extract the data pointer
88-
Some(transmute(to.data))
89-
}
98+
Some(unsafe { transmute(self.as_void_ptr()) })
9099
} else {
91100
None
92101
}
@@ -104,13 +113,7 @@ impl<'a> AnyMutRefExt<'a> for &'a mut Any {
104113
#[inline]
105114
fn as_mut<T: 'static>(self) -> Option<&'a mut T> {
106115
if self.is::<T>() {
107-
unsafe {
108-
// Get the raw representation of the trait object
109-
let to: TraitObject = transmute_copy(&self);
110-
111-
// Extract the data pointer
112-
Some(transmute(to.data))
113-
}
116+
Some(unsafe { transmute(self.as_mut_void_ptr()) })
114117
} else {
115118
None
116119
}
@@ -129,14 +132,13 @@ impl AnyOwnExt for ~Any {
129132
fn move<T: 'static>(self) -> Result<~T, ~Any> {
130133
if self.is::<T>() {
131134
unsafe {
132-
// Get the raw representation of the trait object
133-
let to: TraitObject = transmute_copy(&self);
135+
// Extract the pointer to the boxed value, temporary alias with self
136+
let ptr: ~T = transmute(self.as_void_ptr());
134137

135138
// Prevent destructor on self being run
136139
intrinsics::forget(self);
137140

138-
// Extract the data pointer
139-
Ok(transmute(to.data))
141+
Ok(ptr)
140142
}
141143
} else {
142144
Err(self)
@@ -170,6 +172,100 @@ mod tests {
170172

171173
static TEST: &'static str = "Test";
172174

175+
#[test]
176+
fn any_as_void_ptr() {
177+
let (a, b, c) = (~5u as ~Any, ~TEST as ~Any, ~Test as ~Any);
178+
let a_r: &Any = a;
179+
let b_r: &Any = b;
180+
let c_r: &Any = c;
181+
182+
assert_eq!(a.as_void_ptr(), a_r.as_void_ptr());
183+
assert_eq!(b.as_void_ptr(), b_r.as_void_ptr());
184+
assert_eq!(c.as_void_ptr(), c_r.as_void_ptr());
185+
186+
let (a, b, c) = (&5u as &Any, &TEST as &Any, &Test as &Any);
187+
let a_r: &Any = a;
188+
let b_r: &Any = b;
189+
let c_r: &Any = c;
190+
191+
assert_eq!(a.as_void_ptr(), a_r.as_void_ptr());
192+
assert_eq!(b.as_void_ptr(), b_r.as_void_ptr());
193+
assert_eq!(c.as_void_ptr(), c_r.as_void_ptr());
194+
195+
let mut x = Test;
196+
let mut y: &'static str = "Test";
197+
let (a, b, c) = (&mut 5u as &mut Any,
198+
&mut y as &mut Any,
199+
&mut x as &mut Any);
200+
let a_r: &Any = a;
201+
let b_r: &Any = b;
202+
let c_r: &Any = c;
203+
204+
assert_eq!(a.as_void_ptr(), a_r.as_void_ptr());
205+
assert_eq!(b.as_void_ptr(), b_r.as_void_ptr());
206+
assert_eq!(c.as_void_ptr(), c_r.as_void_ptr());
207+
208+
let (a, b, c) = (5u, "hello", Test);
209+
let (a_r, b_r, c_r) = (&a as &Any, &b as &Any, &c as &Any);
210+
211+
assert_eq!(a.as_void_ptr(), a_r.as_void_ptr());
212+
assert_eq!(b.as_void_ptr(), b_r.as_void_ptr());
213+
assert_eq!(c.as_void_ptr(), c_r.as_void_ptr());
214+
}
215+
216+
#[test]
217+
fn any_as_mut_void_ptr() {
218+
let y: &'static str = "Test";
219+
let mut a = ~5u as ~Any;
220+
let mut b = ~y as ~Any;
221+
let mut c = ~Test as ~Any;
222+
223+
let a_ptr = a.as_mut_void_ptr();
224+
let b_ptr = b.as_mut_void_ptr();
225+
let c_ptr = c.as_mut_void_ptr();
226+
227+
let a_r: &mut Any = a;
228+
let b_r: &mut Any = b;
229+
let c_r: &mut Any = c;
230+
231+
assert_eq!(a_ptr, a_r.as_mut_void_ptr());
232+
assert_eq!(b_ptr, b_r.as_mut_void_ptr());
233+
assert_eq!(c_ptr, c_r.as_mut_void_ptr());
234+
235+
let mut x = Test;
236+
let mut y: &'static str = "Test";
237+
let a = &mut 5u as &mut Any;
238+
let b = &mut y as &mut Any;
239+
let c = &mut x as &mut Any;
240+
241+
let a_ptr = a.as_mut_void_ptr();
242+
let b_ptr = b.as_mut_void_ptr();
243+
let c_ptr = c.as_mut_void_ptr();
244+
245+
let a_r: &mut Any = a;
246+
let b_r: &mut Any = b;
247+
let c_r: &mut Any = c;
248+
249+
assert_eq!(a_ptr, a_r.as_mut_void_ptr());
250+
assert_eq!(b_ptr, b_r.as_mut_void_ptr());
251+
assert_eq!(c_ptr, c_r.as_mut_void_ptr());
252+
253+
let y: &'static str = "Test";
254+
let mut a = 5u;
255+
let mut b = y;
256+
let mut c = Test;
257+
258+
let a_ptr = a.as_mut_void_ptr();
259+
let b_ptr = b.as_mut_void_ptr();
260+
let c_ptr = c.as_mut_void_ptr();
261+
262+
let (a_r, b_r, c_r) = (&mut a as &mut Any, &mut b as &mut Any, &mut c as &mut Any);
263+
264+
assert_eq!(a_ptr, a_r.as_mut_void_ptr());
265+
assert_eq!(b_ptr, b_r.as_mut_void_ptr());
266+
assert_eq!(c_ptr, c_r.as_mut_void_ptr());
267+
}
268+
173269
#[test]
174270
fn any_referenced() {
175271
let (a, b, c) = (&5u as &Any, &TEST as &Any, &Test as &Any);
@@ -299,21 +395,3 @@ mod tests {
299395
assert_eq!(format!("{}", b), ~"&Any");
300396
}
301397
}
302-
303-
#[cfg(test)]
304-
mod bench {
305-
extern crate test;
306-
307-
use any::{Any, AnyRefExt};
308-
use option::Some;
309-
use self::test::BenchHarness;
310-
311-
#[bench]
312-
fn bench_as_ref(bh: &mut BenchHarness) {
313-
bh.iter(|| {
314-
let mut x = 0; let mut y = &mut x as &mut Any;
315-
test::black_box(&mut y);
316-
test::black_box(y.as_ref::<int>() == Some(&0));
317-
});
318-
}
319-
}

trunk/src/libstd/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub use mem::drop;
3535

3636
// Reexported types and traits
3737

38+
pub use any::{Any, AnyOwnExt, AnyRefExt, AnyMutRefExt};
3839
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, IntoBytes};
3940
pub use c_str::ToCStr;
4041
pub use char::Char;

trunk/src/libstd/raw.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010

1111
#[allow(missing_doc)];
1212

13-
//! Contains struct definitions for the layout of compiler built-in types.
14-
//!
15-
//! They can be used as targets of transmutes in unsafe code for manipulating
16-
//! the raw representations directly.
17-
//!
18-
//! Their definitition should always match the ABI defined in `rustc::back::abi`.
19-
2013
use cast;
2114

2215
/// The representation of a Rust managed box
@@ -56,22 +49,13 @@ pub struct Procedure {
5649
env: *(),
5750
}
5851

59-
/// The representation of a Rust trait object.
60-
///
61-
/// This struct does not have a `Repr` implementation
62-
/// because there is no way to refer to all trait objects generically.
63-
pub struct TraitObject {
64-
vtable: *(),
65-
data: *(),
66-
}
67-
6852
/// This trait is meant to map equivalences between raw structs and their
6953
/// corresponding rust values.
7054
pub trait Repr<T> {
7155
/// This function "unwraps" a rust value (without consuming it) into its raw
7256
/// struct representation. This can be used to read/write different values
7357
/// for the struct. This is a safe method because by default it does not
74-
/// enable write-access to the fields of the return value in safe code.
58+
/// give write-access to the struct returned.
7559
#[inline]
7660
fn repr(&self) -> T { unsafe { cast::transmute_copy(self) } }
7761
}

trunk/src/libstd/vec.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,13 +2311,11 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
23112311
if mem::size_of::<T>() == 0 {
23122312
MutItems{ptr: p,
23132313
end: (p as uint + self.len()) as *mut T,
2314-
marker: marker::ContravariantLifetime::<'a>,
2315-
marker2: marker::NoPod}
2314+
marker: marker::ContravariantLifetime::<'a>}
23162315
} else {
23172316
MutItems{ptr: p,
23182317
end: p.offset(self.len() as int),
2319-
marker: marker::ContravariantLifetime::<'a>,
2320-
marker2: marker::NoPod}
2318+
marker: marker::ContravariantLifetime::<'a>}
23212319
}
23222320
}
23232321
}
@@ -2684,23 +2682,15 @@ impl<A> Default for ~[A] {
26842682
fn default() -> ~[A] { ~[] }
26852683
}
26862684

2687-
/// Immutable slice iterator
2688-
pub struct Items<'a, T> {
2689-
priv ptr: *T,
2690-
priv end: *T,
2691-
priv marker: marker::ContravariantLifetime<'a>
2692-
}
2693-
2694-
/// Mutable slice iterator
2695-
pub struct MutItems<'a, T> {
2696-
priv ptr: *mut T,
2697-
priv end: *mut T,
2698-
priv marker: marker::ContravariantLifetime<'a>,
2699-
priv marker2: marker::NoPod
2700-
}
2701-
27022685
macro_rules! iterator {
27032686
(struct $name:ident -> $ptr:ty, $elem:ty) => {
2687+
/// An iterator for iterating over a vector.
2688+
pub struct $name<'a, T> {
2689+
priv ptr: $ptr,
2690+
priv end: $ptr,
2691+
priv marker: marker::ContravariantLifetime<'a>,
2692+
}
2693+
27042694
impl<'a, T> Iterator<$elem> for $name<'a, T> {
27052695
#[inline]
27062696
fn next(&mut self) -> Option<$elem> {

trunk/src/libstd/vec_ng.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ impl<T> Vec<T> {
369369
}
370370

371371
#[inline]
372-
#[deprecated="Use `xs.iter().map(closure)` instead."]
373372
pub fn map<U>(&self, f: |t: &T| -> U) -> Vec<U> {
374373
self.iter().map(f).collect()
375374
}

0 commit comments

Comments
 (0)