Skip to content

Commit 28f54a0

Browse files
committed
auto merge of #4839 : catamorphism/rust/rm-structural-records, r=catamorphism
2 parents e8fc4b3 + b0b5505 commit 28f54a0

File tree

8 files changed

+44
-65
lines changed

8 files changed

+44
-65
lines changed

src/libcargo/pgp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::os;
1212
use core::path::Path;
1313
use core::run;
1414

15-
pub fn gpgv(args: ~[~str]) -> { status: int, out: ~str, err: ~str } {
15+
pub fn gpgv(args: ~[~str]) -> run::ProgramOutput {
1616
return run::program_output(~"gpgv", args);
1717
}
1818

src/libcore/extfmt.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
//! * s - str (any flavor)
5252
//! * ? - arbitrary type (does not use the to_str trait)
5353
54-
// Transitional
55-
#[allow(structural_records)]; // Macros -- needs a snapshot
56-
5754
/*
5855
Syntax Extension: fmt
5956
@@ -619,11 +616,11 @@ pub mod rt {
619616
let padstr = str::from_chars(vec::from_elem(diff, padchar));
620617
return s + padstr;
621618
}
622-
let {might_zero_pad, signed} = match mode {
623-
PadNozero => {might_zero_pad:false, signed:false},
624-
PadSigned => {might_zero_pad:true, signed:true },
625-
PadFloat => {might_zero_pad:true, signed:true},
626-
PadUnsigned => {might_zero_pad:true, signed:false}
619+
let (might_zero_pad, signed) = match mode {
620+
PadNozero => (false, true),
621+
PadSigned => (true, true),
622+
PadFloat => (true, true),
623+
PadUnsigned => (true, false)
627624
};
628625
pure fn have_precision(cv: Conv) -> bool {
629626
return match cv.precision { CountImplied => false, _ => true };

src/libcore/gc.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ with destructors.
3535
3636
*/
3737

38-
// Transitional
39-
#[allow(structural_records)];
40-
4138
use cast;
4239
use container::{Container, Mutable, Map, Set};
4340
use io;
@@ -172,12 +169,14 @@ unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
172169
return begin <= frame && frame <= end;
173170
}
174171

172+
struct Segment { segment: *StackSegment, boundary: bool }
173+
175174
// Find and return the segment containing the given frame pointer. At
176175
// stack segment boundaries, returns true for boundary, so that the
177176
// caller can do any special handling to identify where the correct
178177
// return address is in the stack frame.
179178
unsafe fn find_segment_for_frame(fp: *Word, segment: *StackSegment)
180-
-> {segment: *StackSegment, boundary: bool} {
179+
-> Segment {
181180
// Check if frame is in either current frame or previous frame.
182181
let in_segment = is_frame_in_segment(fp, segment);
183182
let in_prev_segment = ptr::is_not_null((*segment).prev) &&
@@ -191,16 +190,16 @@ unsafe fn find_segment_for_frame(fp: *Word, segment: *StackSegment)
191190
is_frame_in_segment(fp, (*segment).next) {
192191
segment = (*segment).next;
193192
}
194-
return {segment: segment, boundary: false};
193+
return Segment {segment: segment, boundary: false};
195194
}
196195

197196
// If frame is in previous frame, then we're at a boundary.
198197
if !in_segment && in_prev_segment {
199-
return {segment: (*segment).prev, boundary: true};
198+
return Segment {segment: (*segment).prev, boundary: true};
200199
}
201200

202201
// Otherwise, we're somewhere on the inside of the frame.
203-
return {segment: segment, boundary: false};
202+
return Segment {segment: segment, boundary: false};
204203
}
205204

206205
type Memory = uint;
@@ -224,7 +223,7 @@ unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) {
224223
for stackwalk::walk_stack |frame| {
225224
unsafe {
226225
let pc = last_ret;
227-
let {segment: next_segment, boundary: boundary} =
226+
let Segment {segment: next_segment, boundary: boundary} =
228227
find_segment_for_frame(frame.fp, segment);
229228
segment = next_segment;
230229
// Each stack segment is bounded by a morestack frame. The

src/libcore/os.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[allow(structural_records)];
12-
1311
/*!
1412
* Higher-level interfaces to libc::* functions and operating system services.
1513
*
@@ -318,26 +316,30 @@ pub fn waitpid(pid: pid_t) -> c_int {
318316
}
319317

320318

319+
pub struct Pipe { mut in: c_int, mut out: c_int }
320+
321321
#[cfg(unix)]
322-
pub fn pipe() -> {in: c_int, out: c_int} {
322+
pub fn pipe() -> Pipe {
323323
unsafe {
324-
let mut fds = {in: 0 as c_int, out: 0 as c_int};
324+
let mut fds = Pipe {mut in: 0 as c_int,
325+
mut out: 0 as c_int };
325326
assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int));
326-
return {in: fds.in, out: fds.out};
327+
return Pipe {in: fds.in, out: fds.out};
327328
}
328329
}
329330

330331

331332

332333
#[cfg(windows)]
333-
pub fn pipe() -> {in: c_int, out: c_int} {
334+
pub fn pipe() -> Pipe {
334335
unsafe {
335336
// Windows pipes work subtly differently than unix pipes, and their
336337
// inheritance has to be handled in a different way that I do not
337338
// fully understand. Here we explicitly make the pipe non-inheritable,
338339
// which means to pass it to a subprocess they need to be duplicated
339340
// first, as in rust_run_program.
340-
let mut fds = { in: 0 as c_int, out: 0 as c_int };
341+
let mut fds = Pipe { mut in: 0 as c_int,
342+
mut out: 0 as c_int };
341343
let res = libc::pipe(ptr::mut_addr_of(&(fds.in)),
342344
1024 as c_uint,
343345
(libc::O_BINARY | libc::O_NOINHERIT) as c_int);

src/libcore/pipes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ bounded and unbounded protocols allows for less code duplication.
8282
8383
*/
8484

85-
// Transitional -- needs snapshot
86-
#[allow(structural_records)];
85+
#[allow(structural_records)]; // Macros -- needs another snapshot
8786

8887
use cmp::Eq;
8988
use cast::{forget, reinterpret_cast, transmute};

src/libcore/ptr.rs

-11
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,7 @@ pub trait Ptr<T> {
187187
pure fn offset(count: uint) -> Self;
188188
}
189189

190-
#[cfg(stage0)]
191-
unsafe fn memmove32(dst: *mut u8, src: *const u8, count: u32) {
192-
libc::memmove(dst as *c_void, src as *c_void, count as size_t);
193-
}
194-
#[cfg(stage0)]
195-
unsafe fn memmove64(dst: *mut u8, src: *const u8, count: u64) {
196-
libc::memmove(dst as *c_void, src as *c_void, count as size_t);
197-
}
198-
199190
#[abi="rust-intrinsic"]
200-
#[cfg(stage1)]
201-
#[cfg(stage2)]
202191
pub extern {
203192
fn memmove32(dst: *mut u8, src: *u8, size: u32);
204193
fn memmove64(dst: *mut u8, src: *u8, size: u64);

src/libcore/run.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[allow(structural_records)];
12-
1311
//! Process spawning
1412
use cast;
1513
use io;
@@ -301,6 +299,8 @@ fn read_all(rd: io::Reader) -> ~str {
301299
str::from_bytes(buf)
302300
}
303301

302+
pub struct ProgramOutput {status: int, out: ~str, err: ~str}
303+
304304
/**
305305
* Spawns a process, waits for it to exit, and returns the exit code, and
306306
* contents of stdout and stderr.
@@ -315,8 +315,7 @@ fn read_all(rd: io::Reader) -> ~str {
315315
* A record, {status: int, out: str, err: str} containing the exit code,
316316
* the contents of stdout and the contents of stderr.
317317
*/
318-
pub fn program_output(prog: &str, args: &[~str]) ->
319-
{status: int, out: ~str, err: ~str} {
318+
pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
320319
unsafe {
321320
let pipe_in = os::pipe();
322321
let pipe_out = os::pipe();
@@ -371,7 +370,9 @@ pub fn program_output(prog: &str, args: &[~str]) ->
371370
};
372371
count -= 1;
373372
};
374-
return {status: status, out: move outs, err: move errs};
373+
return ProgramOutput {status: status,
374+
out: move outs,
375+
err: move errs};
375376
}
376377
}
377378

src/librustdoc/config.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use core::cmp;
1414
use core::os;
1515
use core::result;
1616
use core::run;
17+
use core::run::ProgramOutput;
1718
use core::vec;
1819
use core::result::Result;
1920
use std::getopts;
@@ -104,29 +105,18 @@ pub fn default_config(input_crate: &Path) -> Config {
104105
}
105106
}
106107

107-
struct ProcOut {
108-
status: int,
109-
out: ~str,
110-
err: ~str
111-
}
112-
113-
type ProgramOutput = fn~((&str), (&[~str])) -> ProcOut;
108+
type Process = fn~((&str), (&[~str])) -> ProgramOutput;
114109

115-
pub fn mock_program_output(_prog: &str, _args: &[~str]) -> ProcOut {
116-
ProcOut {
110+
pub fn mock_program_output(_prog: &str, _args: &[~str]) -> ProgramOutput {
111+
ProgramOutput {
117112
status: 0,
118113
out: ~"",
119114
err: ~""
120115
}
121116
}
122117

123-
pub fn program_output(prog: &str, args: &[~str]) -> ProcOut {
124-
let {status, out, err} = run::program_output(prog, args);
125-
ProcOut {
126-
status: status,
127-
out: out,
128-
err: err
129-
}
118+
pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
119+
run::program_output(prog, args)
130120
}
131121

132122
pub fn parse_config(args: &[~str]) -> Result<Config, ~str> {
@@ -135,7 +125,7 @@ pub fn parse_config(args: &[~str]) -> Result<Config, ~str> {
135125

136126
pub fn parse_config_(
137127
args: &[~str],
138-
program_output: ProgramOutput
128+
program_output: Process
139129
) -> Result<Config, ~str> {
140130
let args = args.tail();
141131
let opts = vec::unzip(opts()).first();
@@ -159,7 +149,7 @@ pub fn parse_config_(
159149
fn config_from_opts(
160150
input_crate: &Path,
161151
matches: &getopts::Matches,
162-
program_output: ProgramOutput
152+
program_output: Process
163153
) -> Result<Config, ~str> {
164154

165155
let config = default_config(input_crate);
@@ -235,7 +225,7 @@ fn parse_output_style(output_style: &str) -> Result<OutputStyle, ~str> {
235225
fn maybe_find_pandoc(
236226
config: &Config,
237227
maybe_pandoc_cmd: Option<~str>,
238-
program_output: ProgramOutput
228+
program_output: Process
239229
) -> Result<Option<~str>, ~str> {
240230
if config.output_format != PandocHtml {
241231
return result::Ok(maybe_pandoc_cmd);
@@ -272,8 +262,9 @@ fn should_find_pandoc() {
272262
output_format: PandocHtml,
273263
.. default_config(&Path("test"))
274264
};
275-
let mock_program_output = fn~(_prog: &str, _args: &[~str]) -> ProcOut {
276-
ProcOut {
265+
let mock_program_output = fn~(_prog: &str, _args: &[~str])
266+
-> ProgramOutput {
267+
ProgramOutput {
277268
status: 0, out: ~"pandoc 1.8.2.1", err: ~""
278269
}
279270
};
@@ -287,8 +278,9 @@ fn should_error_with_no_pandoc() {
287278
output_format: PandocHtml,
288279
.. default_config(&Path("test"))
289280
};
290-
let mock_program_output = fn~(_prog: &str, _args: &[~str]) -> ProcOut {
291-
ProcOut {
281+
let mock_program_output = fn~(_prog: &str, _args: &[~str])
282+
-> ProgramOutput {
283+
ProgramOutput {
292284
status: 1, out: ~"", err: ~""
293285
}
294286
};

0 commit comments

Comments
 (0)