Skip to content

Commit 73a7672

Browse files
committed
std: Stamp out structural records
See rust-lang#4665
1 parent 27e1ac5 commit 73a7672

File tree

8 files changed

+74
-71
lines changed

8 files changed

+74
-71
lines changed

src/libstd/c_vec.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ use core::task;
4646
/**
4747
* The type representing a foreign chunk of memory
4848
*
49-
* Wrapped in a enum for opacity; FIXME #818 when it is possible to have
50-
* truly opaque types, this should be revisited.
5149
*/
52-
pub enum CVec<T> {
53-
CVecCtor({ base: *mut T, len: uint, rsrc: @DtorRes})
50+
pub struct CVec<T> {
51+
priv base: *mut T,
52+
priv len: uint,
53+
priv rsrc: @DtorRes
5454
}
5555

5656
struct DtorRes {
@@ -85,11 +85,11 @@ fn DtorRes(dtor: Option<fn@()>) -> DtorRes {
8585
* * len - The number of elements in the buffer
8686
*/
8787
pub unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
88-
return CVecCtor({
88+
return CVec{
8989
base: base,
9090
len: len,
9191
rsrc: @DtorRes(option::None)
92-
});
92+
};
9393
}
9494

9595
/**
@@ -105,11 +105,11 @@ pub unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
105105
*/
106106
pub unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
107107
-> CVec<T> {
108-
return CVecCtor({
108+
return CVec{
109109
base: base,
110110
len: len,
111111
rsrc: @DtorRes(option::Some(dtor))
112-
});
112+
};
113113
}
114114

115115
/*
@@ -123,7 +123,7 @@ pub unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
123123
*/
124124
pub fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
125125
assert ofs < len(t);
126-
return unsafe { *ptr::mut_offset((*t).base, ofs) };
126+
return unsafe { *ptr::mut_offset(t.base, ofs) };
127127
}
128128

129129
/**
@@ -133,22 +133,18 @@ pub fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
133133
*/
134134
pub fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
135135
assert ofs < len(t);
136-
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
136+
unsafe { *ptr::mut_offset(t.base, ofs) = v };
137137
}
138138

139139
/*
140140
Section: Elimination forms
141141
*/
142142

143143
/// Returns the length of the vector
144-
pub pure fn len<T>(t: CVec<T>) -> uint {
145-
return (*t).len;
146-
}
144+
pub pure fn len<T>(t: CVec<T>) -> uint { t.len }
147145

148146
/// Returns a pointer to the first element of the vector
149-
pub unsafe fn ptr<T>(t: CVec<T>) -> *mut T {
150-
return (*t).base;
151-
}
147+
pub unsafe fn ptr<T>(t: CVec<T>) -> *mut T { t.base }
152148

153149
#[cfg(test)]
154150
mod tests {

src/libstd/ebml.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,27 @@ pub mod reader {
8484
}
8585
}
8686

87-
fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
87+
struct Res {
88+
val: uint,
89+
next: uint
90+
}
91+
92+
fn vuint_at(data: &[u8], start: uint) -> Res {
8893
let a = data[start];
8994
if a & 0x80u8 != 0u8 {
90-
return {val: (a & 0x7fu8) as uint, next: start + 1u};
95+
return Res {val: (a & 0x7fu8) as uint, next: start + 1u};
9196
}
9297
if a & 0x40u8 != 0u8 {
93-
return {val: ((a & 0x3fu8) as uint) << 8u |
98+
return Res {val: ((a & 0x3fu8) as uint) << 8u |
9499
(data[start + 1u] as uint),
95100
next: start + 2u};
96101
} else if a & 0x20u8 != 0u8 {
97-
return {val: ((a & 0x1fu8) as uint) << 16u |
102+
return Res {val: ((a & 0x1fu8) as uint) << 16u |
98103
(data[start + 1u] as uint) << 8u |
99104
(data[start + 2u] as uint),
100105
next: start + 3u};
101106
} else if a & 0x10u8 != 0u8 {
102-
return {val: ((a & 0x0fu8) as uint) << 24u |
107+
return Res {val: ((a & 0x0fu8) as uint) << 24u |
103108
(data[start + 1u] as uint) << 16u |
104109
(data[start + 2u] as uint) << 8u |
105110
(data[start + 3u] as uint),

src/libstd/md4.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ use core::str;
1414
use core::uint;
1515
use core::vec;
1616

17-
pub pure fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
17+
struct Quad {
18+
a: u32,
19+
b: u32,
20+
c: u32,
21+
d: u32
22+
}
23+
24+
pub pure fn md4(msg: &[u8]) -> Quad {
1825
// subtle: if orig_len is merely uint, then the code below
1926
// which performs shifts by 32 bits or more has undefined
2027
// results.
@@ -95,11 +102,11 @@ pub pure fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
95102
a += aa; b += bb; c += cc; d += dd;
96103
i += 64u;
97104
}
98-
return {a: a, b: b, c: c, d: d};
105+
return Quad {a: a, b: b, c: c, d: d};
99106
}
100107

101108
pub pure fn md4_str(msg: &[u8]) -> ~str {
102-
let {a, b, c, d} = md4(msg);
109+
let Quad {a, b, c, d} = md4(msg);
103110
pure fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
104111
f(a); f(b); f(c); f(d);
105112
}

src/libstd/sha1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const k3: u32 = 0xCA62C1D6u32;
6666

6767
/// Construct a `sha` object
6868
pub fn sha1() -> Sha1 {
69-
type Sha1State =
69+
struct Sha1State
7070
{h: ~[mut u32],
7171
mut len_low: u32,
7272
mut len_high: u32,
@@ -258,7 +258,7 @@ pub fn sha1() -> Sha1 {
258258
return s;
259259
}
260260
}
261-
let st = {
261+
let st = Sha1State {
262262
h: vec::cast_to_mut(vec::from_elem(digest_buf_len, 0u32)),
263263
mut len_low: 0u32,
264264
mut len_high: 0u32,

src/libstd/std.rc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ not required in or otherwise suitable for the core library.
3434
#[forbid(deprecated_pattern)];
3535
#[allow(deprecated_self)];
3636

37-
38-
// Transitional
39-
#[legacy_records];
40-
4137
#[no_core];
4238

4339
extern mod core(vers = "0.6");

src/libstd/test.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
9292
};
9393
9494
let filter =
95-
if vec::len(matches.free) > 0u {
95+
if vec::len(matches.free) > 0 {
9696
option::Some(matches.free[0])
9797
} else { option::None };
9898
@@ -111,26 +111,27 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
111111
#[deriving_eq]
112112
pub enum TestResult { TrOk, TrFailed, TrIgnored, }
113113
114-
type ConsoleTestState =
115-
@{out: io::Writer,
116-
log_out: Option<io::Writer>,
117-
use_color: bool,
118-
mut total: uint,
119-
mut passed: uint,
120-
mut failed: uint,
121-
mut ignored: uint,
122-
mut failures: ~[TestDesc]};
114+
struct ConsoleTestState {
115+
out: io::Writer,
116+
log_out: Option<io::Writer>,
117+
use_color: bool,
118+
mut total: uint,
119+
mut passed: uint,
120+
mut failed: uint,
121+
mut ignored: uint,
122+
mut failures: ~[TestDesc]
123+
}
123124
124125
// A simple console test runner
125126
pub fn run_tests_console(opts: &TestOpts,
126127
tests: &[TestDesc]) -> bool {
127128
128-
fn callback(event: &TestEvent, st: ConsoleTestState) {
129+
fn callback(event: &TestEvent, st: @ConsoleTestState) {
129130
debug!("callback(event=%?)", event);
130131
match *event {
131132
TeFiltered(ref filtered_tests) => {
132133
st.total = filtered_tests.len();
133-
let noun = if st.total != 1u { ~"tests" } else { ~"test" };
134+
let noun = if st.total != 1 { ~"tests" } else { ~"test" };
134135
st.out.write_line(fmt!("\nrunning %u %s", st.total, noun));
135136
}
136137
TeWait(ref test) => st.out.write_str(
@@ -142,18 +143,18 @@ pub fn run_tests_console(opts: &TestOpts,
142143
}
143144
match result {
144145
TrOk => {
145-
st.passed += 1u;
146+
st.passed += 1;
146147
write_ok(st.out, st.use_color);
147148
st.out.write_line(~"");
148149
}
149150
TrFailed => {
150-
st.failed += 1u;
151+
st.failed += 1;
151152
write_failed(st.out, st.use_color);
152153
st.out.write_line(~"");
153154
st.failures.push(move test);
154155
}
155156
TrIgnored => {
156-
st.ignored += 1u;
157+
st.ignored += 1;
157158
write_ignored(st.out, st.use_color);
158159
st.out.write_line(~"");
159160
}
@@ -174,19 +175,19 @@ pub fn run_tests_console(opts: &TestOpts,
174175
};
175176
176177
let st =
177-
@{out: io::stdout(),
178+
@ConsoleTestState{out: io::stdout(),
178179
log_out: log_out,
179180
use_color: use_color(),
180-
mut total: 0u,
181-
mut passed: 0u,
182-
mut failed: 0u,
183-
mut ignored: 0u,
181+
mut total: 0,
182+
mut passed: 0,
183+
mut failed: 0,
184+
mut ignored: 0,
184185
mut failures: ~[]};
185186
186187
run_tests(opts, tests, |x| callback(&x, st));
187188
188189
assert (st.passed + st.failed + st.ignored == st.total);
189-
let success = st.failed == 0u;
190+
let success = st.failed == 0;
190191
191192
if !success {
192193
print_failures(st);
@@ -234,7 +235,7 @@ pub fn run_tests_console(opts: &TestOpts,
234235
}
235236
}
236237
237-
fn print_failures(st: ConsoleTestState) {
238+
fn print_failures(st: @ConsoleTestState) {
238239
st.out.write_line(~"\nfailures:");
239240
let failures = copy st.failures;
240241
let failures = vec::map(failures, |test| test.name);
@@ -262,13 +263,13 @@ fn should_sort_failures_before_printing_them() {
262263
};
263264
264265
let st =
265-
@{out: wr,
266+
@ConsoleTestState{out: wr,
266267
log_out: option::None,
267268
use_color: false,
268-
mut total: 0u,
269-
mut passed: 0u,
270-
mut failed: 0u,
271-
mut ignored: 0u,
269+
mut total: 0,
270+
mut passed: 0,
271+
mut failed: 0,
272+
mut ignored: 0,
272273
mut failures: ~[move test_b, move test_a]};
273274
274275
print_failures(st);
@@ -279,7 +280,7 @@ fn should_sort_failures_before_printing_them() {
279280
assert apos < bpos;
280281
}
281282
282-
fn use_color() -> bool { return get_concurrency() == 1u; }
283+
fn use_color() -> bool { return get_concurrency() == 1; }
283284
284285
enum TestEvent {
285286
TeFiltered(~[TestDesc]),
@@ -334,15 +335,15 @@ fn run_tests(opts: &TestOpts,
334335
335336
// Windows tends to dislike being overloaded with threads.
336337
#[cfg(windows)]
337-
const sched_overcommit : uint = 1u;
338+
const sched_overcommit : uint = 1;
338339
339340
#[cfg(unix)]
340341
const sched_overcommit : uint = 4u;
341342
342343
fn get_concurrency() -> uint {
343344
unsafe {
344345
let threads = rustrt::rust_sched_threads() as uint;
345-
if threads == 1u { 1u }
346+
if threads == 1 { 1 }
346347
else { threads * sched_overcommit }
347348
}
348349
}
@@ -556,7 +557,7 @@ mod tests {
556557
];
557558
let filtered = filter_tests(&opts, tests);
558559
559-
assert (vec::len(filtered) == 1u);
560+
assert (vec::len(filtered) == 1);
560561
assert (filtered[0].name == ~"1");
561562
assert (filtered[0].ignore == false);
562563
}

src/libstd/uv_iotask.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@ use core::task::TaskBuilder;
2727
use core::task;
2828

2929
/// Used to abstract-away direct interaction with a libuv loop.
30-
pub enum IoTask {
31-
IoTask_({
32-
async_handle: *ll::uv_async_t,
33-
op_chan: SharedChan<IoTaskMsg>
34-
})
30+
pub struct IoTask {
31+
async_handle: *ll::uv_async_t,
32+
op_chan: SharedChan<IoTaskMsg>
3533
}
3634

3735
impl IoTask: Clone {
3836
fn clone(&self) -> IoTask {
39-
IoTask_({
37+
IoTask{
4038
async_handle: self.async_handle,
4139
op_chan: self.op_chan.clone()
42-
})
40+
}
4341
}
4442
}
4543

@@ -131,10 +129,10 @@ fn run_loop(iotask_ch: &Chan<IoTask>) {
131129

132130
// Send out a handle through which folks can talk to us
133131
// while we dwell in the I/O loop
134-
let iotask = IoTask_({
132+
let iotask = IoTask{
135133
async_handle: async_handle,
136134
op_chan: SharedChan(msg_ch)
137-
});
135+
};
138136
iotask_ch.send(iotask);
139137

140138
log(debug, ~"about to run uv loop");

src/libstd/uv_ll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ pub mod test {
15431543
let continue_async_handle_ptr =
15441544
ptr::addr_of(&continue_async_handle);
15451545
let async_data =
1546-
{ continue_chan: continue_chan };
1546+
async_handle_data { continue_chan: continue_chan };
15471547
let async_data_ptr = ptr::addr_of(&async_data);
15481548

15491549
let server_data = tcp_server_data {

0 commit comments

Comments
 (0)