Skip to content

Commit 492677e

Browse files
committed
libsyntax: Change all uses of &fn to ||.
1 parent 18a30af commit 492677e

16 files changed

+139
-111
lines changed

src/libsyntax/abi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static AbiDatas: &'static [AbiData] = &[
8484
AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch},
8585
];
8686

87-
fn each_abi(op: &fn(abi: Abi) -> bool) -> bool {
87+
fn each_abi(op: |abi: Abi| -> bool) -> bool {
8888
/*!
8989
*
9090
* Iterates through each of the defined ABIs.
@@ -201,7 +201,7 @@ impl AbiSet {
201201
self.bits |= (1 << abi.index());
202202
}
203203

204-
pub fn each(&self, op: &fn(abi: Abi) -> bool) -> bool {
204+
pub fn each(&self, op: |abi: Abi| -> bool) -> bool {
205205
each_abi(|abi| !self.contains(abi) || op(abi))
206206
}
207207

src/libsyntax/ast_map.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub enum ast_node {
122122
}
123123

124124
impl ast_node {
125-
pub fn with_attrs<T>(&self, f: &fn(Option<&[Attribute]>) -> T) -> T {
125+
pub fn with_attrs<T>(&self, f: |Option<&[Attribute]>| -> T) -> T {
126126
let attrs = match *self {
127127
node_item(i, _) => Some(i.attrs.as_slice()),
128128
node_foreign_item(fi, _, _, _) => Some(fi.attrs.as_slice()),
@@ -480,9 +480,8 @@ pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str {
480480
}
481481
}
482482

483-
pub fn node_item_query<Result>(items: map, id: NodeId,
484-
query: &fn(@item) -> Result,
485-
error_msg: ~str) -> Result {
483+
pub fn node_item_query<Result>(items: map, id: NodeId, query: |@item| -> Result, error_msg: ~str)
484+
-> Result {
486485
match items.find(&id) {
487486
Some(&node_item(it, _)) => query(it),
488487
_ => fail!("{}", error_msg)

src/libsyntax/ast_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ pub fn is_item_impl(item: @ast::item) -> bool {
636636
}
637637
}
638638

639-
pub fn walk_pat(pat: @Pat, it: &fn(@Pat) -> bool) -> bool {
639+
pub fn walk_pat(pat: @Pat, it: |@Pat| -> bool) -> bool {
640640
if !it(pat) {
641641
return false;
642642
}
@@ -665,7 +665,7 @@ pub fn walk_pat(pat: @Pat, it: &fn(@Pat) -> bool) -> bool {
665665
}
666666

667667
pub trait EachViewItem {
668-
fn each_view_item(&self, f: &fn(&ast::view_item) -> bool) -> bool;
668+
fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool;
669669
}
670670

671671
struct EachViewItemData<'self> {
@@ -679,7 +679,7 @@ impl<'self> Visitor<()> for EachViewItemData<'self> {
679679
}
680680

681681
impl EachViewItem for ast::Crate {
682-
fn each_view_item(&self, f: &fn(&ast::view_item) -> bool) -> bool {
682+
fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool {
683683
let mut visit = EachViewItemData {
684684
callback: f,
685685
};

src/libsyntax/diagnostic.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,11 @@ fn print_macro_backtrace(cm: @codemap::CodeMap, sp: Span) {
347347
}
348348
}
349349

350-
pub fn expect<T:Clone>(diag: @mut span_handler,
351-
opt: Option<T>,
352-
msg: &fn() -> ~str) -> T {
350+
pub fn expect<T:Clone>(
351+
diag: @mut span_handler,
352+
opt: Option<T>,
353+
msg: || -> ~str)
354+
-> T {
353355
match opt {
354356
Some(ref t) => (*t).clone(),
355357
None => diag.handler().bug(msg()),

src/libsyntax/ext/base.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,11 @@ impl <K: Eq + Hash + IterBytes + 'static, V: 'static> MapChain<K,V>{
559559
// should each_key and each_value operate on shadowed
560560
// names? I think not.
561561
// delaying implementing this....
562-
pub fn each_key (&self, _f: &fn (&K)->bool) {
562+
pub fn each_key (&self, _f: |&K| -> bool) {
563563
fail!("unimplemented 2013-02-15T10:01");
564564
}
565565

566-
pub fn each_value (&self, _f: &fn (&V) -> bool) {
566+
pub fn each_value (&self, _f: |&V| -> bool) {
567567
fail!("unimplemented 2013-02-15T10:02");
568568
}
569569

@@ -601,7 +601,11 @@ impl <K: Eq + Hash + IterBytes + 'static, V: 'static> MapChain<K,V>{
601601
// ... there are definitely some opportunities for abstraction
602602
// here that I'm ignoring. (e.g., manufacturing a predicate on
603603
// the maps in the chain, and using an abstract "find".
604-
pub fn insert_into_frame(&mut self, key: K, ext: @V, n: K, pred: &fn(&@V)->bool) {
604+
pub fn insert_into_frame(&mut self,
605+
key: K,
606+
ext: @V,
607+
n: K,
608+
pred: |&@V| -> bool) {
605609
match *self {
606610
BaseMapChain (~ref mut map) => {
607611
if satisfies_pred(map,&n,pred) {
@@ -622,10 +626,12 @@ impl <K: Eq + Hash + IterBytes + 'static, V: 'static> MapChain<K,V>{
622626
}
623627

624628
// returns true if the binding for 'n' satisfies 'pred' in 'map'
625-
fn satisfies_pred<K : Eq + Hash + IterBytes,V>(map : &mut HashMap<K,V>,
626-
n: &K,
627-
pred: &fn(&V)->bool)
628-
-> bool {
629+
fn satisfies_pred<K:Eq + Hash + IterBytes,
630+
V>(
631+
map: &mut HashMap<K,V>,
632+
n: &K,
633+
pred: |&V| -> bool)
634+
-> bool {
629635
match map.find(n) {
630636
Some(ref v) => (pred(*v)),
631637
None => false
@@ -637,7 +643,8 @@ mod test {
637643
use super::MapChain;
638644
use std::hashmap::HashMap;
639645

640-
#[test] fn testenv () {
646+
#[test]
647+
fn testenv() {
641648
let mut a = HashMap::new();
642649
a.insert (@"abc",@15);
643650
let m = MapChain::new(~a);

src/libsyntax/ext/deriving/decodable.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span,
124124
/// Create a decoder for a single enum variant/struct:
125125
/// - `outer_pat_ident` is the name of this enum variant/struct
126126
/// - `getarg` should retrieve the `uint`-th field with name `@str`.
127-
fn decode_static_fields(cx: @ExtCtxt, outer_span: Span, outer_pat_ident: Ident,
127+
fn decode_static_fields(cx: @ExtCtxt,
128+
outer_span: Span,
129+
outer_pat_ident: Ident,
128130
fields: &StaticFields,
129-
getarg: &fn(Span, @str, uint) -> @Expr) -> @Expr {
131+
getarg: |Span, @str, uint| -> @Expr)
132+
-> @Expr {
130133
match *fields {
131134
Unnamed(ref fields) => {
132135
if fields.is_empty() {

src/libsyntax/ext/deriving/generic.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1064,14 +1064,13 @@ Fold the fields. `use_foldl` controls whether this is done
10641064
left-to-right (`true`) or right-to-left (`false`).
10651065
*/
10661066
pub fn cs_fold(use_foldl: bool,
1067-
f: &fn(@ExtCtxt, Span,
1068-
old: @Expr,
1069-
self_f: @Expr,
1070-
other_fs: &[@Expr]) -> @Expr,
1067+
f: |@ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr,
10711068
base: @Expr,
10721069
enum_nonmatch_f: EnumNonMatchFunc,
1073-
cx: @ExtCtxt, trait_span: Span,
1074-
substructure: &Substructure) -> @Expr {
1070+
cx: @ExtCtxt,
1071+
trait_span: Span,
1072+
substructure: &Substructure)
1073+
-> @Expr {
10751074
match *substructure.fields {
10761075
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
10771076
if use_foldl {
@@ -1104,10 +1103,12 @@ f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1),
11041103
~~~
11051104
*/
11061105
#[inline]
1107-
pub fn cs_same_method(f: &fn(@ExtCtxt, Span, ~[@Expr]) -> @Expr,
1106+
pub fn cs_same_method(f: |@ExtCtxt, Span, ~[@Expr]| -> @Expr,
11081107
enum_nonmatch_f: EnumNonMatchFunc,
1109-
cx: @ExtCtxt, trait_span: Span,
1110-
substructure: &Substructure) -> @Expr {
1108+
cx: @ExtCtxt,
1109+
trait_span: Span,
1110+
substructure: &Substructure)
1111+
-> @Expr {
11111112
match *substructure.fields {
11121113
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
11131114
// call self_n.method(other_1_n, other_2_n, ...)
@@ -1136,11 +1137,13 @@ fields. `use_foldl` controls whether this is done left-to-right
11361137
*/
11371138
#[inline]
11381139
pub fn cs_same_method_fold(use_foldl: bool,
1139-
f: &fn(@ExtCtxt, Span, @Expr, @Expr) -> @Expr,
1140+
f: |@ExtCtxt, Span, @Expr, @Expr| -> @Expr,
11401141
base: @Expr,
11411142
enum_nonmatch_f: EnumNonMatchFunc,
1142-
cx: @ExtCtxt, trait_span: Span,
1143-
substructure: &Substructure) -> @Expr {
1143+
cx: @ExtCtxt,
1144+
trait_span: Span,
1145+
substructure: &Substructure)
1146+
-> @Expr {
11441147
cs_same_method(
11451148
|cx, span, vals| {
11461149
if use_foldl {

src/libsyntax/ext/deriving/rand.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
128128
_ => cx.bug("Non-static method in `deriving(Rand)`")
129129
};
130130

131-
fn rand_thing(cx: @ExtCtxt, span: Span,
131+
fn rand_thing(cx: @ExtCtxt,
132+
span: Span,
132133
ctor_ident: Ident,
133134
summary: &StaticFields,
134-
rand_call: &fn(Span) -> @Expr) -> @Expr {
135+
rand_call: |Span| -> @Expr)
136+
-> @Expr {
135137
match *summary {
136138
Unnamed(ref fields) => {
137139
if fields.is_empty() {

src/libsyntax/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub trait ast_fold {
381381
}
382382
}
383383

384-
fn map_exprs(&self, f: &fn(@Expr) -> @Expr, es: &[@Expr]) -> ~[@Expr] {
384+
fn map_exprs(&self, f: |@Expr| -> @Expr, es: &[@Expr]) -> ~[@Expr] {
385385
es.map(|x| f(*x))
386386
}
387387

src/libsyntax/opt_vec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ impl<T> OptVec<T> {
5050
*self = Vec(~[t]);
5151
}
5252

53-
pub fn map<U>(&self, op: &fn(&T) -> U) -> OptVec<U> {
53+
pub fn map<U>(&self, op: |&T| -> U) -> OptVec<U> {
5454
match *self {
5555
Empty => Empty,
5656
Vec(ref v) => Vec(v.map(op))
5757
}
5858
}
5959

60-
pub fn map_move<U>(self, op: &fn(T) -> U) -> OptVec<U> {
60+
pub fn map_move<U>(self, op: |T| -> U) -> OptVec<U> {
6161
match self {
6262
Empty => Empty,
6363
Vec(v) => Vec(v.move_iter().map(op).collect())
@@ -91,11 +91,11 @@ impl<T> OptVec<T> {
9191
}
9292

9393
#[inline]
94-
pub fn map_to_vec<B>(&self, op: &fn(&T) -> B) -> ~[B] {
94+
pub fn map_to_vec<B>(&self, op: |&T| -> B) -> ~[B] {
9595
self.iter().map(op).collect()
9696
}
9797

98-
pub fn mapi_to_vec<B>(&self, op: &fn(uint, &T) -> B) -> ~[B] {
98+
pub fn mapi_to_vec<B>(&self, op: |uint, &T| -> B) -> ~[B] {
9999
let mut index = 0;
100100
self.map_to_vec(|a| {
101101
let i = index;

src/libsyntax/parse/lexer.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,22 @@ fn byte_offset(rdr: &StringReader, pos: BytePos) -> BytePos {
216216
/// Calls `f` with a string slice of the source text spanning from `start`
217217
/// up to but excluding `rdr.last_pos`, meaning the slice does not include
218218
/// the character `rdr.curr`.
219-
pub fn with_str_from<T>(rdr: @mut StringReader, start: BytePos, f: &fn(s: &str) -> T) -> T {
219+
pub fn with_str_from<T>(
220+
rdr: @mut StringReader,
221+
start: BytePos,
222+
f: |s: &str| -> T)
223+
-> T {
220224
with_str_from_to(rdr, start, rdr.last_pos, f)
221225
}
222226

223227
/// Calls `f` with astring slice of the source text spanning from `start`
224228
/// up to but excluding `end`.
225-
fn with_str_from_to<T>(rdr: @mut StringReader,
226-
start: BytePos,
227-
end: BytePos,
228-
f: &fn(s: &str) -> T) -> T {
229+
fn with_str_from_to<T>(
230+
rdr: @mut StringReader,
231+
start: BytePos,
232+
end: BytePos,
233+
f: |s: &str| -> T)
234+
-> T {
229235
f(rdr.src.slice(
230236
byte_offset(rdr, start).to_uint(),
231237
byte_offset(rdr, end).to_uint()))

src/libsyntax/parse/mod.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,14 @@ pub fn parse_tts_from_source_str(
177177
// consumed all of the input before returning the function's
178178
// result.
179179
pub fn parse_from_source_str<T>(
180-
f: &fn(&Parser) -> T,
181-
name: @str, ss: codemap::FileSubstr,
182-
source: @str,
183-
cfg: ast::CrateConfig,
184-
sess: @mut ParseSess
185-
) -> T {
186-
let p = new_parser_from_source_substr(
187-
sess,
188-
cfg,
189-
name,
190-
ss,
191-
source
192-
);
180+
f: |&Parser| -> T,
181+
name: @str,
182+
ss: codemap::FileSubstr,
183+
source: @str,
184+
cfg: ast::CrateConfig,
185+
sess: @mut ParseSess)
186+
-> T {
187+
let p = new_parser_from_source_substr(sess, cfg, name, ss, source);
193188
let r = f(&p);
194189
if !p.reader.is_eof() {
195190
p.reader.fatal(~"expected end-of-string");

src/libsyntax/parse/obsolete.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl ParserObsoleteMethods for Parser {
8282
),
8383
ObsoleteBareFnType => (
8484
"bare function type",
85-
"use `&fn` or `extern fn` instead"
85+
"use `|A| -> B` or `extern fn(A) -> B` instead"
8686
),
8787
ObsoleteNamedExternModule => (
8888
"named external module",

0 commit comments

Comments
 (0)