libsyntax: Remove all non-proc do syntax.

This commit is contained in:
Patrick Walton 2013-11-20 16:23:04 -08:00
parent a61a3678eb
commit efc512362b
26 changed files with 178 additions and 192 deletions

View file

@ -370,9 +370,9 @@ impl AstBuilder for @ExtCtxt {
}
fn strip_bounds(&self, generics: &Generics) -> Generics {
let new_params = do generics.ty_params.map |ty_param| {
let new_params = generics.ty_params.map(|ty_param| {
ast::TyParam { bounds: opt_vec::Empty, ..*ty_param }
};
});
Generics {
ty_params: new_params,
.. (*generics).clone()
@ -883,9 +883,9 @@ impl AstBuilder for @ExtCtxt {
fn view_use_list(&self, sp: Span, vis: ast::visibility,
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item {
let imports = do imports.map |id| {
let imports = imports.map(|id| {
respan(sp, ast::path_list_ident_ { name: *id, id: ast::DUMMY_NODE_ID })
};
});
self.view_use(sp, vis,
~[@respan(sp,

View file

@ -103,7 +103,7 @@ fn cs_clone(
},
_ => {
// struct-like
let fields = do all_fields.map |field| {
let fields = all_fields.map(|field| {
let ident = match field.name {
Some(i) => i,
None => cx.span_bug(span,
@ -111,7 +111,7 @@ fn cs_clone(
name))
};
cx.field_imm(span, ident, subcall(field.self_))
};
});
if fields.is_empty() {
// no fields, so construct like `None`

View file

@ -70,13 +70,16 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span,
};
let read_struct_field = cx.ident_of("read_struct_field");
let result = do decode_static_fields(cx, span, substr.type_ident,
summary) |span, name, field| {
let result = decode_static_fields(cx,
span,
substr.type_ident,
summary,
|span, name, field| {
cx.expr_method_call(span, blkdecoder, read_struct_field,
~[cx.expr_str(span, name),
cx.expr_uint(span, field),
lambdadecode])
};
});
cx.expr_method_call(span, decoder, cx.ident_of("read_struct"),
~[cx.expr_str(span, cx.str_of(substr.type_ident)),
cx.expr_uint(span, nfields),
@ -93,12 +96,15 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span,
let (name, parts) = match *f { (i, ref p) => (i, p) };
variants.push(cx.expr_str(span, cx.str_of(name)));
let decoded = do decode_static_fields(cx, span, name,
parts) |span, _, field| {
let decoded = decode_static_fields(cx,
span,
name,
parts,
|span, _, field| {
cx.expr_method_call(span, blkdecoder, rvariant_arg,
~[cx.expr_uint(span, field),
lambdadecode])
};
});
arms.push(cx.arm(span,
~[cx.pat_lit(span, cx.expr_uint(span, i))],
@ -135,18 +141,18 @@ fn decode_static_fields(cx: @ExtCtxt,
if fields.is_empty() {
cx.expr_ident(outer_span, outer_pat_ident)
} else {
let fields = do fields.iter().enumerate().map |(i, &span)| {
let fields = fields.iter().enumerate().map(|(i, &span)| {
getarg(span, format!("_field{}", i).to_managed(), i)
}.collect();
}).collect();
cx.expr_call_ident(outer_span, outer_pat_ident, fields)
}
}
Named(ref fields) => {
// use the field's span to get nicer error messages.
let fields = do fields.iter().enumerate().map |(i, &(name, span))| {
let fields = fields.iter().enumerate().map(|(i, &(name, span))| {
cx.field_imm(span, name, getarg(span, cx.str_of(name), i))
}.collect();
}).collect();
cx.expr_struct_ident(outer_span, outer_pat_ident, fields)
}
}

View file

@ -60,9 +60,9 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp
}
}
Named(ref fields) => {
let default_fields = do fields.map |&(ident, span)| {
let default_fields = fields.map(|&(ident, span)| {
cx.field_imm(span, ident, default_call(span))
};
});
cx.expr_struct_ident(span, substr.type_ident, default_fields)
}
}

View file

@ -24,19 +24,19 @@ would generate two implementations like:
impl<S:extra::serialize::Encoder> Encodable<S> for Node {
fn encode(&self, s: &S) {
do s.emit_struct("Node", 1) {
s.emit_struct("Node", 1, || {
s.emit_field("id", 0, || s.emit_uint(self.id))
}
})
}
}
impl<D:Decoder> Decodable for node_id {
fn decode(d: &D) -> Node {
do d.read_struct("Node", 1) {
d.read_struct("Node", 1, || {
Node {
id: d.read_field(~"x", 0, || decode(d))
}
}
})
}
}
@ -53,10 +53,10 @@ would yield functions like:
T: Encodable<S>
> spanned<T>: Encodable<S> {
fn encode<S:Encoder>(s: &S) {
do s.emit_rec {
s.emit_rec(|| {
s.emit_field("node", 0, || self.node.encode(s));
s.emit_field("span", 1, || self.span.encode(s));
}
})
}
}
@ -65,12 +65,12 @@ would yield functions like:
T: Decodable<D>
> spanned<T>: Decodable<D> {
fn decode(d: &D) -> spanned<T> {
do d.read_rec {
d.read_rec(|| {
{
node: d.read_field(~"node", 0, || decode(d)),
span: d.read_field(~"span", 1, || decode(d)),
}
}
})
}
}
*/

View file

@ -362,9 +362,9 @@ impl<'self> TraitDef<'self> {
// a TyParamBound requires an ast id
let mut bounds = opt_vec::from(
// extra restrictions on the generics parameters to the type being derived upon
do self.additional_bounds.map |p| {
self.additional_bounds.map(|p| {
cx.typarambound(p.to_path(cx, trait_span, type_ident, generics))
});
}));
// require the current trait
bounds.push(cx.typarambound(trait_path.clone()));
@ -375,9 +375,9 @@ impl<'self> TraitDef<'self> {
let trait_ref = cx.trait_ref(trait_path);
// Create the type parameters on the `self` path.
let self_ty_params = do generics.ty_params.map |ty_param| {
let self_ty_params = generics.ty_params.map(|ty_param| {
cx.ty_ident(trait_span, ty_param.ident)
};
});
let self_lifetimes = generics.lifetimes.clone();
@ -405,7 +405,7 @@ impl<'self> TraitDef<'self> {
struct_def: &struct_def,
type_ident: Ident,
generics: &Generics) -> @ast::item {
let methods = do self.methods.map |method_def| {
let methods = self.methods.map(|method_def| {
let (explicit_self, self_args, nonself_args, tys) =
method_def.split_self_nonself_args(cx, trait_span, type_ident, generics);
@ -426,7 +426,7 @@ impl<'self> TraitDef<'self> {
type_ident, generics,
explicit_self, tys,
body)
};
});
self.create_derived_impl(cx, trait_span, type_ident, generics, methods)
}
@ -436,7 +436,7 @@ impl<'self> TraitDef<'self> {
enum_def: &enum_def,
type_ident: Ident,
generics: &Generics) -> @ast::item {
let methods = do self.methods.map |method_def| {
let methods = self.methods.map(|method_def| {
let (explicit_self, self_args, nonself_args, tys) =
method_def.split_self_nonself_args(cx, trait_span, type_ident, generics);
@ -457,7 +457,7 @@ impl<'self> TraitDef<'self> {
type_ident, generics,
explicit_self, tys,
body)
};
});
self.create_derived_impl(cx, trait_span, type_ident, generics, methods)
}
@ -547,9 +547,9 @@ impl<'self> MethodDef<'self> {
// create the generics that aren't for Self
let fn_generics = self.generics.to_generics(cx, trait_span, type_ident, generics);
let args = do arg_types.move_iter().map |(name, ty)| {
let args = arg_types.move_iter().map(|(name, ty)| {
cx.arg(trait_span, name, ty)
}.collect();
}).collect();
let ret_type = self.get_ret_ty(cx, trait_span, generics, type_ident);
@ -624,19 +624,19 @@ impl<'self> MethodDef<'self> {
// transpose raw_fields
let fields = match raw_fields {
[ref self_arg, .. rest] => {
do self_arg.iter().enumerate().map |(i, &(span, opt_id, field))| {
let other_fields = do rest.map |l| {
self_arg.iter().enumerate().map(|(i, &(span, opt_id, field))| {
let other_fields = rest.map(|l| {
match &l[i] {
&(_, _, ex) => ex
}
};
});
FieldInfo {
span: span,
name: opt_id,
self_: field,
other: other_fields
}
}.collect()
}).collect()
}
[] => { cx.span_bug(trait_span, "No self arguments to non-static \
method in generic `deriving`") }
@ -787,16 +787,16 @@ impl<'self> MethodDef<'self> {
}
}
let field_tuples =
do self_vec.iter()
.zip(enum_matching_fields.iter())
.map |(&(span, id, self_f), other)| {
self_vec.iter()
.zip(enum_matching_fields.iter())
.map(|(&(span, id, self_f), other)| {
FieldInfo {
span: span,
name: id,
self_: self_f,
other: (*other).clone()
}
}.collect();
}).collect();
substructure = EnumMatching(variant_index, variant, field_tuples);
}
None => {
@ -901,7 +901,7 @@ impl<'self> MethodDef<'self> {
self_args: &[@Expr],
nonself_args: &[@Expr])
-> @Expr {
let summary = do enum_def.variants.map |v| {
let summary = enum_def.variants.map(|v| {
let ident = v.node.name;
let summary = match v.node.kind {
ast::tuple_variant_kind(ref args) => Unnamed(args.map(|va| va.ty.span)),
@ -910,7 +910,7 @@ impl<'self> MethodDef<'self> {
}
};
(ident, summary)
};
});
self.call_substructure_method(cx,
trait_span, type_ident,
self_args, nonself_args,
@ -944,10 +944,10 @@ pub fn create_subpatterns(cx: @ExtCtxt,
field_paths: ~[ast::Path],
mutbl: ast::Mutability)
-> ~[@ast::Pat] {
do field_paths.map |path| {
field_paths.map(|path| {
cx.pat(path.span,
ast::PatIdent(ast::BindByRef(mutbl), (*path).clone(), None))
}
})
}
#[deriving(Eq)] // dogfooding!
@ -1003,10 +1003,10 @@ fn create_struct_pattern(cx: @ExtCtxt,
// struct_type is definitely not Unknown, since struct_def.fields
// must be nonempty to reach here
let pattern = if struct_type == Record {
let field_pats = do subpats.iter().zip(ident_expr.iter()).map |(&pat, &(_, id, _))| {
let field_pats = subpats.iter().zip(ident_expr.iter()).map(|(&pat, &(_, id, _))| {
// id is guaranteed to be Some
ast::FieldPat { ident: id.unwrap(), pat: pat }
}.collect();
}).collect();
cx.pat_struct(trait_span, matching_path, field_pats)
} else {
cx.pat_enum(trait_span, matching_path, subpats)
@ -1075,13 +1075,13 @@ pub fn cs_fold(use_foldl: bool,
match *substructure.fields {
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
if use_foldl {
do all_fields.iter().fold(base) |old, field| {
all_fields.iter().fold(base, |old, field| {
f(cx, field.span, old, field.self_, field.other)
}
})
} else {
do all_fields.rev_iter().fold(base) |old, field| {
all_fields.rev_iter().fold(base, |old, field| {
f(cx, field.span, old, field.self_, field.other)
}
})
}
},
EnumNonMatching(ref all_enums) => enum_nonmatch_f(cx, trait_span,
@ -1113,12 +1113,12 @@ pub fn cs_same_method(f: |@ExtCtxt, Span, ~[@Expr]| -> @Expr,
match *substructure.fields {
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
// call self_n.method(other_1_n, other_2_n, ...)
let called = do all_fields.map |field| {
let called = all_fields.map(|field| {
cx.expr_method_call(field.span,
field.self_,
substructure.method_ident,
field.other.clone())
};
});
f(cx, trait_span, called)
},
@ -1148,13 +1148,13 @@ pub fn cs_same_method_fold(use_foldl: bool,
cs_same_method(
|cx, span, vals| {
if use_foldl {
do vals.iter().fold(base) |old, &new| {
vals.iter().fold(base, |old, &new| {
f(cx, span, old, new)
}
})
} else {
do vals.rev_iter().fold(base) |old, &new| {
vals.rev_iter().fold(base, |old, &new| {
f(cx, span, old, new)
}
})
}
},
enum_nonmatch_f,

View file

@ -90,7 +90,7 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @
cx.span_bug(span, "#[deriving(IterBytes)] needs at least one field");
}
do exprs.slice(1, exprs.len()).iter().fold(exprs[0]) |prev, me| {
exprs.slice(1, exprs.len()).iter().fold(exprs[0], |prev, me| {
cx.expr_binary(span, BiAnd, prev, *me)
}
})
}

View file

@ -74,7 +74,7 @@ pub fn expand_meta_deriving(cx: @ExtCtxt,
in_items
}
MetaList(_, ref titems) => {
do titems.rev_iter().fold(in_items) |in_items, &titem| {
titems.rev_iter().fold(in_items, |in_items, &titem| {
match titem.node {
MetaNameValue(tname, _) |
MetaList(tname, _) |
@ -112,7 +112,7 @@ pub fn expand_meta_deriving(cx: @ExtCtxt,
}
}
}
}
})
}
}
}

View file

@ -104,7 +104,7 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
value_ref,
variant_count);
let mut arms = do variants.iter().enumerate().map |(i, id_sum)| {
let mut arms = variants.iter().enumerate().map(|(i, id_sum)| {
let i_expr = cx.expr_uint(span, i);
let pat = cx.pat_lit(span, i_expr);
@ -115,7 +115,7 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
rand_thing(cx, span, ident, summary, |sp| rand_call(sp)))
}
}
}.collect::<~[ast::Arm]>();
}).collect::<~[ast::Arm]>();
// _ => {} at the end. Should never occur
arms.push(cx.arm_unreachable(span));
@ -144,9 +144,9 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
}
}
Named(ref fields) => {
let rand_fields = do fields.map |&(ident, span)| {
let rand_fields = fields.map(|&(ident, span)| {
cx.field_imm(span, ident, rand_call(span))
};
});
cx.expr_struct_ident(span, ctor_ident, rand_fields)
}
}

View file

@ -171,9 +171,9 @@ impl<'self> Ty<'self> {
-> ast::Path {
match *self {
Self => {
let self_params = do self_generics.ty_params.map |ty_param| {
let self_params = self_generics.ty_params.map(|ty_param| {
cx.ty_ident(span, ty_param.ident)
};
});
let lifetimes = self_generics.lifetimes.clone();
cx.path_all(span, false, ~[self_ty], lifetimes,
@ -192,10 +192,10 @@ impl<'self> Ty<'self> {
fn mk_ty_param(cx: @ExtCtxt, span: Span, name: &str, bounds: &[Path],
self_ident: Ident, self_generics: &Generics) -> ast::TyParam {
let bounds = opt_vec::from(
do bounds.map |b| {
bounds.map(|b| {
let path = b.to_path(cx, span, self_ident, self_generics);
cx.typarambound(path)
});
}));
cx.typaram(cx.ident_of(name), bounds)
}
@ -224,16 +224,16 @@ impl<'self> LifetimeBounds<'self> {
self_ty: Ident,
self_generics: &Generics)
-> Generics {
let lifetimes = do self.lifetimes.map |lt| {
let lifetimes = self.lifetimes.map(|lt| {
cx.lifetime(span, cx.ident_of(*lt))
};
let ty_params = do self.bounds.map |t| {
});
let ty_params = self.bounds.map(|t| {
match t {
&(ref name, ref bounds) => {
mk_ty_param(cx, span, *name, *bounds, self_ty, self_generics)
}
}
};
});
mk_generics(lifetimes, ty_params)
}
}

View file

@ -76,9 +76,9 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
}
}
Named(ref fields) => {
let zero_fields = do fields.map |&(ident, span)| {
let zero_fields = fields.map(|&(ident, span)| {
cx.field_imm(span, ident, zero_call(span))
};
});
cx.expr_struct_ident(span, substr.type_ident, zero_fields)
}
}

View file

@ -261,8 +261,8 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
// For each item, look through the attributes. If any of them are
// decorated with "item decorators", then use that function to transform
// the item into a new set of items.
let new_items = do vec::flat_map(module_.items) |item| {
do item.attrs.rev_iter().fold(~[*item]) |items, attr| {
let new_items = vec::flat_map(module_.items, |item| {
item.attrs.rev_iter().fold(~[*item], |items, attr| {
let mname = attr.name();
match (*extsbox).find(&intern(mname)) {
@ -280,8 +280,8 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
},
_ => items,
}
}
};
})
});
ast::_mod {
items: new_items,

View file

@ -742,12 +742,12 @@ pub fn expand_args(ecx: @ExtCtxt, sp: Span,
"format argument must be a string literal.");
let mut err = false;
do parse::parse_error::cond.trap(|m| {
parse::parse_error::cond.trap(|m| {
if !err {
err = true;
ecx.span_err(efmt.span, m);
}
}).inside {
}).inside(|| {
for piece in parse::Parser::new(fmt) {
if !err {
cx.verify_piece(&piece);
@ -755,7 +755,7 @@ pub fn expand_args(ecx: @ExtCtxt, sp: Span,
cx.pieces.push(piece);
}
}
}
});
if err { return MRExpr(efmt) }
// Make sure that all arguments were used and all arguments have types.

View file

@ -127,12 +127,12 @@ pub fn copy_up(mpu: &matcher_pos_up) -> ~MatcherPos {
}
pub fn count_names(ms: &[matcher]) -> uint {
do ms.iter().fold(0) |ct, m| {
ms.iter().fold(0, |ct, m| {
ct + match m.node {
match_tok(_) => 0u,
match_seq(ref more_ms, _, _, _, _) => count_names((*more_ms)),
match_nonterminal(_,_,_) => 1u
}}
}})
}
pub fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: BytePos)
@ -416,9 +416,9 @@ pub fn parse(
}
cur_eis.push(ei);
do rust_parser.tokens_consumed.times() || {
rdr.next_token();
}
rust_parser.tokens_consumed.times(|| {
let _ = rdr.next_token();
});
}
}

View file

@ -151,10 +151,10 @@ fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis {
}
match *t {
tt_delim(ref tts) | tt_seq(_, ref tts, _, _) => {
do tts.iter().fold(lis_unconstrained) |lis, tt| {
tts.iter().fold(lis_unconstrained, |lis, tt| {
let lis2 = lockstep_iter_size(tt, r);
lis_merge(lis, lis2)
}
})
}
tt_tok(*) => lis_unconstrained,
tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) {