Skip to content

Commit 84825ee

Browse files
committed
librustc: Make the default sigil for block lambdas & instead of @.
1 parent bd6536f commit 84825ee

23 files changed

+70
-72
lines changed

src/libcore/task/spawn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
608608
};
609609
if result {
610610
// Unwinding function in case any ancestral enlisting fails
611-
let bail = |tg: TaskGroupInner| {
611+
let bail: @fn(TaskGroupInner) = |tg| {
612612
leave_taskgroup(tg, child, false)
613613
};
614614
// Attempt to join every ancestor group.

src/librustc/metadata/encoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ export encode_def_id;
6666

6767
type abbrev_map = map::HashMap<ty::t, tyencode::ty_abbrev>;
6868

69-
type encode_inlined_item = fn@(ecx: @encode_ctxt,
70-
ebml_w: writer::Encoder,
71-
path: ast_map::path,
72-
ii: ast::inlined_item);
69+
pub type encode_inlined_item = fn@(ecx: @encode_ctxt,
70+
ebml_w: writer::Encoder,
71+
path: ast_map::path,
72+
ii: ast::inlined_item);
7373

7474
type encode_parms = {
7575
diag: span_handler,
@@ -572,7 +572,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
572572
index: @mut ~[entry<int>]) {
573573
index.push({val: item.id, pos: ebml_w.writer.tell()});
574574
}
575-
let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index);
575+
let add_to_index: &fn() = || add_to_index_(item, ebml_w, index);
576576

577577
debug!("encoding info for item at %s",
578578
ecx.tcx.sess.codemap.span_to_str(item.span));

src/librustc/middle/privacy.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ use syntax::ast_map::{node_item, node_method};
3030
use syntax::ast_map;
3131
use syntax::ast_util::{Private, Public, has_legacy_export_attr, is_local};
3232
use syntax::ast_util::{visibility_to_privacy};
33+
use syntax::codemap::span;
3334
use syntax::visit;
3435

3536
fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
3637
let privileged_items = @DVec();
3738
let legacy_exports = has_legacy_export_attr(crate.node.attrs);
3839

3940
// Adds structs that are privileged to this scope.
40-
let add_privileged_items = |items: &[@ast::item]| {
41+
let add_privileged_items: @fn(&[@ast::item]) -> int = |items| {
4142
let mut count = 0;
4243
for items.each |item| {
4344
match item.node {
@@ -53,7 +54,8 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
5354
};
5455

5556
// Checks that an enum variant is in scope
56-
let check_variant = |span, enum_id| {
57+
let check_variant: @fn(span: span, enum_id: ast::def_id) =
58+
|span, enum_id| {
5759
let variant_info = ty::enum_variants(tcx, enum_id)[0];
5860
let parental_privacy = if is_local(enum_id) {
5961
let parent_vis = ast_map::node_item_query(tcx.items, enum_id.node,
@@ -81,7 +83,8 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
8183
};
8284

8385
// Checks that a private field is in scope.
84-
let check_field = |span, id, ident| {
86+
let check_field: @fn(span: span, id: ast::def_id, ident: ast::ident) =
87+
|span, id, ident| {
8588
let fields = ty::lookup_struct_fields(tcx, id);
8689
for fields.each |field| {
8790
if field.ident != ident { loop; }
@@ -95,7 +98,8 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
9598
};
9699

97100
// Checks that a private method is in scope.
98-
let check_method = |span, origin: &method_origin| {
101+
let check_method: @fn(span: span, origin: &method_origin) =
102+
|span, origin| {
99103
match *origin {
100104
method_static(method_id) => {
101105
if method_id.crate == local_crate {

src/librustc/middle/trans/_match.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,8 +1610,9 @@ fn trans_match_inner(scope_cx: block,
16101610
if ty::type_is_empty(tcx, t) {
16111611
// Special case for empty types
16121612
let fail_cx = @mut None;
1613-
Some(|| mk_fail(scope_cx, discr_expr.span,
1614-
~"scrutinizing value that can't exist", fail_cx))
1613+
let f: mk_fail = || mk_fail(scope_cx, discr_expr.span,
1614+
~"scrutinizing value that can't exist", fail_cx);
1615+
Some(f)
16151616
} else {
16161617
None
16171618
}

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,7 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
28672867

28682868
fn crate_ctxt_to_encode_parms(cx: @crate_ctxt) -> encoder::encode_parms {
28692869
// XXX: Bad copy of `c`, whatever it is.
2870-
let encode_inlined_item =
2870+
let encode_inlined_item: encoder::encode_inlined_item =
28712871
|a,b,c,d| astencode::encode_inlined_item(a, b, copy c, d, cx.maps);
28722872

28732873
return {

src/librustc/middle/trans/closure.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,24 +427,23 @@ fn trans_expr_fn(bcx: block,
427427
~"expr_fn");
428428
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
429429

430-
// XXX: Bad copies.
431-
let trans_closure_env = |proto, copy body, copy sub_path, copy decl| {
430+
let trans_closure_env: &fn(ast::Proto) -> Result = |proto| {
432431
let cap_vars = capture::compute_capture_vars(ccx.tcx, user_id, proto,
433432
cap_clause);
434433
let ret_handle = match is_loop_body { Some(x) => x, None => None };
435434
// XXX: Bad copy.
436435
let {llbox, cdata_ty, bcx} = build_closure(bcx, copy cap_vars, proto,
437436
ret_handle);
438-
trans_closure(ccx, /*bad*/copy sub_path, decl, body, llfn, no_self,
439-
/*bad*/copy bcx.fcx.param_substs, user_id, None,
440-
|fcx| {
441-
load_environment(fcx, cdata_ty, copy cap_vars,
442-
ret_handle.is_some(), proto);
437+
trans_closure(ccx, /*bad*/copy sub_path, decl, /*bad*/copy body,
438+
llfn, no_self, /*bad*/copy bcx.fcx.param_substs,
439+
user_id, None, |fcx| {
440+
load_environment(fcx, cdata_ty, copy cap_vars,
441+
ret_handle.is_some(), proto);
443442
}, |bcx| {
444-
if is_loop_body.is_some() {
445-
Store(bcx, C_bool(true), bcx.fcx.llretptr);
446-
}
447-
});
443+
if is_loop_body.is_some() {
444+
Store(bcx, C_bool(true), bcx.fcx.llretptr);
445+
}
446+
});
448447
rslt(bcx, llbox)
449448
};
450449

src/librustc/middle/trans/common.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,14 @@ fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
444444
}
445445
fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
446446
let free_fn = match heap {
447-
heap_shared => |a| glue::trans_free(a, ptr),
448-
heap_exchange => |a| glue::trans_unique_free(a, ptr)
447+
heap_shared => {
448+
let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
449+
f
450+
}
451+
heap_exchange => {
452+
let f: @fn(block) -> block = |a| glue::trans_unique_free(a, ptr);
453+
f
454+
}
449455
};
450456
do in_scope_cx(cx) |scope_info| {
451457
scope_info.cleanups.push(clean_temp(ptr, free_fn,

src/librustc/middle/trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn monomorphic_fn(ccx: @crate_ctxt,
153153
~[path_name((ccx.names)(ccx.sess.str_of(name)))]);
154154
let s = mangle_exported_name(ccx, /*bad*/copy pt, mono_ty);
155155

156-
let mk_lldecl = |/*bad*/copy s| {
156+
let mk_lldecl = || {
157157
let lldecl = decl_internal_cdecl_fn(ccx.llmod, /*bad*/copy s, llfty);
158158
ccx.monomorphized.insert(hash_id, lldecl);
159159
lldecl

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
15611561
fn_ty.meta.onceness)
15621562
}
15631563
_ => {
1564-
(None, ast::impure_fn, ast::ProtoBox, ast::Many)
1564+
(None, ast::impure_fn, ast::ProtoBorrowed, ast::Many)
15651565
}
15661566
}
15671567
};

src/librustc/util/common.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] {
5858
// of b -- skipping any inner loops (loop, while, loop_body)
5959
fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
6060
let rs = @mut false;
61-
let visit_expr =
62-
|e: @ast::expr, &&flag: @mut bool, v: visit::vt<@mut bool>| {
61+
let visit_expr: @fn(@ast::expr,
62+
&&flag: @mut bool,
63+
v: visit::vt<@mut bool>) = |e, &&flag, v| {
6364
*flag |= p(e.node);
6465
match e.node {
6566
// Skip inner loops, since a break in the inner loop isn't a
@@ -80,8 +81,9 @@ fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
8081
// of b -- skipping any inner loops (loop, while, loop_body)
8182
fn block_query(b: ast::blk, p: fn@(@ast::expr) -> bool) -> bool {
8283
let rs = @mut false;
83-
let visit_expr =
84-
|e: @ast::expr, &&flag: @mut bool, v: visit::vt<@mut bool>| {
84+
let visit_expr: @fn(@ast::expr,
85+
&&flag: @mut bool,
86+
v: visit::vt<@mut bool>) = |e, &&flag, v| {
8587
*flag |= p(e);
8688
visit::visit_expr(e, flag, v)
8789
};

src/libsyntax/diagnostic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ fn print_diagnostic(topic: ~str, lvl: level, msg: &str) {
213213
fn collect(messages: @DVec<~str>)
214214
-> fn@(Option<(@codemap::CodeMap, span)>, &str, level)
215215
{
216-
|_o, msg: &str, _l| { messages.push(msg.to_str()); }
216+
let f: @fn(Option<(@codemap::CodeMap, span)>, &str, level) =
217+
|_o, msg: &str, _l| { messages.push(msg.to_str()); };
218+
f
217219
}
218220

219221
fn emit(cmsp: Option<(@codemap::CodeMap, span)>, msg: &str, lvl: level) {

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
136136
cx.span_fatal(best_fail_spot, best_fail_msg);
137137
}
138138

139-
let exp = |cx, sp, arg| generic_extension(cx, sp, name,
140-
arg, lhses, rhses);
139+
let exp: @fn(ext_ctxt, span, ~[ast::token_tree]) -> mac_result =
140+
|cx, sp, arg| generic_extension(cx, sp, name, arg, lhses, rhses);
141141

142142
return mr_def({
143143
name: *cx.parse_sess().interner.get(name),

src/libsyntax/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
641641
f(fk, decl, body, sp, id);
642642
visit_fn(fk, decl, body, sp, id, e, v);
643643
}
644-
let visit_ty = |a,b,c| v_ty(v.visit_ty, a, b, c);
644+
let visit_ty: @fn(@Ty, &&x: (), vt<()>) =
645+
|a,b,c| v_ty(v.visit_ty, a, b, c);
645646
fn v_struct_field(f: fn@(@struct_field), sf: @struct_field, &&e: (),
646647
v: vt<()>) {
647648
f(sf);

src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn to_lambda1(f: fn@(uint) -> uint) -> fn@(uint) -> uint {
1313
}
1414

1515
fn to_lambda2(b: fn(uint) -> uint) -> fn@(uint) -> uint {
16-
return to_lambda1({|x| b(x)}); //~ ERROR illegal move from argument `b`
16+
return to_lambda1(|x| b(x)); //~ ERROR illegal move from argument `b`
1717
}
1818

1919
fn main() {

src/test/compile-fail/issue-1896.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/test/compile-fail/issue-2149.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ impl<A> ~[A]: vec_monad<A> {
2121
}
2222
}
2323
fn main() {
24-
["hi"].bind({|x| [x] }); //~ ERROR type `[&static/str]/1` does not implement any method in scope named `bind`
24+
["hi"].bind(|x| [x] );
25+
//~^ ERROR type `[&static/str]/1` does not implement any method in scope named `bind`
26+
//~^^ ERROR Unconstrained region variable
2527
}

src/test/run-fail/unwind-closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ fn f(a: @int) {
1616

1717
fn main() {
1818
let b = @0;
19-
let g = {|move b|f(b)};
19+
let g : fn@() = |move b|f(b);
2020
g();
2121
}

src/test/run-pass/cycle-collection2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
type foo = { mut z : fn@() };
11+
struct foo { mut z : fn@() }
1212

1313
fn nop() { }
1414
fn nop_foo(_x : @foo) { }
1515

1616
fn main() {
17-
let w = @{ mut z: {||nop()} };
18-
let x = {||nop_foo(w)};
17+
let w = @foo{ mut z: || nop() };
18+
let x : fn@() = || nop_foo(w);
1919
w.z = x;
2020
}

src/test/run-pass/cycle-collection4.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
type foo = { mut z : fn@() };
11+
struct foo { mut z : fn@() }
1212

1313
fn nop() { }
1414
fn nop_foo(_y: ~[int], _x : @foo) { }
1515

1616
fn main() {
17-
let w = @{ mut z: {||nop()} };
18-
let x = {||nop_foo(~[], w)};
17+
let w = @foo{ z: || nop() };
18+
let x : fn@() = || nop_foo(~[], w);
1919
w.z = x;
2020
}

src/test/run-pass/cycle-collection5.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
type foo = { mut z : fn@() };
11+
struct foo { mut z : fn@() }
1212

1313
fn nop() { }
1414
fn nop_foo(_y: @int, _x : @foo) { }
1515

1616
fn o() -> @int { @10 }
1717

1818
fn main() {
19-
let w = @{ mut z: {||nop()} };
20-
let x = {||nop_foo(o(), w)};
19+
let w = @foo { mut z: || nop() };
20+
let x : fn@() = || nop_foo(o(), w);
2121
w.z = x;
2222
}

src/test/run-pass/fixed-point-bind-box.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#[legacy_modes];
1313

1414
fn fix_help<A, B>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
15-
return f({|a|fix_help(f, a)}, x);
15+
return f( |a| fix_help(f, a), x);
1616
}
1717

1818
fn fix<A, B>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
19-
return {|a|fix_help(f, a)};
19+
return |a| fix_help(f, a);
2020
}
2121

2222
fn fact_(f: fn@(&&v: int) -> int, &&n: int) -> int {

src/test/run-pass/fixed-point-bind-unique.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#[legacy_modes];
1313

1414
fn fix_help<A: &static, B: Owned>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
15-
return f({|a|fix_help(f, a)}, x);
15+
return f(|a| fix_help(f, a), x);
1616
}
1717

1818
fn fix<A: &static, B: Owned>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
19-
return {|a|fix_help(f, a)};
19+
return |a| fix_help(f, a);
2020
}
2121

2222
fn fact_(f: fn@(&&v: int) -> int, &&n: int) -> int {

src/test/run-pass/last-use-corner-cases.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
// Ensure function arguments and box arguments interact sanely.
2727
fn call_me(x: fn() -> int, y: ~int) { assert x() == *y; }
2828
let q = ~30;
29-
call_me({|copy q| *q}, q);
29+
call_me(|| *q, q);
3030

3131
// Check that no false positives are found in loops.
3232
let mut q = ~40, p = 10;

0 commit comments

Comments
 (0)