Skip to content

Commit b1c6998

Browse files
committed
librustc: Don't accept as Trait anymore; fix all occurrences of it.
1 parent 24a0de4 commit b1c6998

Some content is hidden

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

101 files changed

+676
-538
lines changed

doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ to pointers to the trait name, used as a type.
12271227
# impl Shape for int { }
12281228
# let mycircle = 0;
12291229
1230-
let myshape: Shape = @mycircle as @Shape;
1230+
let myshape: @Shape = @mycircle as @Shape;
12311231
~~~~
12321232

12331233
The resulting value is a managed box containing the value that was cast,

src/libcore/flate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Simple compression
1717
use libc;
1818
use libc::{c_void, size_t, c_int};
1919
use ptr;
20+
use rand::RngUtil;
2021
use vec;
2122

2223
#[cfg(test)] use rand;

src/libcore/hashmap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod linear {
2020
use hash::Hash;
2121
use iter;
2222
use option::{None, Option, Some};
23+
use rand::RngUtil;
2324
use rand;
2425
use uint;
2526
use vec;

src/libcore/io.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,7 @@ pub fn fd_writer(fd: fd_t, cleanup: bool) -> @Writer {
785785

786786

787787
pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
788-
-> Result<Writer, ~str> {
789-
788+
-> Result<@Writer, ~str> {
790789
#[cfg(windows)]
791790
fn wb() -> c_int {
792791
(O_WRONLY | libc::consts::os::extra::O_BINARY) as c_int
@@ -1079,22 +1078,24 @@ impl<T:Writer> WriterUtil for T {
10791078
}
10801079

10811080
#[allow(non_implicitly_copyable_typarams)]
1082-
pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<Writer, ~str> {
1081+
pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> {
10831082
mk_file_writer(path, flags).chain(|w| result::Ok(w))
10841083
}
10851084

10861085

10871086
// FIXME: fileflags // #2004
1088-
pub fn buffered_file_writer(path: &Path) -> Result<Writer, ~str> {
1087+
pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
10891088
unsafe {
10901089
let f = do os::as_c_charp(path.to_str()) |pathbuf| {
10911090
do os::as_c_charp("w") |modebuf| {
10921091
libc::fopen(pathbuf, modebuf)
10931092
}
10941093
};
1095-
return if f as uint == 0u { result::Err(~"error opening "
1096-
+ path.to_str()) }
1097-
else { result::Ok(FILE_writer(f, true)) }
1094+
return if f as uint == 0u {
1095+
result::Err(~"error opening " + path.to_str())
1096+
} else {
1097+
result::Ok(FILE_writer(f, true))
1098+
}
10981099
}
10991100
}
11001101
@@ -1142,14 +1143,14 @@ pub pure fn BytesWriter() -> BytesWriter {
11421143
BytesWriter { bytes: ~[], mut pos: 0u }
11431144
}
11441145
1145-
pub pure fn with_bytes_writer(f: &fn(Writer)) -> ~[u8] {
1146+
pub pure fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
11461147
let wr = @BytesWriter();
1147-
f(wr as Writer);
1148+
f(wr as @Writer);
11481149
let @BytesWriter{bytes, _} = wr;
11491150
return bytes;
11501151
}
11511152
1152-
pub pure fn with_str_writer(f: &fn(Writer)) -> ~str {
1153+
pub pure fn with_str_writer(f: &fn(@Writer)) -> ~str {
11531154
let mut v = with_bytes_writer(f);
11541155
11551156
// FIXME (#3758): This should not be needed.
@@ -1277,8 +1278,8 @@ pub mod fsync {
12771278
pub trait FSyncable { fn fsync(&self, l: Level) -> int; }
12781279

12791280
// Call o.fsync after executing blk
1280-
pub fn obj_sync(o: FSyncable, opt_level: Option<Level>,
1281-
blk: &fn(v: Res<FSyncable>)) {
1281+
pub fn obj_sync(o: @FSyncable, opt_level: Option<Level>,
1282+
blk: &fn(v: Res<@FSyncable>)) {
12821283
blk(Res(Arg {
12831284
val: o, opt_level: opt_level,
12841285
fsync_fn: |o, l| o.fsync(l)
@@ -1305,12 +1306,12 @@ mod tests {
13051306
~"A hoopy frood who really knows where his towel is.";
13061307
debug!(copy frood);
13071308
{
1308-
let out: io::Writer =
1309+
let out: @io::Writer =
13091310
result::get(
13101311
&io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
13111312
out.write_str(frood);
13121313
}
1313-
let inp: io::Reader = result::get(&io::file_reader(tmpfile));
1314+
let inp: @io::Reader = result::get(&io::file_reader(tmpfile));
13141315
let frood2: ~str = inp.read_c_str();
13151316
debug!(copy frood2);
13161317
fail_unless!(frood == frood2);

src/libcore/os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ mod tests {
12651265
use os::{remove_file, setenv};
12661266
use os;
12671267
use path::Path;
1268+
use rand::RngUtil;
12681269
use rand;
12691270
use run;
12701271
use str;
@@ -1282,7 +1283,7 @@ mod tests {
12821283
}
12831284
12841285
fn make_rand_name() -> ~str {
1285-
let rng: rand::Rng = rand::Rng();
1286+
let rng: @rand::Rng = rand::Rng();
12861287
let n = ~"TEST" + rng.gen_str(10u);
12871288
fail_unless!(getenv(n).is_none());
12881289
n

src/libcore/rand.rs

Lines changed: 100 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,97 +22,100 @@ use libc::size_t;
2222

2323
/// A type that can be randomly generated using an RNG
2424
pub trait Rand {
25-
static fn rand(rng: rand::Rng) -> Self;
25+
static fn rand(rng: @rand::Rng) -> Self;
2626
}
2727

2828
impl Rand for int {
29-
static fn rand(rng: rand::Rng) -> int {
29+
static fn rand(rng: @rand::Rng) -> int {
3030
rng.gen_int()
3131
}
3232
}
3333

3434
impl Rand for i8 {
35-
static fn rand(rng: rand::Rng) -> i8 {
35+
static fn rand(rng: @rand::Rng) -> i8 {
3636
rng.gen_i8()
3737
}
3838
}
3939

4040
impl Rand for i16 {
41-
static fn rand(rng: rand::Rng) -> i16 {
41+
static fn rand(rng: @rand::Rng) -> i16 {
4242
rng.gen_i16()
4343
}
4444
}
4545

4646
impl Rand for i32 {
47-
static fn rand(rng: rand::Rng) -> i32 {
47+
static fn rand(rng: @rand::Rng) -> i32 {
4848
rng.gen_i32()
4949
}
5050
}
5151

5252
impl Rand for i64 {
53-
static fn rand(rng: rand::Rng) -> i64 {
53+
static fn rand(rng: @rand::Rng) -> i64 {
5454
rng.gen_i64()
5555
}
5656
}
5757

5858
impl Rand for u8 {
59-
static fn rand(rng: rand::Rng) -> u8 {
59+
static fn rand(rng: @rand::Rng) -> u8 {
6060
rng.gen_u8()
6161
}
6262
}
6363

6464
impl Rand for u16 {
65-
static fn rand(rng: rand::Rng) -> u16 {
65+
static fn rand(rng: @rand::Rng) -> u16 {
6666
rng.gen_u16()
6767
}
6868
}
6969

7070
impl Rand for u32 {
71-
static fn rand(rng: rand::Rng) -> u32 {
71+
static fn rand(rng: @rand::Rng) -> u32 {
7272
rng.gen_u32()
7373
}
7474
}
7575

7676
impl Rand for u64 {
77-
static fn rand(rng: rand::Rng) -> u64 {
77+
static fn rand(rng: @rand::Rng) -> u64 {
7878
rng.gen_u64()
7979
}
8080
}
8181

8282
impl Rand for float {
83-
static fn rand(rng: rand::Rng) -> float {
83+
static fn rand(rng: @rand::Rng) -> float {
8484
rng.gen_float()
8585
}
8686
}
8787

8888
impl Rand for f32 {
89-
static fn rand(rng: rand::Rng) -> f32 {
89+
static fn rand(rng: @rand::Rng) -> f32 {
9090
rng.gen_f32()
9191
}
9292
}
9393

9494
impl Rand for f64 {
95-
static fn rand(rng: rand::Rng) -> f64 {
95+
static fn rand(rng: @rand::Rng) -> f64 {
9696
rng.gen_f64()
9797
}
9898
}
9999

100100
impl Rand for char {
101-
static fn rand(rng: rand::Rng) -> char {
101+
static fn rand(rng: @rand::Rng) -> char {
102102
rng.gen_char()
103103
}
104104
}
105105

106106
impl Rand for bool {
107-
static fn rand(rng: rand::Rng) -> bool {
107+
static fn rand(rng: @rand::Rng) -> bool {
108108
rng.gen_bool()
109109
}
110110
}
111111

112112
impl<T:Rand> Rand for Option<T> {
113-
static fn rand(rng: rand::Rng) -> Option<T> {
114-
if rng.gen_bool() { Some(Rand::rand(rng)) }
115-
else { None }
113+
static fn rand(rng: @rand::Rng) -> Option<T> {
114+
if rng.gen_bool() {
115+
Some(Rand::rand(rng))
116+
} else {
117+
None
118+
}
116119
}
117120
}
118121

@@ -145,8 +148,83 @@ pub struct Weighted<T> {
145148
item: T,
146149
}
147150

151+
pub trait RngUtil {
152+
fn gen<T:Rand>(&self) -> T;
153+
/// Return a random int
154+
fn gen_int(&self) -> int;
155+
fn gen_int_range(&self, start: int, end: int) -> int;
156+
/// Return a random i8
157+
fn gen_i8(&self) -> i8;
158+
/// Return a random i16
159+
fn gen_i16(&self) -> i16;
160+
/// Return a random i32
161+
fn gen_i32(&self) -> i32;
162+
/// Return a random i64
163+
fn gen_i64(&self) -> i64;
164+
/// Return a random uint
165+
fn gen_uint(&self) -> uint;
166+
/**
167+
* Return a uint randomly chosen from the range [start, end),
168+
* failing if start >= end
169+
*/
170+
fn gen_uint_range(&self, start: uint, end: uint) -> uint;
171+
/// Return a random u8
172+
fn gen_u8(&self) -> u8;
173+
/// Return a random u16
174+
fn gen_u16(&self) -> u16;
175+
/// Return a random u32
176+
fn gen_u32(&self) -> u32;
177+
/// Return a random u64
178+
fn gen_u64(&self) -> u64;
179+
/// Return a random float in the interval [0,1]
180+
fn gen_float(&self) -> float;
181+
/// Return a random f32 in the interval [0,1]
182+
fn gen_f32(&self) -> f32;
183+
/// Return a random f64 in the interval [0,1]
184+
fn gen_f64(&self) -> f64;
185+
/// Return a random char
186+
fn gen_char(&self) -> char;
187+
/**
188+
* Return a char randomly chosen from chars, failing if chars is empty
189+
*/
190+
fn gen_char_from(&self, chars: &str) -> char;
191+
/// Return a random bool
192+
fn gen_bool(&self) -> bool;
193+
/// Return a bool with a 1 in n chance of true
194+
fn gen_weighted_bool(&self, n: uint) -> bool;
195+
/**
196+
* Return a random string of the specified length composed of A-Z,a-z,0-9
197+
*/
198+
fn gen_str(&self, len: uint) -> ~str;
199+
/// Return a random byte string of the specified length
200+
fn gen_bytes(&self, len: uint) -> ~[u8];
201+
/// Choose an item randomly, failing if values is empty
202+
fn choose<T:Copy>(&self, values: &[T]) -> T;
203+
/// Choose Some(item) randomly, returning None if values is empty
204+
fn choose_option<T:Copy>(&self, values: &[T]) -> Option<T>;
205+
/**
206+
* Choose an item respecting the relative weights, failing if the sum of
207+
* the weights is 0
208+
*/
209+
fn choose_weighted<T:Copy>(&self, v : &[Weighted<T>]) -> T;
210+
/**
211+
* Choose Some(item) respecting the relative weights, returning none if
212+
* the sum of the weights is 0
213+
*/
214+
fn choose_weighted_option<T:Copy>(&self, v: &[Weighted<T>]) -> Option<T>;
215+
/**
216+
* Return a vec containing copies of the items, in order, where
217+
* the weight of the item determines how many copies there are
218+
*/
219+
fn weighted_vec<T:Copy>(&self, v: &[Weighted<T>]) -> ~[T];
220+
/// Shuffle a vec
221+
fn shuffle<T:Copy>(&self, values: &[T]) -> ~[T];
222+
/// Shuffle a mutable vec in place
223+
fn shuffle_mut<T>(&self, values: &mut [T]);
224+
}
225+
148226
/// Extension methods for random number generators
149-
pub impl Rng {
227+
impl RngUtil for @Rng {
150228
/// Return a random value for a Rand type
151229
fn gen<T:Rand>(&self) -> T {
152230
Rand::rand(*self)
@@ -407,7 +485,7 @@ pub fn seed() -> ~[u8] {
407485
}
408486

409487
/// Create a random number generator with a system specified seed
410-
pub fn Rng() -> Rng {
488+
pub fn Rng() -> @Rng {
411489
seeded_rng(seed())
412490
}
413491

@@ -449,7 +527,7 @@ impl Rng for XorShiftState {
449527
}
450528
}
451529

452-
pub pure fn xorshift() -> Rng {
530+
pub pure fn xorshift() -> @Rng {
453531
// constants taken from http://en.wikipedia.org/wiki/Xorshift
454532
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
455533
}
@@ -467,7 +545,7 @@ fn tls_rng_state(_v: @RandRes) {}
467545
* seeded by the system. Intended to be used in method chaining style, ie
468546
* task_rng().gen_int().
469547
*/
470-
pub fn task_rng() -> Rng {
548+
pub fn task_rng() -> @Rng {
471549
let r : Option<@RandRes>;
472550
unsafe {
473551
r = task::local_data::local_data_get(tls_rng_state);

src/libcore/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ trait EscapedCharWriter {
4141
fn write_escaped_char(&self, ch: char);
4242
}
4343

44-
impl EscapedCharWriter for Writer {
44+
impl EscapedCharWriter for @Writer {
4545
fn write_escaped_char(&self, ch: char) {
4646
match ch {
4747
'\t' => self.write_str("\\t"),

0 commit comments

Comments
 (0)