Skip to content

Commit e43b02e

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 163800 b: refs/heads/master c: 0dac05d h: refs/heads/master v: v3
1 parent 8e8a71a commit e43b02e

33 files changed

+378
-246
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 2160427900ea675e494274d42a8d8485724f440e
2+
refs/heads/master: 0dac05dd627612232403c07ca8bd6d3376eec64a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 8443b09e361b96d1f9b7f45a65ed0d31c0e86e70
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42

trunk/src/libsyntax/ast_map/blocks.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,23 @@ impl<'a> FnLikeNode<'a> {
181181
}
182182

183183
pub fn kind(self) -> visit::FnKind<'a> {
184-
let item = |p: ItemFnParts<'a>| -> visit::FnKind<'a> {
184+
let item = |: p: ItemFnParts<'a>| -> visit::FnKind<'a> {
185185
visit::FkItemFn(p.ident, p.generics, p.style, p.abi)
186186
};
187-
let closure = |_: ClosureParts| {
187+
let closure = |: _: ClosureParts| {
188188
visit::FkFnBlock
189189
};
190-
let method = |m: &'a ast::Method| {
190+
let method = |: m: &'a ast::Method| {
191191
visit::FkMethod(m.pe_ident(), m.pe_generics(), m)
192192
};
193193
self.handle(item, method, closure)
194194
}
195195

196-
fn handle<A>(self,
197-
item_fn: |ItemFnParts<'a>| -> A,
198-
method: |&'a ast::Method| -> A,
199-
closure: |ClosureParts<'a>| -> A) -> A {
196+
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
197+
I: FnOnce(ItemFnParts<'a>) -> A,
198+
M: FnOnce(&'a ast::Method) -> A,
199+
C: FnOnce(ClosureParts<'a>) -> A,
200+
{
200201
match self.node {
201202
ast_map::NodeItem(i) => match i.node {
202203
ast::ItemFn(ref decl, style, abi, ref generics, ref block) =>

trunk/src/libsyntax/ast_map/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ impl<'ast> Map<'ast> {
424424
}
425425
}
426426

427-
pub fn with_path<T>(&self, id: NodeId, f: |PathElems| -> T) -> T {
427+
pub fn with_path<T, F>(&self, id: NodeId, f: F) -> T where
428+
F: FnOnce(PathElems) -> T,
429+
{
428430
self.with_path_next(id, None, f)
429431
}
430432

@@ -438,7 +440,9 @@ impl<'ast> Map<'ast> {
438440
})
439441
}
440442

441-
fn with_path_next<T>(&self, id: NodeId, next: LinkedPath, f: |PathElems| -> T) -> T {
443+
fn with_path_next<T, F>(&self, id: NodeId, next: LinkedPath, f: F) -> T where
444+
F: FnOnce(PathElems) -> T,
445+
{
442446
let parent = self.get_parent(id);
443447
let parent = match self.find_entry(id) {
444448
Some(EntryForeignItem(..)) | Some(EntryVariant(..)) => {
@@ -470,7 +474,9 @@ impl<'ast> Map<'ast> {
470474

471475
/// Given a node ID and a closure, apply the closure to the array
472476
/// of attributes associated with the AST corresponding to the Node ID
473-
pub fn with_attrs<T>(&self, id: NodeId, f: |Option<&[Attribute]>| -> T) -> T {
477+
pub fn with_attrs<T, F>(&self, id: NodeId, f: F) -> T where
478+
F: FnOnce(Option<&[Attribute]>) -> T,
479+
{
474480
let attrs = match self.get(id) {
475481
NodeItem(i) => Some(i.attrs.as_slice()),
476482
NodeForeignItem(fi) => Some(fi.attrs.as_slice()),

trunk/src/libsyntax/ast_util.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
602602
id_visitor.operation.result
603603
}
604604

605+
// FIXME(#19596) unbox `it`
605606
pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
606607
if !it(pat) {
607608
return false;
@@ -632,21 +633,21 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
632633
}
633634

634635
pub trait EachViewItem {
635-
fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool;
636+
fn each_view_item<F>(&self, f: F) -> bool where F: FnMut(&ast::ViewItem) -> bool;
636637
}
637638

638-
struct EachViewItemData<'a> {
639-
callback: |&ast::ViewItem|: 'a -> bool,
639+
struct EachViewItemData<F> where F: FnMut(&ast::ViewItem) -> bool {
640+
callback: F,
640641
}
641642

642-
impl<'a, 'v> Visitor<'v> for EachViewItemData<'a> {
643+
impl<'v, F> Visitor<'v> for EachViewItemData<F> where F: FnMut(&ast::ViewItem) -> bool {
643644
fn visit_view_item(&mut self, view_item: &ast::ViewItem) {
644645
let _ = (self.callback)(view_item);
645646
}
646647
}
647648

648649
impl EachViewItem for ast::Crate {
649-
fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool {
650+
fn each_view_item<F>(&self, f: F) -> bool where F: FnMut(&ast::ViewItem) -> bool {
650651
let mut visit = EachViewItemData {
651652
callback: f,
652653
};

trunk/src/libsyntax/attr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ impl AttrMetaMethods for P<MetaItem> {
115115

116116
pub trait AttributeMethods {
117117
fn meta<'a>(&'a self) -> &'a MetaItem;
118-
fn with_desugared_doc<T>(&self, f: |&Attribute| -> T) -> T;
118+
fn with_desugared_doc<T, F>(&self, f: F) -> T where
119+
F: FnOnce(&Attribute) -> T;
119120
}
120121

121122
impl AttributeMethods for Attribute {
@@ -127,7 +128,9 @@ impl AttributeMethods for Attribute {
127128
/// Convert self to a normal #[doc="foo"] comment, if it is a
128129
/// comment like `///` or `/** */`. (Returns self unchanged for
129130
/// non-sugared doc attributes.)
130-
fn with_desugared_doc<T>(&self, f: |&Attribute| -> T) -> T {
131+
fn with_desugared_doc<T, F>(&self, f: F) -> T where
132+
F: FnOnce(&Attribute) -> T,
133+
{
131134
if self.node.is_sugared_doc {
132135
let comment = self.value_str().unwrap();
133136
let meta = mk_name_value_item_str(

trunk/src/libsyntax/codemap.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ impl CodeMap {
568568
ExpnId(expansions.len().to_u32().expect("too many ExpnInfo's!") - 1)
569569
}
570570

571-
pub fn with_expn_info<T>(&self, id: ExpnId, f: |Option<&ExpnInfo>| -> T) -> T {
571+
pub fn with_expn_info<T, F>(&self, id: ExpnId, f: F) -> T where
572+
F: FnOnce(Option<&ExpnInfo>) -> T,
573+
{
572574
match id {
573575
NO_EXPANSION => f(None),
574576
ExpnId(i) => f(Some(&(*self.expansions.borrow())[i as uint]))

trunk/src/libsyntax/config.rs

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use util::small_vector::SmallVector;
1919

2020
/// A folder that strips out items that do not belong in the current
2121
/// configuration.
22-
struct Context<'a> {
23-
in_cfg: |attrs: &[ast::Attribute]|: 'a -> bool,
22+
struct Context<F> where F: FnMut(&[ast::Attribute]) -> bool {
23+
in_cfg: F,
2424
}
2525

2626
// Support conditional compilation by transforming the AST, stripping out
@@ -30,7 +30,7 @@ pub fn strip_unconfigured_items(diagnostic: &SpanHandler, krate: ast::Crate) ->
3030
strip_items(krate, |attrs| in_cfg(diagnostic, config.as_slice(), attrs))
3131
}
3232

33-
impl<'a> fold::Folder for Context<'a> {
33+
impl<F> fold::Folder for Context<F> where F: FnMut(&[ast::Attribute]) -> bool {
3434
fn fold_mod(&mut self, module: ast::Mod) -> ast::Mod {
3535
fold_mod(self, module)
3636
}
@@ -54,24 +54,32 @@ impl<'a> fold::Folder for Context<'a> {
5454
}
5555
}
5656

57-
pub fn strip_items(krate: ast::Crate,
58-
in_cfg: |attrs: &[ast::Attribute]| -> bool)
59-
-> ast::Crate {
57+
pub fn strip_items<F>(krate: ast::Crate, in_cfg: F) -> ast::Crate where
58+
F: FnMut(&[ast::Attribute]) -> bool,
59+
{
6060
let mut ctxt = Context {
6161
in_cfg: in_cfg,
6262
};
6363
ctxt.fold_crate(krate)
6464
}
6565

66-
fn filter_view_item(cx: &mut Context, view_item: ast::ViewItem) -> Option<ast::ViewItem> {
66+
fn filter_view_item<F>(cx: &mut Context<F>,
67+
view_item: ast::ViewItem)
68+
-> Option<ast::ViewItem> where
69+
F: FnMut(&[ast::Attribute]) -> bool
70+
{
6771
if view_item_in_cfg(cx, &view_item) {
6872
Some(view_item)
6973
} else {
7074
None
7175
}
7276
}
7377

74-
fn fold_mod(cx: &mut Context, ast::Mod {inner, view_items, items}: ast::Mod) -> ast::Mod {
78+
fn fold_mod<F>(cx: &mut Context<F>,
79+
ast::Mod {inner,
80+
view_items, items}: ast::Mod) -> ast::Mod where
81+
F: FnMut(&[ast::Attribute]) -> bool
82+
{
7583
ast::Mod {
7684
inner: inner,
7785
view_items: view_items.into_iter().filter_map(|a| {
@@ -83,17 +91,23 @@ fn fold_mod(cx: &mut Context, ast::Mod {inner, view_items, items}: ast::Mod) ->
8391
}
8492
}
8593

86-
fn filter_foreign_item(cx: &mut Context, item: P<ast::ForeignItem>)
87-
-> Option<P<ast::ForeignItem>> {
94+
fn filter_foreign_item<F>(cx: &mut Context<F>,
95+
item: P<ast::ForeignItem>)
96+
-> Option<P<ast::ForeignItem>> where
97+
F: FnMut(&[ast::Attribute]) -> bool
98+
{
8899
if foreign_item_in_cfg(cx, &*item) {
89100
Some(item)
90101
} else {
91102
None
92103
}
93104
}
94105

95-
fn fold_foreign_mod(cx: &mut Context, ast::ForeignMod {abi, view_items, items}: ast::ForeignMod)
96-
-> ast::ForeignMod {
106+
fn fold_foreign_mod<F>(cx: &mut Context<F>,
107+
ast::ForeignMod {abi, view_items, items}: ast::ForeignMod)
108+
-> ast::ForeignMod where
109+
F: FnMut(&[ast::Attribute]) -> bool
110+
{
97111
ast::ForeignMod {
98112
abi: abi,
99113
view_items: view_items.into_iter().filter_map(|a| {
@@ -105,15 +119,19 @@ fn fold_foreign_mod(cx: &mut Context, ast::ForeignMod {abi, view_items, items}:
105119
}
106120
}
107121

108-
fn fold_item(cx: &mut Context, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
122+
fn fold_item<F>(cx: &mut Context<F>, item: P<ast::Item>) -> SmallVector<P<ast::Item>> where
123+
F: FnMut(&[ast::Attribute]) -> bool
124+
{
109125
if item_in_cfg(cx, &*item) {
110126
SmallVector::one(item.map(|i| cx.fold_item_simple(i)))
111127
} else {
112128
SmallVector::zero()
113129
}
114130
}
115131

116-
fn fold_item_underscore(cx: &mut Context, item: ast::Item_) -> ast::Item_ {
132+
fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_ where
133+
F: FnMut(&[ast::Attribute]) -> bool
134+
{
117135
let item = match item {
118136
ast::ItemImpl(a, b, c, impl_items) => {
119137
let impl_items = impl_items.into_iter()
@@ -166,7 +184,9 @@ fn fold_item_underscore(cx: &mut Context, item: ast::Item_) -> ast::Item_ {
166184
fold::noop_fold_item_underscore(item, cx)
167185
}
168186

169-
fn fold_struct(cx: &mut Context, def: P<ast::StructDef>) -> P<ast::StructDef> {
187+
fn fold_struct<F>(cx: &mut Context<F>, def: P<ast::StructDef>) -> P<ast::StructDef> where
188+
F: FnMut(&[ast::Attribute]) -> bool
189+
{
170190
def.map(|ast::StructDef { fields, ctor_id }| {
171191
ast::StructDef {
172192
fields: fields.into_iter().filter(|m| {
@@ -177,7 +197,9 @@ fn fold_struct(cx: &mut Context, def: P<ast::StructDef>) -> P<ast::StructDef> {
177197
})
178198
}
179199

180-
fn retain_stmt(cx: &mut Context, stmt: &ast::Stmt) -> bool {
200+
fn retain_stmt<F>(cx: &mut Context<F>, stmt: &ast::Stmt) -> bool where
201+
F: FnMut(&[ast::Attribute]) -> bool
202+
{
181203
match stmt.node {
182204
ast::StmtDecl(ref decl, _) => {
183205
match decl.node {
@@ -191,7 +213,9 @@ fn retain_stmt(cx: &mut Context, stmt: &ast::Stmt) -> bool {
191213
}
192214
}
193215

194-
fn fold_block(cx: &mut Context, b: P<ast::Block>) -> P<ast::Block> {
216+
fn fold_block<F>(cx: &mut Context<F>, b: P<ast::Block>) -> P<ast::Block> where
217+
F: FnMut(&[ast::Attribute]) -> bool
218+
{
195219
b.map(|ast::Block {id, view_items, stmts, expr, rules, span}| {
196220
let resulting_stmts: Vec<P<ast::Stmt>> =
197221
stmts.into_iter().filter(|a| retain_stmt(cx, &**a)).collect();
@@ -212,7 +236,9 @@ fn fold_block(cx: &mut Context, b: P<ast::Block>) -> P<ast::Block> {
212236
})
213237
}
214238

215-
fn fold_expr(cx: &mut Context, expr: P<ast::Expr>) -> P<ast::Expr> {
239+
fn fold_expr<F>(cx: &mut Context<F>, expr: P<ast::Expr>) -> P<ast::Expr> where
240+
F: FnMut(&[ast::Attribute]) -> bool
241+
{
216242
expr.map(|ast::Expr {id, span, node}| {
217243
fold::noop_fold_expr(ast::Expr {
218244
id: id,
@@ -229,27 +255,37 @@ fn fold_expr(cx: &mut Context, expr: P<ast::Expr>) -> P<ast::Expr> {
229255
})
230256
}
231257

232-
fn item_in_cfg(cx: &mut Context, item: &ast::Item) -> bool {
258+
fn item_in_cfg<F>(cx: &mut Context<F>, item: &ast::Item) -> bool where
259+
F: FnMut(&[ast::Attribute]) -> bool
260+
{
233261
return (cx.in_cfg)(item.attrs.as_slice());
234262
}
235263

236-
fn foreign_item_in_cfg(cx: &mut Context, item: &ast::ForeignItem) -> bool {
264+
fn foreign_item_in_cfg<F>(cx: &mut Context<F>, item: &ast::ForeignItem) -> bool where
265+
F: FnMut(&[ast::Attribute]) -> bool
266+
{
237267
return (cx.in_cfg)(item.attrs.as_slice());
238268
}
239269

240-
fn view_item_in_cfg(cx: &mut Context, item: &ast::ViewItem) -> bool {
270+
fn view_item_in_cfg<F>(cx: &mut Context<F>, item: &ast::ViewItem) -> bool where
271+
F: FnMut(&[ast::Attribute]) -> bool
272+
{
241273
return (cx.in_cfg)(item.attrs.as_slice());
242274
}
243275

244-
fn trait_method_in_cfg(cx: &mut Context, meth: &ast::TraitItem) -> bool {
276+
fn trait_method_in_cfg<F>(cx: &mut Context<F>, meth: &ast::TraitItem) -> bool where
277+
F: FnMut(&[ast::Attribute]) -> bool
278+
{
245279
match *meth {
246280
ast::RequiredMethod(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()),
247281
ast::ProvidedMethod(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()),
248282
ast::TypeTraitItem(ref typ) => (cx.in_cfg)(typ.attrs.as_slice()),
249283
}
250284
}
251285

252-
fn impl_item_in_cfg(cx: &mut Context, impl_item: &ast::ImplItem) -> bool {
286+
fn impl_item_in_cfg<F>(cx: &mut Context<F>, impl_item: &ast::ImplItem) -> bool where
287+
F: FnMut(&[ast::Attribute]) -> bool
288+
{
253289
match *impl_item {
254290
ast::MethodImplItem(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()),
255291
ast::TypeImplItem(ref typ) => (cx.in_cfg)(typ.attrs.as_slice()),

trunk/src/libsyntax/diagnostic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ fn print_macro_backtrace(w: &mut EmitterWriter,
581581
cs.map_or(Ok(()), |call_site| print_macro_backtrace(w, cm, call_site))
582582
}
583583

584-
pub fn expect<T>(diag: &SpanHandler, opt: Option<T>, msg: || -> String) -> T {
584+
pub fn expect<T, M>(diag: &SpanHandler, opt: Option<T>, msg: M) -> T where
585+
M: FnOnce() -> String,
586+
{
585587
match opt {
586588
Some(t) => t,
587589
None => diag.handler().bug(msg().as_slice()),

trunk/src/libsyntax/diagnostics/plugin.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ thread_local!(static USED_DIAGNOSTICS: RefCell<HashMap<Name, Span>> = {
2525
RefCell::new(HashMap::new())
2626
})
2727

28-
fn with_registered_diagnostics<T>(f: |&mut HashMap<Name, Option<Name>>| -> T) -> T {
29-
REGISTERED_DIAGNOSTICS.with(|slot| {
28+
fn with_registered_diagnostics<T, F>(f: F) -> T where
29+
F: FnOnce(&mut HashMap<Name, Option<Name>>) -> T,
30+
{
31+
REGISTERED_DIAGNOSTICS.with(move |slot| {
3032
f(&mut *slot.borrow_mut())
3133
})
3234
}
3335

34-
fn with_used_diagnostics<T>(f: |&mut HashMap<Name, Span>| -> T) -> T {
35-
USED_DIAGNOSTICS.with(|slot| {
36+
fn with_used_diagnostics<T, F>(f: F) -> T where
37+
F: FnOnce(&mut HashMap<Name, Span>) -> T,
38+
{
39+
USED_DIAGNOSTICS.with(move |slot| {
3640
f(&mut *slot.borrow_mut())
3741
})
3842
}

trunk/src/libsyntax/ext/deriving/bounds.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ use ext::deriving::generic::*;
1515
use ext::deriving::generic::ty::*;
1616
use ptr::P;
1717

18-
pub fn expand_deriving_bound(cx: &mut ExtCtxt,
19-
span: Span,
20-
mitem: &MetaItem,
21-
item: &Item,
22-
push: |P<Item>|) {
23-
18+
pub fn expand_deriving_bound<F>(cx: &mut ExtCtxt,
19+
span: Span,
20+
mitem: &MetaItem,
21+
item: &Item,
22+
push: F) where
23+
F: FnOnce(P<Item>),
24+
{
2425
let name = match mitem.node {
2526
MetaWord(ref tname) => {
2627
match tname.get() {

0 commit comments

Comments
 (0)