Skip to content

Commit 749ee53

Browse files
committed
librustc: Make || lambdas not infer to procs
1 parent 38efa17 commit 749ee53

Some content is hidden

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

64 files changed

+139
-126
lines changed

doc/tutorial-tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn print_message() { println("I am running in a different task!"); }
7676
spawn(print_message);
7777
7878
// Print something more profound in a different task using a lambda expression
79-
spawn( || println("I am also running in a different task!") );
79+
spawn(proc() println("I am also running in a different task!") );
8080
8181
// The canonical way to spawn is using `do` notation
8282
do spawn {
@@ -278,7 +278,7 @@ fn fib(n: u64) -> u64 {
278278
12586269025
279279
}
280280
281-
let mut delayed_fib = extra::future::Future::spawn (|| fib(50) );
281+
let mut delayed_fib = extra::future::Future::spawn(proc() fib(50));
282282
make_a_sandwich();
283283
println!("fib(50) = {:?}", delayed_fib.get())
284284
~~~

src/compiletest/compiletest.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,15 @@ pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
333333
let config = Cell::new((*config).clone());
334334
// FIXME (#9639): This needs to handle non-utf8 paths
335335
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
336-
test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) })
336+
test::DynTestFn(proc() { runtest::run(config.take(), testfile.take()) })
337337
}
338338

339339
pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
340340
use std::cell::Cell;
341341
let config = Cell::new((*config).clone());
342342
// FIXME (#9639): This needs to handle non-utf8 paths
343343
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
344-
test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) })
344+
test::DynMetricFn(proc(mm) {
345+
runtest::run_metrics(config.take(), testfile.take(), mm)
346+
})
345347
}

src/libextra/future.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ mod test {
161161
162162
#[test]
163163
fn test_from_fn() {
164-
let mut f = Future::from_fn(|| ~"brail");
164+
let mut f = Future::from_fn(proc() ~"brail");
165165
assert_eq!(f.get(), ~"brail");
166166
}
167167
@@ -185,14 +185,14 @@ mod test {
185185
186186
#[test]
187187
fn test_spawn() {
188-
let mut f = Future::spawn(|| ~"bale");
188+
let mut f = Future::spawn(proc() ~"bale");
189189
assert_eq!(f.get(), ~"bale");
190190
}
191191
192192
#[test]
193193
#[should_fail]
194194
fn test_futurefail() {
195-
let mut f = Future::spawn(|| fail!());
195+
let mut f = Future::spawn(proc() fail!());
196196
let _x: ~str = f.get();
197197
}
198198

src/libextra/task_pool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<T> TaskPool<T> {
5757
let (port, chan) = comm::stream::<Msg<T>>();
5858
let init_fn = init_fn_factory();
5959

60-
let task_body: proc() = || {
60+
let task_body: proc() = proc() {
6161
let local_data = init_fn(i);
6262
loop {
6363
match port.recv() {
@@ -98,11 +98,11 @@ impl<T> TaskPool<T> {
9898
#[test]
9999
fn test_task_pool() {
100100
let f: || -> proc(uint) -> uint = || {
101-
let g: proc(uint) -> uint = |i| i;
101+
let g: proc(uint) -> uint = proc(i) i;
102102
g
103103
};
104104
let mut pool = TaskPool::new(4, Some(SingleThreaded), f);
105105
8.times(|| {
106-
pool.execute(|i| println!("Hello from thread {}!", *i));
106+
pool.execute(proc(i) println!("Hello from thread {}!", *i));
107107
})
108108
}

src/libextra/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ pub fn run_test(force_ignore: bool,
912912
return;
913913
}
914914
DynTestFn(f) => run_test_inner(desc, monitor_ch, f),
915-
StaticTestFn(f) => run_test_inner(desc, monitor_ch, || f())
915+
StaticTestFn(f) => run_test_inner(desc, monitor_ch, proc() f())
916916
}
917917
}
918918

@@ -1209,7 +1209,7 @@ mod tests {
12091209
ignore: true,
12101210
should_fail: false
12111211
},
1212-
testfn: DynTestFn(|| f()),
1212+
testfn: DynTestFn(proc() f()),
12131213
};
12141214
let (p, ch) = stream();
12151215
let ch = SharedChan::new(ch);
@@ -1227,7 +1227,7 @@ mod tests {
12271227
ignore: true,
12281228
should_fail: false
12291229
},
1230-
testfn: DynTestFn(|| f()),
1230+
testfn: DynTestFn(proc() f()),
12311231
};
12321232
let (p, ch) = stream();
12331233
let ch = SharedChan::new(ch);
@@ -1245,7 +1245,7 @@ mod tests {
12451245
ignore: false,
12461246
should_fail: true
12471247
},
1248-
testfn: DynTestFn(|| f()),
1248+
testfn: DynTestFn(proc() f()),
12491249
};
12501250
let (p, ch) = stream();
12511251
let ch = SharedChan::new(ch);
@@ -1263,7 +1263,7 @@ mod tests {
12631263
ignore: false,
12641264
should_fail: true
12651265
},
1266-
testfn: DynTestFn(|| f()),
1266+
testfn: DynTestFn(proc() f()),
12671267
};
12681268
let (p, ch) = stream();
12691269
let ch = SharedChan::new(ch);
@@ -1318,15 +1318,15 @@ mod tests {
13181318
ignore: true,
13191319
should_fail: false,
13201320
},
1321-
testfn: DynTestFn(|| {}),
1321+
testfn: DynTestFn(proc() {}),
13221322
},
13231323
TestDescAndFn {
13241324
desc: TestDesc {
13251325
name: StaticTestName("2"),
13261326
ignore: false,
13271327
should_fail: false
13281328
},
1329-
testfn: DynTestFn(|| {}),
1329+
testfn: DynTestFn(proc() {}),
13301330
},
13311331
];
13321332
let filtered = filter_tests(&opts, tests);

src/librustc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
345345
task_builder.opts.stack_size = Some(STACK_SIZE);
346346
}
347347

348-
match task_builder.try(|| {
348+
match task_builder.try(proc() {
349349
let ch = ch_capture.clone();
350350
// The 'diagnostics emitter'. Every error, warning, etc. should
351351
// go through this function.
@@ -403,6 +403,6 @@ pub fn main() {
403403

404404
pub fn main_args(args: &[~str]) -> int {
405405
let owned_args = args.to_owned();
406-
monitor(|demitter| run_compiler(owned_args, demitter));
406+
monitor(proc(demitter) run_compiler(owned_args, demitter));
407407
0
408408
}

src/librustc/middle/typeck/check/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,8 +2905,13 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
29052905
_match::check_match(fcx, expr, discrim, *arms);
29062906
}
29072907
ast::ExprFnBlock(ref decl, ref body) => {
2908-
check_expr_fn(fcx, expr, None,
2909-
decl, body, Vanilla, expected);
2908+
check_expr_fn(fcx,
2909+
expr,
2910+
Some(ast::BorrowedSigil),
2911+
decl,
2912+
body,
2913+
Vanilla,
2914+
expected);
29102915
}
29112916
ast::ExprProc(ref decl, ref body) => {
29122917
check_expr_fn(fcx,

src/librustpkg/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl CtxMethods for BuildContext {
474474
let psp = package_script_path.clone();
475475
let ws = workspace.clone();
476476
let pid = pkgid.clone();
477-
prep.exec(|exec| {
477+
prep.exec(proc(exec) {
478478
let mut pscript = PkgScript::parse(subsysroot.clone(),
479479
psp.clone(),
480480
&ws,
@@ -636,7 +636,7 @@ impl CtxMethods for BuildContext {
636636
let sub_target_ex = target_exec.clone();
637637
let sub_target_lib = target_lib.clone();
638638
let sub_build_inputs = build_inputs.to_owned();
639-
prep.exec(|exe_thing| {
639+
prep.exec(proc(exe_thing) {
640640
let mut outputs = ~[];
641641
// Declare all the *inputs* to the declared input too, as inputs
642642
for executable in subex.iter() {

src/librustpkg/package_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl PkgSrc {
412412
let sub_deps = deps.clone();
413413
let inputs = inputs_to_discover.map(|&(ref k, ref p)|
414414
(k.clone(), p.as_str().unwrap().to_owned()));
415-
prep.exec(|exec| {
415+
prep.exec(proc(exec) {
416416
for &(ref kind, ref p) in inputs.iter() {
417417
let pth = Path::new(p.clone());
418418
exec.discover_input(*kind, *p, if *kind == ~"file" {

src/librustuv/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ mod test {
10921092
let handle2 = Cell::new(sched2.make_handle());
10931093
let tasksFriendHandle = Cell::new(sched2.make_handle());
10941094
1095-
let on_exit: proc(UnwindResult) = |exit_status| {
1095+
let on_exit: proc(UnwindResult) = proc(exit_status) {
10961096
handle1.take().send(Shutdown);
10971097
handle2.take().send(Shutdown);
10981098
assert!(exit_status.is_success());
@@ -1106,7 +1106,7 @@ mod test {
11061106
})
11071107
}
11081108
1109-
let test_function: proc() = || {
1109+
let test_function: proc() = proc() {
11101110
let io = unsafe { local_io() };
11111111
let addr = next_test_ip4();
11121112
let maybe_socket = io.udp_bind(addr);

src/libstd/io/net/unix.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,29 @@ mod tests {
214214

215215
#[test]
216216
fn smoke() {
217-
smalltest(|mut server| {
217+
smalltest(proc(mut server) {
218218
let mut buf = [0];
219219
server.read(buf);
220220
assert!(buf[0] == 99);
221-
}, |mut client| {
221+
}, proc(mut client) {
222222
client.write([99]);
223223
})
224224
}
225225

226226
#[test]
227227
fn read_eof() {
228-
smalltest(|mut server| {
228+
smalltest(proc(mut server) {
229229
let mut buf = [0];
230230
assert!(server.read(buf).is_none());
231231
assert!(server.read(buf).is_none());
232-
}, |_client| {
232+
}, proc(_client) {
233233
// drop the client
234234
})
235235
}
236236

237237
#[test]
238238
fn write_begone() {
239-
smalltest(|mut server| {
239+
smalltest(proc(mut server) {
240240
let buf = [0];
241241
let mut stop = false;
242242
while !stop{
@@ -248,7 +248,7 @@ mod tests {
248248
server.write(buf);
249249
})
250250
}
251-
}, |_client| {
251+
}, proc(_client) {
252252
// drop the client
253253
})
254254
}

src/libstd/rt/local.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mod test {
134134
do run_in_bare_thread {
135135
local_ptr::init_tls_key();
136136
let mut sched = ~new_test_uv_sched();
137-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
137+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
138138
Local::put(task);
139139
let task: ~Task = Local::take();
140140
cleanup_task(task);
@@ -146,11 +146,11 @@ mod test {
146146
do run_in_bare_thread {
147147
local_ptr::init_tls_key();
148148
let mut sched = ~new_test_uv_sched();
149-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
149+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
150150
Local::put(task);
151151
let task: ~Task = Local::take();
152152
cleanup_task(task);
153-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
153+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
154154
Local::put(task);
155155
let task: ~Task = Local::take();
156156
cleanup_task(task);
@@ -163,7 +163,7 @@ mod test {
163163
do run_in_bare_thread {
164164
local_ptr::init_tls_key();
165165
let mut sched = ~new_test_uv_sched();
166-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
166+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
167167
Local::put(task);
168168

169169
unsafe {
@@ -179,7 +179,7 @@ mod test {
179179
do run_in_bare_thread {
180180
local_ptr::init_tls_key();
181181
let mut sched = ~new_test_uv_sched();
182-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
182+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
183183
Local::put(task);
184184

185185
let res = Local::borrow(|_task: &mut Task| {

src/libstd/rt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ fn run_(main: proc(), use_main_sched: bool) -> int {
340340

341341
// When the main task exits, after all the tasks in the main
342342
// task tree, shut down the schedulers and set the exit code.
343-
let handles = Cell::new(handles);
344-
let on_exit: proc(UnwindResult) = |exit_success| {
343+
let handles = handles;
344+
let on_exit: proc(UnwindResult) = proc(exit_success) {
345345
unsafe {
346346
assert!(!(*exited_already.get()).swap(true, SeqCst),
347347
"the runtime already exited");
348348
}
349349

350-
let mut handles = handles.take();
350+
let mut handles = handles;
351351
for handle in handles.mut_iter() {
352352
handle.send(Shutdown);
353353
}

src/libstd/rt/sched.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ mod test {
979979
assert!(Task::on_appropriate_sched());
980980
};
981981

982-
let on_exit: proc(UnwindResult) = |exit_status| {
982+
let on_exit: proc(UnwindResult) = proc(exit_status) {
983983
rtassert!(exit_status.is_success())
984984
};
985985
task.death.on_exit = Some(on_exit);
@@ -1193,12 +1193,15 @@ mod test {
11931193

11941194
let thread = do Thread::start {
11951195
let mut sched = sched.take();
1196-
let bootstrap_task = ~Task::new_root(&mut sched.stack_pool, None, ||());
1196+
let bootstrap_task =
1197+
~Task::new_root(&mut sched.stack_pool,
1198+
None,
1199+
proc()());
11971200
sched.bootstrap(bootstrap_task);
11981201
};
11991202

12001203
let mut stack_pool = StackPool::new();
1201-
let task = ~Task::new_root(&mut stack_pool, None, ||());
1204+
let task = ~Task::new_root(&mut stack_pool, None, proc()());
12021205
handle.send(TaskFromFriend(task));
12031206

12041207
handle.send(Shutdown);

src/libstd/rt/task.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl Coroutine {
425425

426426
fn build_start_wrapper(start: proc()) -> proc() {
427427
let start_cell = Cell::new(start);
428-
let wrapper: proc() = || {
428+
let wrapper: proc() = proc() {
429429
// First code after swap to this new context. Run our
430430
// cleanup job.
431431
unsafe {
@@ -712,10 +712,10 @@ mod test {
712712
#[test]
713713
fn unwind() {
714714
do run_in_newsched_task() {
715-
let result = spawntask_try(||());
715+
let result = spawntask_try(proc()());
716716
rtdebug!("trying first assert");
717717
assert!(result.is_ok());
718-
let result = spawntask_try(|| fail!());
718+
let result = spawntask_try(proc() fail!());
719719
rtdebug!("trying second assert");
720720
assert!(result.is_err());
721721
}

0 commit comments

Comments
 (0)