Skip to content

Commit 7e3f201

Browse files
committed
librustc: Change most uses of &fn() to ||.
1 parent 492677e commit 7e3f201

Some content is hidden

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

51 files changed

+298
-293
lines changed

src/librustc/driver/session.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ pub fn basic_options() -> @options {
386386
}
387387

388388
// Seems out of place, but it uses session, so I'm putting it here
389-
pub fn expect<T:Clone>(sess: Session, opt: Option<T>, msg: &fn() -> ~str)
390-
-> T {
389+
pub fn expect<T:Clone>(sess: Session, opt: Option<T>, msg: || -> ~str) -> T {
391390
diagnostic::expect(sess.diagnostic(), opt, msg)
392391
}
393392

src/librustc/front/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'self> fold::ast_fold for Context<'self> {
4242
}
4343

4444
pub fn strip_items(crate: ast::Crate,
45-
in_cfg: &fn(attrs: &[ast::Attribute]) -> bool)
45+
in_cfg: |attrs: &[ast::Attribute]| -> bool)
4646
-> ast::Crate {
4747
let ctxt = Context {
4848
in_cfg: in_cfg,

src/librustc/metadata/csearch.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,18 @@ pub fn get_type_param_count(cstore: @mut cstore::CStore, def: ast::DefId)
4444
/// Iterates over all the language items in the given crate.
4545
pub fn each_lang_item(cstore: @mut cstore::CStore,
4646
cnum: ast::CrateNum,
47-
f: &fn(ast::NodeId, uint) -> bool) -> bool {
47+
f: |ast::NodeId, uint| -> bool)
48+
-> bool {
4849
let crate_data = cstore::get_crate_data(cstore, cnum);
4950
decoder::each_lang_item(crate_data, f)
5051
}
5152

5253
/// Iterates over each child of the given item.
5354
pub fn each_child_of_item(cstore: @mut cstore::CStore,
5455
def_id: ast::DefId,
55-
callback: &fn(decoder::DefLike, ast::Ident,
56-
ast::visibility)) {
56+
callback: |decoder::DefLike,
57+
ast::Ident,
58+
ast::visibility|) {
5759
let crate_data = cstore::get_crate_data(cstore, def_id.crate);
5860
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
5961
cstore::get_crate_data(cstore, cnum)
@@ -68,9 +70,9 @@ pub fn each_child_of_item(cstore: @mut cstore::CStore,
6870
/// Iterates over each top-level crate item.
6971
pub fn each_top_level_item_of_crate(cstore: @mut cstore::CStore,
7072
cnum: ast::CrateNum,
71-
callback: &fn(decoder::DefLike,
72-
ast::Ident,
73-
ast::visibility)) {
73+
callback: |decoder::DefLike,
74+
ast::Ident,
75+
ast::visibility|) {
7476
let crate_data = cstore::get_crate_data(cstore, cnum);
7577
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
7678
cstore::get_crate_data(cstore, cnum)
@@ -178,7 +180,7 @@ pub fn get_static_methods_if_impl(cstore: @mut cstore::CStore,
178180

179181
pub fn get_item_attrs(cstore: @mut cstore::CStore,
180182
def_id: ast::DefId,
181-
f: &fn(~[@ast::MetaItem])) {
183+
f: |~[@ast::MetaItem]|) {
182184
let cdata = cstore::get_crate_data(cstore, def_id.crate);
183185
decoder::get_item_attrs(cdata, def_id.node, f)
184186
}
@@ -262,21 +264,21 @@ pub fn get_item_visibility(cstore: @mut cstore::CStore,
262264

263265
pub fn each_impl(cstore: @mut cstore::CStore,
264266
crate_num: ast::CrateNum,
265-
callback: &fn(ast::DefId)) {
267+
callback: |ast::DefId|) {
266268
let cdata = cstore::get_crate_data(cstore, crate_num);
267269
decoder::each_impl(cdata, callback)
268270
}
269271

270272
pub fn each_implementation_for_type(cstore: @mut cstore::CStore,
271273
def_id: ast::DefId,
272-
callback: &fn(ast::DefId)) {
274+
callback: |ast::DefId|) {
273275
let cdata = cstore::get_crate_data(cstore, def_id.crate);
274276
decoder::each_implementation_for_type(cdata, def_id.node, callback)
275277
}
276278

277279
pub fn each_implementation_for_trait(cstore: @mut cstore::CStore,
278280
def_id: ast::DefId,
279-
callback: &fn(ast::DefId)) {
281+
callback: |ast::DefId|) {
280282
let cdata = cstore::get_crate_data(cstore, def_id.crate);
281283
decoder::each_implementation_for_trait(cdata, def_id.node, callback)
282284
}

src/librustc/metadata/cstore.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::CrateNum) -> bool {
8282
cstore.metas.contains_key(&cnum)
8383
}
8484

85-
pub fn iter_crate_data(cstore: &CStore,
86-
i: &fn(ast::CrateNum, @crate_metadata)) {
85+
pub fn iter_crate_data(cstore: &CStore, i: |ast::CrateNum, @crate_metadata|) {
8786
for (&k, &v) in cstore.metas.iter() {
8887
i(k, v);
8988
}

src/librustc/metadata/decoder.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type Cmd = @crate_metadata;
5151
// what crate that's in and give us a def_id that makes sense for the current
5252
// build.
5353

54-
fn lookup_hash(d: ebml::Doc, eq_fn: &fn(x:&[u8]) -> bool, hash: u64) ->
54+
fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) ->
5555
Option<ebml::Doc> {
5656
let index = reader::get_doc(d, tag_index);
5757
let table = reader::get_doc(index, tag_index_table);
@@ -205,7 +205,7 @@ fn get_provided_source(d: ebml::Doc, cdata: Cmd) -> Option<ast::DefId> {
205205
}
206206
}
207207

208-
fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) -> bool {
208+
fn each_reexport(d: ebml::Doc, f: |ebml::Doc| -> bool) -> bool {
209209
reader::tagged_docs(d, tag_items_data_item_reexport, f)
210210
}
211211

@@ -509,7 +509,7 @@ pub fn def_like_to_def(def_like: DefLike) -> ast::Def {
509509
}
510510

511511
/// Iterates over the language items in the given crate.
512-
pub fn each_lang_item(cdata: Cmd, f: &fn(ast::NodeId, uint) -> bool) -> bool {
512+
pub fn each_lang_item(cdata: Cmd, f: |ast::NodeId, uint| -> bool) -> bool {
513513
let root = reader::Doc(cdata.data);
514514
let lang_items = reader::get_doc(root, tag_lang_items);
515515
do reader::tagged_docs(lang_items, tag_lang_items_item) |item_doc| {
@@ -733,8 +733,9 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
733733
cdata: Cmd,
734734
item_doc: ebml::Doc,
735735
get_crate_data: GetCrateDataCb,
736-
callback: &fn(DefLike, ast::Ident,
737-
ast::visibility)) {
736+
callback: |DefLike,
737+
ast::Ident,
738+
ast::visibility|) {
738739
// Iterate over all children.
739740
let _ = do reader::tagged_docs(item_doc, tag_mod_child) |child_info_doc| {
740741
let child_def_id = reader::with_doc_data(child_info_doc,
@@ -861,7 +862,7 @@ pub fn each_child_of_item(intr: @ident_interner,
861862
cdata: Cmd,
862863
id: ast::NodeId,
863864
get_crate_data: GetCrateDataCb,
864-
callback: &fn(DefLike, ast::Ident, ast::visibility)) {
865+
callback: |DefLike, ast::Ident, ast::visibility|) {
865866
// Find the item.
866867
let root_doc = reader::Doc(cdata.data);
867868
let items = reader::get_doc(root_doc, tag_items);
@@ -881,8 +882,9 @@ pub fn each_child_of_item(intr: @ident_interner,
881882
pub fn each_top_level_item_of_crate(intr: @ident_interner,
882883
cdata: Cmd,
883884
get_crate_data: GetCrateDataCb,
884-
callback: &fn(DefLike, ast::Ident,
885-
ast::visibility)) {
885+
callback: |DefLike,
886+
ast::Ident,
887+
ast::visibility|) {
886888
let root_doc = reader::Doc(cdata.data);
887889
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
888890
let crate_items_doc = reader::get_doc(misc_info_doc,
@@ -1201,8 +1203,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
12011203

12021204
pub fn get_item_attrs(cdata: Cmd,
12031205
node_id: ast::NodeId,
1204-
f: &fn(~[@ast::MetaItem])) {
1205-
1206+
f: |~[@ast::MetaItem]|) {
12061207
let item = lookup_item(node_id, cdata.data);
12071208
do reader::tagged_docs(item, tag_attributes) |attributes| {
12081209
do reader::tagged_docs(attributes, tag_attribute) |attribute| {
@@ -1474,7 +1475,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId {
14741475
}
14751476
}
14761477

1477-
pub fn each_impl(cdata: Cmd, callback: &fn(ast::DefId)) {
1478+
pub fn each_impl(cdata: Cmd, callback: |ast::DefId|) {
14781479
let impls_doc = reader::get_doc(reader::Doc(cdata.data), tag_impls);
14791480
let _ = do reader::tagged_docs(impls_doc, tag_impls_impl) |impl_doc| {
14801481
callback(item_def_id(impl_doc, cdata));
@@ -1484,7 +1485,7 @@ pub fn each_impl(cdata: Cmd, callback: &fn(ast::DefId)) {
14841485

14851486
pub fn each_implementation_for_type(cdata: Cmd,
14861487
id: ast::NodeId,
1487-
callback: &fn(ast::DefId)) {
1488+
callback: |ast::DefId|) {
14881489
let item_doc = lookup_item(id, cdata.data);
14891490
do reader::tagged_docs(item_doc, tag_items_data_item_inherent_impl)
14901491
|impl_doc| {
@@ -1496,7 +1497,7 @@ pub fn each_implementation_for_type(cdata: Cmd,
14961497

14971498
pub fn each_implementation_for_trait(cdata: Cmd,
14981499
id: ast::NodeId,
1499-
callback: &fn(ast::DefId)) {
1500+
callback: |ast::DefId|) {
15001501
let item_doc = lookup_item(id, cdata.data);
15011502

15021503
let _ = do reader::tagged_docs(item_doc,

src/librustc/metadata/encoder.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
535535
/// * For enums, iterates through the node IDs of the variants.
536536
///
537537
/// * For newtype structs, iterates through the node ID of the constructor.
538-
fn each_auxiliary_node_id(item: @item, callback: &fn(NodeId) -> bool)
539-
-> bool {
538+
fn each_auxiliary_node_id(item: @item, callback: |NodeId| -> bool) -> bool {
540539
let mut continue_ = true;
541540
match item.node {
542541
item_enum(ref enum_def, _) => {
@@ -912,7 +911,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
912911
index: @mut ~[entry<i64>]) {
913912
index.push(entry { val: item.id as i64, pos: ebml_w.writer.tell() });
914913
}
915-
let add_to_index: &fn() = || add_to_index(item, ebml_w, index);
914+
let add_to_index: || = || add_to_index(item, ebml_w, index);
916915

917916
debug!("encoding info for item at {}",
918917
ecx.tcx.sess.codemap.span_to_str(item.span));
@@ -1412,7 +1411,7 @@ fn create_index<T:Clone + Hash + IterBytes + 'static>(
14121411
fn encode_index<T:'static>(
14131412
ebml_w: &mut writer::Encoder,
14141413
buckets: ~[@~[entry<T>]],
1415-
write_fn: &fn(@mut MemWriter, &T)) {
1414+
write_fn: |@mut MemWriter, &T|) {
14161415
ebml_w.start_tag(tag_index);
14171416
let mut bucket_locs = ~[];
14181417
ebml_w.start_tag(tag_index_buckets);

src/librustc/metadata/filesearch.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
3535

3636
pub trait FileSearch {
3737
fn sysroot(&self) -> @Path;
38-
fn for_each_lib_search_path(&self, f: &fn(&Path) -> FileMatch);
38+
fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch);
3939
fn get_target_lib_path(&self) -> Path;
4040
fn get_target_lib_file_path(&self, file: &Path) -> Path;
4141
}
@@ -51,7 +51,8 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
5151
}
5252
impl FileSearch for FileSearchImpl {
5353
fn sysroot(&self) -> @Path { self.sysroot }
54-
fn for_each_lib_search_path(&self, f: &fn(&Path) -> FileMatch) {
54+
55+
fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) {
5556
let mut visited_dirs = HashSet::new();
5657
let mut found = false;
5758

src/librustc/metadata/tydecode.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ fn next_byte(st: &mut PState) -> u8 {
7979
return b;
8080
}
8181

82-
fn scan<R>(st: &mut PState, is_last: &fn(char) -> bool,
83-
op: &fn(&[u8]) -> R) -> R
84-
{
82+
fn scan<R>(st: &mut PState, is_last: |char| -> bool, op: |&[u8]| -> R) -> R {
8583
let start_pos = st.pos;
8684
debug!("scan: '{}' (start)", st.data[st.pos] as char);
8785
while !is_last(st.data[st.pos] as char) {
@@ -98,7 +96,7 @@ pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
9896
return parse_ident_(st, |a| is_last(last, a) );
9997
}
10098

101-
fn parse_ident_(st: &mut PState, is_last: &fn(char) -> bool) -> ast::Ident {
99+
fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident {
102100
let rslt = scan(st, is_last, str::from_utf8);
103101
return st.tcx.sess.ident_of(rslt);
104102
}
@@ -292,7 +290,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
292290
}
293291
}
294292

295-
fn parse_opt<T>(st: &mut PState, f: &fn(&mut PState) -> T) -> Option<T> {
293+
fn parse_opt<T>(st: &mut PState, f: |&mut PState| -> T) -> Option<T> {
296294
match next(st) {
297295
'n' => None,
298296
's' => Some(f(st)),

src/librustc/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn enc_mt(w: @mut MemWriter, cx: @ctxt, mt: ty::mt) {
120120
enc_ty(w, cx, mt.ty);
121121
}
122122

123-
fn enc_opt<T>(w: @mut MemWriter, t: Option<T>, enc_f: &fn(T)) {
123+
fn enc_opt<T>(w: @mut MemWriter, t: Option<T>, enc_f: |T|) {
124124
match t {
125125
None => mywrite!(w, "n"),
126126
Some(v) => {

src/librustc/middle/astencode.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -845,14 +845,12 @@ impl ebml_writer_helpers for writer::Encoder {
845845
}
846846

847847
trait write_tag_and_id {
848-
fn tag(&mut self, tag_id: c::astencode_tag, f: &fn(&mut Self));
848+
fn tag(&mut self, tag_id: c::astencode_tag, f: |&mut Self|);
849849
fn id(&mut self, id: ast::NodeId);
850850
}
851851

852852
impl write_tag_and_id for writer::Encoder {
853-
fn tag(&mut self,
854-
tag_id: c::astencode_tag,
855-
f: &fn(&mut writer::Encoder)) {
853+
fn tag(&mut self, tag_id: c::astencode_tag, f: |&mut writer::Encoder|) {
856854
self.start_tag(tag_id as uint);
857855
f(self);
858856
self.end_tag();

src/librustc/middle/borrowck/check_loans.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ impl<'self> CheckLoanCtxt<'self> {
124124

125125
pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
126126

127-
pub fn each_issued_loan(&self,
128-
scope_id: ast::NodeId,
129-
op: &fn(&Loan) -> bool)
127+
pub fn each_issued_loan(&self, scope_id: ast::NodeId, op: |&Loan| -> bool)
130128
-> bool {
131129
//! Iterates over each loan that has been issued
132130
//! on entrance to `scope_id`, regardless of whether it is
@@ -142,7 +140,7 @@ impl<'self> CheckLoanCtxt<'self> {
142140

143141
pub fn each_in_scope_loan(&self,
144142
scope_id: ast::NodeId,
145-
op: &fn(&Loan) -> bool)
143+
op: |&Loan| -> bool)
146144
-> bool {
147145
//! Like `each_issued_loan()`, but only considers loans that are
148146
//! currently in scope.
@@ -160,7 +158,7 @@ impl<'self> CheckLoanCtxt<'self> {
160158
pub fn each_in_scope_restriction(&self,
161159
scope_id: ast::NodeId,
162160
loan_path: @LoanPath,
163-
op: &fn(&Loan, &Restriction) -> bool)
161+
op: |&Loan, &Restriction| -> bool)
164162
-> bool {
165163
//! Iterates through all the in-scope restrictions for the
166164
//! given `loan_path`

src/librustc/middle/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl BorrowckCtxt {
533533
pub fn cat_pattern(&self,
534534
cmt: mc::cmt,
535535
pat: @ast::Pat,
536-
op: &fn(mc::cmt, @ast::Pat)) {
536+
op: |mc::cmt, @ast::Pat|) {
537537
let mc = self.mc_ctxt();
538538
mc.cat_pattern(cmt, pat, op);
539539
}

src/librustc/middle/borrowck/move_data.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ impl MoveData {
412412
}
413413
}
414414

415-
fn each_base_path(&self,
416-
index: MovePathIndex,
417-
f: &fn(MovePathIndex) -> bool)
415+
fn each_base_path(&self, index: MovePathIndex, f: |MovePathIndex| -> bool)
418416
-> bool {
419417
let mut p = index;
420418
while p != InvalidMovePathIndex {
@@ -428,7 +426,8 @@ impl MoveData {
428426

429427
fn each_extending_path(&self,
430428
index: MovePathIndex,
431-
f: &fn(MovePathIndex) -> bool) -> bool {
429+
f: |MovePathIndex| -> bool)
430+
-> bool {
432431
if !f(index) {
433432
return false;
434433
}
@@ -446,7 +445,8 @@ impl MoveData {
446445

447446
fn each_applicable_move(&self,
448447
index0: MovePathIndex,
449-
f: &fn(MoveIndex) -> bool) -> bool {
448+
f: |MoveIndex| -> bool)
449+
-> bool {
450450
let mut ret = true;
451451
do self.each_extending_path(index0) |index| {
452452
let mut p = self.path(index).first_move;
@@ -505,7 +505,7 @@ impl FlowedMoveData {
505505

506506
pub fn each_path_moved_by(&self,
507507
id: ast::NodeId,
508-
f: &fn(&Move, @LoanPath) -> bool)
508+
f: |&Move, @LoanPath| -> bool)
509509
-> bool {
510510
/*!
511511
* Iterates through each path moved by `id`
@@ -521,7 +521,7 @@ impl FlowedMoveData {
521521
pub fn each_move_of(&self,
522522
id: ast::NodeId,
523523
loan_path: @LoanPath,
524-
f: &fn(&Move, @LoanPath) -> bool)
524+
f: |&Move, @LoanPath| -> bool)
525525
-> bool {
526526
/*!
527527
* Iterates through each move of `loan_path` (or some base path
@@ -587,7 +587,7 @@ impl FlowedMoveData {
587587
pub fn each_assignment_of(&self,
588588
id: ast::NodeId,
589589
loan_path: @LoanPath,
590-
f: &fn(&Assignment) -> bool)
590+
f: |&Assignment| -> bool)
591591
-> bool {
592592
/*!
593593
* Iterates through every assignment to `loan_path` that

0 commit comments

Comments
 (0)