Skip to content

Commit 1869461

Browse files
committed
libsyntax: Remove fn@, fn~, and fn& from libsyntax. rs=defun
1 parent 4fde10f commit 1869461

File tree

9 files changed

+181
-194
lines changed

9 files changed

+181
-194
lines changed

src/libsyntax/ast_util.rs

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ pub fn empty(range: id_range) -> bool {
396396
range.min >= range.max
397397
}
398398

399-
pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
400-
let visit_generics = fn@(generics: &Generics) {
399+
pub fn id_visitor(vfn: @fn(node_id)) -> visit::vt<()> {
400+
let visit_generics: @fn(&Generics) = |generics| {
401401
for generics.ty_params.each |p| {
402402
vfn(p.id);
403403
}
@@ -408,7 +408,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
408408
visit::mk_simple_visitor(@visit::SimpleVisitor {
409409
visit_mod: |_m, _sp, id| vfn(id),
410410

411-
visit_view_item: fn@(vi: @view_item) {
411+
visit_view_item: |vi| {
412412
match vi.node {
413413
view_item_extern_mod(_, _, id) => vfn(id),
414414
view_item_use(ref vps) => {
@@ -423,11 +423,9 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
423423
}
424424
},
425425

426-
visit_foreign_item: fn@(ni: @foreign_item) {
427-
vfn(ni.id)
428-
},
426+
visit_foreign_item: |ni| vfn(ni.id),
429427

430-
visit_item: fn@(i: @item) {
428+
visit_item: |i| {
431429
vfn(i.id);
432430
match i.node {
433431
item_enum(ref enum_definition, _) =>
@@ -436,36 +434,21 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
436434
}
437435
},
438436

439-
visit_local: fn@(l: @local) {
440-
vfn(l.node.id);
441-
},
442-
443-
visit_block: fn@(b: &blk) {
444-
vfn(b.node.id);
445-
},
446-
447-
visit_stmt: fn@(s: @stmt) {
448-
vfn(ast_util::stmt_id(*s));
449-
},
450-
451-
visit_arm: fn@(_a: &arm) { },
452-
453-
visit_pat: fn@(p: @pat) {
454-
vfn(p.id)
455-
},
456-
457-
visit_decl: fn@(_d: @decl) {
458-
},
437+
visit_local: |l| vfn(l.node.id),
438+
visit_block: |b| vfn(b.node.id),
439+
visit_stmt: |s| vfn(ast_util::stmt_id(*s)),
440+
visit_arm: |_| {},
441+
visit_pat: |p| vfn(p.id),
442+
visit_decl: |_| {},
459443

460-
visit_expr: fn@(e: @expr) {
444+
visit_expr: |e| {
461445
vfn(e.callee_id);
462446
vfn(e.id);
463447
},
464448

465-
visit_expr_post: fn@(_e: @expr) {
466-
},
449+
visit_expr_post: |_| {},
467450

468-
visit_ty: fn@(t: @Ty) {
451+
visit_ty: |t| {
469452
match t.node {
470453
ty_path(_, id) => vfn(id),
471454
_ => { /* fall through */ }
@@ -474,8 +457,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
474457

475458
visit_generics: visit_generics,
476459

477-
visit_fn: fn@(fk: &visit::fn_kind, d: &ast::fn_decl,
478-
_b: &ast::blk, _sp: span, id: ast::node_id) {
460+
visit_fn: |fk, d, _, _, id| {
479461
vfn(id);
480462

481463
match *fk {
@@ -502,32 +484,19 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
502484
}
503485
},
504486

505-
visit_ty_method: fn@(_ty_m: &ty_method) {
506-
},
507-
508-
visit_trait_method: fn@(_ty_m: &trait_method) {
509-
},
510-
511-
visit_struct_def: fn@(_sd: @struct_def,
512-
_id: ident,
513-
_generics: &Generics,
514-
_id: node_id) {
515-
},
516-
517-
visit_struct_field: fn@(f: @struct_field) {
518-
vfn(f.node.id);
519-
},
520-
521-
visit_struct_method: fn@(_m: @method) {
522-
}
487+
visit_ty_method: |_| {},
488+
visit_trait_method: |_| {},
489+
visit_struct_def: |_, _, _, _| {},
490+
visit_struct_field: |f| vfn(f.node.id),
491+
visit_struct_method: |_| {}
523492
})
524493
}
525494

526-
pub fn visit_ids_for_inlined_item(item: inlined_item, vfn: fn@(node_id)) {
495+
pub fn visit_ids_for_inlined_item(item: inlined_item, vfn: @fn(node_id)) {
527496
item.accept((), id_visitor(vfn));
528497
}
529498

530-
pub fn compute_id_range(visit_ids_fn: fn(fn@(node_id))) -> id_range {
499+
pub fn compute_id_range(visit_ids_fn: &fn(@fn(node_id))) -> id_range {
531500
let min = @mut int::max_value;
532501
let max = @mut int::min_value;
533502
do visit_ids_fn |id| {

src/libsyntax/diagnostic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ use core::dvec::DVec;
2323

2424
use std::term;
2525

26-
pub type Emitter = fn@(cmsp: Option<(@codemap::CodeMap, span)>,
27-
msg: &str, lvl: level);
26+
pub type Emitter = @fn(cmsp: Option<(@codemap::CodeMap, span)>,
27+
msg: &str,
28+
lvl: level);
2829

2930
// a handler deals with errors; certain errors
3031
// (fatal, bug, unimpl) may cause immediate exit,
@@ -204,8 +205,7 @@ fn print_diagnostic(topic: ~str, lvl: level, msg: &str) {
204205
}
205206

206207
pub fn collect(messages: @DVec<~str>)
207-
-> fn@(Option<(@codemap::CodeMap, span)>, &str, level)
208-
{
208+
-> @fn(Option<(@codemap::CodeMap, span)>, &str, level) {
209209
let f: @fn(Option<(@codemap::CodeMap, span)>, &str, level) =
210210
|_o, msg: &str, _l| { messages.push(msg.to_str()); };
211211
f

src/libsyntax/ext/base.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,39 @@ pub struct MacroDef {
3737
ext: SyntaxExtension
3838
}
3939

40-
pub type ItemDecorator =
41-
fn@(ext_ctxt, span, @ast::meta_item, ~[@ast::item]) -> ~[@ast::item];
40+
pub type ItemDecorator = @fn(ext_ctxt,
41+
span,
42+
@ast::meta_item,
43+
~[@ast::item])
44+
-> ~[@ast::item];
4245

4346
pub struct SyntaxExpanderTT {
4447
expander: SyntaxExpanderTTFun,
4548
span: Option<span>
4649
}
4750

48-
pub type SyntaxExpanderTTFun
49-
= fn@(ext_ctxt, span, &[ast::token_tree]) -> MacResult;
51+
pub type SyntaxExpanderTTFun = @fn(ext_ctxt,
52+
span,
53+
&[ast::token_tree])
54+
-> MacResult;
5055

5156
pub struct SyntaxExpanderTTItem {
5257
expander: SyntaxExpanderTTItemFun,
5358
span: Option<span>
5459
}
5560

56-
pub type SyntaxExpanderTTItemFun
57-
= fn@(ext_ctxt, span, ast::ident, ~[ast::token_tree]) -> MacResult;
61+
pub type SyntaxExpanderTTItemFun = @fn(ext_ctxt,
62+
span,
63+
ast::ident,
64+
~[ast::token_tree])
65+
-> MacResult;
5866

5967
pub enum MacResult {
6068
MRExpr(@ast::expr),
6169
MRItem(@ast::item),
62-
MRAny(fn@()-> @ast::expr, fn@()-> Option<@ast::item>, fn@()->@ast::stmt),
70+
MRAny(@fn() -> @ast::expr,
71+
@fn() -> Option<@ast::item>,
72+
@fn() -> @ast::stmt),
6373
MRDef(MacroDef)
6474
}
6575

src/libsyntax/ext/expand.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ use core::option;
2626
use core::vec;
2727
use core::hashmap::LinearMap;
2828

29-
pub fn expand_expr(extsbox: @mut SyntaxEnv, cx: ext_ctxt,
30-
e: &expr_, s: span, fld: ast_fold,
31-
orig: fn@(&expr_, span, ast_fold) -> (expr_, span))
29+
pub fn expand_expr(extsbox: @mut SyntaxEnv,
30+
cx: ext_ctxt,
31+
e: &expr_,
32+
s: span,
33+
fld: ast_fold,
34+
orig: @fn(&expr_, span, ast_fold) -> (expr_, span))
3235
-> (expr_, span) {
3336
match *e {
3437
// expr_mac should really be expr_ext or something; it's the
@@ -105,9 +108,11 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, cx: ext_ctxt,
105108
//
106109
// NB: there is some redundancy between this and expand_item, below, and
107110
// they might benefit from some amount of semantic and language-UI merger.
108-
pub fn expand_mod_items(extsbox: @mut SyntaxEnv, cx: ext_ctxt,
109-
module_: &ast::_mod, fld: ast_fold,
110-
orig: fn@(&ast::_mod, ast_fold) -> ast::_mod)
111+
pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
112+
cx: ext_ctxt,
113+
module_: &ast::_mod,
114+
fld: ast_fold,
115+
orig: @fn(&ast::_mod, ast_fold) -> ast::_mod)
111116
-> ast::_mod {
112117
// Fold the contents first:
113118
let module_ = orig(module_, fld);
@@ -155,8 +160,10 @@ macro_rules! with_exts_frame (
155160

156161
// When we enter a module, record it, for the sake of `module!`
157162
pub fn expand_item(extsbox: @mut SyntaxEnv,
158-
cx: ext_ctxt, it: @ast::item, fld: ast_fold,
159-
orig: fn@(@ast::item, ast_fold) -> Option<@ast::item>)
163+
cx: ext_ctxt,
164+
it: @ast::item,
165+
fld: ast_fold,
166+
orig: @fn(@ast::item, ast_fold) -> Option<@ast::item>)
160167
-> Option<@ast::item> {
161168
// need to do expansion first... it might turn out to be a module.
162169
let maybe_it = match it.node {
@@ -296,11 +303,13 @@ pub fn expand_item_mac(+extsbox: @mut SyntaxEnv,
296303
}
297304
298305
// expand a stmt
299-
pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx: ext_ctxt,
300-
s: &stmt_, sp: span, fld: ast_fold,
301-
orig: fn@(s: &stmt_, span, ast_fold) -> (stmt_, span))
306+
pub fn expand_stmt(extsbox: @mut SyntaxEnv,
307+
cx: ext_ctxt,
308+
s: &stmt_,
309+
sp: span,
310+
fld: ast_fold,
311+
orig: @fn(&stmt_, span, ast_fold) -> (stmt_, span))
302312
-> (stmt_, span) {
303-
304313
let (mac, pth, tts, semi) = match *s {
305314
stmt_mac(ref mac, semi) => {
306315
match mac.node {
@@ -356,10 +365,13 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx: ext_ctxt,
356365

357366

358367

359-
pub fn expand_block(extsbox: @mut SyntaxEnv, cx: ext_ctxt,
360-
blk: &blk_, sp: span, fld: ast_fold,
361-
orig: fn@(&blk_, span, ast_fold) -> (blk_, span))
362-
-> (blk_, span) {
368+
pub fn expand_block(extsbox: @mut SyntaxEnv,
369+
cx: ext_ctxt,
370+
blk: &blk_,
371+
sp: span,
372+
fld: ast_fold,
373+
orig: @fn(&blk_, span, ast_fold) -> (blk_, span))
374+
-> (blk_, span) {
363375
match (*extsbox).find(&@~" block") {
364376
// no scope limit on macros in this block, no need
365377
// to push an exts frame:

src/libsyntax/ext/fmt.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
4242
fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: &str) -> ! {
4343
cx.span_fatal(sp, msg);
4444
}
45-
let parse_fmt_err = fn@(s: &str) -> ! {
46-
parse_fmt_err_(cx, fmtspan, s)
47-
};
45+
let parse_fmt_err: @fn(&str) -> ! = |s| parse_fmt_err_(cx, fmtspan, s);
4846
let pieces = parse_fmt_string(fmt, parse_fmt_err);
4947
MRExpr(pieces_to_expr(cx, sp, pieces, args))
5048
}

src/libsyntax/fold.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub trait ast_fold {
3939
fn fold_ident(@self, ident) -> ident;
4040
fn fold_path(@self, @path) -> @path;
4141
fn fold_local(@self, @local) -> @local;
42-
fn map_exprs(@self, fn@(@expr) -> @expr, &[@expr]) -> ~[@expr];
42+
fn map_exprs(@self, @fn(@expr) -> @expr, &[@expr]) -> ~[@expr];
4343
fn new_id(@self, node_id) -> node_id;
4444
fn new_span(@self, span) -> span;
4545
}
@@ -48,29 +48,29 @@ pub trait ast_fold {
4848

4949
pub struct AstFoldFns {
5050
//unlike the others, item_ is non-trivial
51-
fold_crate: fn@(&crate_, span, ast_fold) -> (crate_, span),
52-
fold_view_item: fn@(view_item_, ast_fold) -> view_item_,
53-
fold_foreign_item: fn@(@foreign_item, ast_fold) -> @foreign_item,
54-
fold_item: fn@(@item, ast_fold) -> Option<@item>,
55-
fold_struct_field: fn@(@struct_field, ast_fold) -> @struct_field,
56-
fold_item_underscore: fn@(&item_, ast_fold) -> item_,
57-
fold_method: fn@(@method, ast_fold) -> @method,
58-
fold_block: fn@(&blk_, span, ast_fold) -> (blk_, span),
59-
fold_stmt: fn@(&stmt_, span, ast_fold) -> (stmt_, span),
60-
fold_arm: fn@(&arm, ast_fold) -> arm,
61-
fold_pat: fn@(&pat_, span, ast_fold) -> (pat_, span),
62-
fold_decl: fn@(&decl_, span, ast_fold) -> (decl_, span),
63-
fold_expr: fn@(&expr_, span, ast_fold) -> (expr_, span),
64-
fold_ty: fn@(&ty_, span, ast_fold) -> (ty_, span),
65-
fold_mod: fn@(&_mod, ast_fold) -> _mod,
66-
fold_foreign_mod: fn@(&foreign_mod, ast_fold) -> foreign_mod,
67-
fold_variant: fn@(&variant_, span, ast_fold) -> (variant_, span),
68-
fold_ident: fn@(ident, ast_fold) -> ident,
69-
fold_path: fn@(@path, ast_fold) -> path,
70-
fold_local: fn@(&local_, span, ast_fold) -> (local_, span),
71-
map_exprs: fn@(fn@(@expr) -> @expr, &[@expr]) -> ~[@expr],
72-
new_id: fn@(node_id) -> node_id,
73-
new_span: fn@(span) -> span
51+
fold_crate: @fn(&crate_, span, ast_fold) -> (crate_, span),
52+
fold_view_item: @fn(view_item_, ast_fold) -> view_item_,
53+
fold_foreign_item: @fn(@foreign_item, ast_fold) -> @foreign_item,
54+
fold_item: @fn(@item, ast_fold) -> Option<@item>,
55+
fold_struct_field: @fn(@struct_field, ast_fold) -> @struct_field,
56+
fold_item_underscore: @fn(&item_, ast_fold) -> item_,
57+
fold_method: @fn(@method, ast_fold) -> @method,
58+
fold_block: @fn(&blk_, span, ast_fold) -> (blk_, span),
59+
fold_stmt: @fn(&stmt_, span, ast_fold) -> (stmt_, span),
60+
fold_arm: @fn(&arm, ast_fold) -> arm,
61+
fold_pat: @fn(&pat_, span, ast_fold) -> (pat_, span),
62+
fold_decl: @fn(&decl_, span, ast_fold) -> (decl_, span),
63+
fold_expr: @fn(&expr_, span, ast_fold) -> (expr_, span),
64+
fold_ty: @fn(&ty_, span, ast_fold) -> (ty_, span),
65+
fold_mod: @fn(&_mod, ast_fold) -> _mod,
66+
fold_foreign_mod: @fn(&foreign_mod, ast_fold) -> foreign_mod,
67+
fold_variant: @fn(&variant_, span, ast_fold) -> (variant_, span),
68+
fold_ident: @fn(ident, ast_fold) -> ident,
69+
fold_path: @fn(@path, ast_fold) -> path,
70+
fold_local: @fn(&local_, span, ast_fold) -> (local_, span),
71+
map_exprs: @fn(@fn(@expr) -> @expr, &[@expr]) -> ~[@expr],
72+
new_id: @fn(node_id) -> node_id,
73+
new_span: @fn(span) -> span
7474
}
7575

7676
pub type ast_fold_fns = @AstFoldFns;
@@ -446,12 +446,12 @@ fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> decl_ {
446446
}
447447
}
448448

449-
pub fn wrap<T>(f: fn@(&T, ast_fold) -> T)
450-
-> fn@(&T, span, ast_fold) -> (T, span)
451-
{
452-
fn@(x: &T, s: span, fld: @ast_fold) -> (T, span) {
449+
pub fn wrap<T>(f: @fn(&T, ast_fold) -> T)
450+
-> @fn(&T, span, ast_fold) -> (T, span) {
451+
let result: @fn(&T, span, @ast_fold) -> (T, span) = |x, s, fld| {
453452
(f(x, fld), s)
454-
}
453+
};
454+
result
455455
}
456456

457457
pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ {
@@ -759,7 +759,7 @@ fn noop_fold_local(l: &local_, fld: @ast_fold) -> local_ {
759759

760760
/* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
761761
value */
762-
fn noop_map_exprs(f: fn@(@expr) -> @expr, es: &[@expr]) -> ~[@expr] {
762+
fn noop_map_exprs(f: @fn(@expr) -> @expr, es: &[@expr]) -> ~[@expr] {
763763
es.map(|x| f(*x))
764764
}
765765

@@ -893,11 +893,10 @@ impl ast_fold for AstFoldFns {
893893
let (n, s) = (self.fold_local)(&x.node, x.span, self as @ast_fold);
894894
@spanned { node: n, span: (self.new_span)(s) }
895895
}
896-
fn map_exprs(
897-
@self,
898-
f: fn@(@expr) -> @expr,
899-
e: &[@expr]
900-
) -> ~[@expr] {
896+
fn map_exprs(@self,
897+
f: @fn(@expr) -> @expr,
898+
e: &[@expr])
899+
-> ~[@expr] {
901900
(self.map_exprs)(f, e)
902901
}
903902
fn new_id(@self, node_id: ast::node_id) -> node_id {

0 commit comments

Comments
 (0)