let mut res = None;
- do each_abi |abi| {
+ each_abi(|abi| {
if name == abi.data().name {
res = Some(abi);
false
} else {
true
}
- };
+ });
res
}
let mut res = None;
- do self.each |abi| {
+ self.each(|abi| {
let data = abi.data();
match data.abi_arch {
Archs(a) if (a & arch.bit()) != 0 => { res = Some(abi); false }
Archs(_) => { true }
RustArch | AllArch => { res = Some(abi); false }
}
- };
+ });
res.map(|r| r.for_target(os, arch))
}
pub fn check_valid(&self) -> Option<(Abi, Abi)> {
let mut abis = ~[];
- do self.each |abi| { abis.push(abi); true };
+ self.each(|abi| { abis.push(abi); true });
for (i, abi) in abis.iter().enumerate() {
let data = abi.data();
impl ToStr for AbiSet {
fn to_str(&self) -> ~str {
let mut strs = ~[];
- do self.each |abi| {
+ self.each(|abi| {
strs.push(abi.data().name);
true
- };
+ });
format!("\"{}\"", strs.connect(" "))
}
}
pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner)
-> ~str {
- let strs = do p.map |e| {
+ let strs = p.map(|e| {
match *e {
path_mod(s) | path_name(s) | path_pretty_name(s, _) => {
itr.get(s.name)
}
}
- };
+ });
strs.connect(sep)
}
}
pub fn public_methods(ms: ~[@method]) -> ~[@method] {
- do ms.move_iter().filter |m| {
+ ms.move_iter().filter(|m| {
match m.vis {
public => true,
_ => false
}
- }.collect()
+ }).collect()
}
// extract a TypeMethod from a trait_method. if the trait_method is
pub fn contains(haystack: &[@ast::MetaItem],
needle: @ast::MetaItem) -> bool {
debug!("attr::contains (name={})", needle.name());
- do haystack.iter().any |item| {
+ haystack.iter().any(|item| {
debug!(" testing: {}", item.name());
item.node == needle.node
- }
+ })
}
pub fn contains_name<AM: AttrMetaMethods>(metas: &[AM], name: &str) -> bool {
debug!("attr::contains_name (name={})", name);
- do metas.iter().any |item| {
+ metas.iter().any(|item| {
debug!(" testing: {}", item.name());
name == item.name()
- }
+ })
}
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str)
.map(|&mi| (mi.name(), mi))
.collect::<~[(@str, @MetaItem)]>();
- do extra::sort::quick_sort(v) |&(a, _), &(b, _)| {
- a <= b
- }
+ extra::sort::quick_sort(v, |&(a, _), &(b, _)| a <= b);
// There doesn't seem to be a more optimal way to do this
- do v.move_iter().map |(_, m)| {
+ v.move_iter().map(|(_, m)| {
match m.node {
MetaList(n, ref mis) => {
@Spanned {
}
_ => m
}
- }.collect()
+ }).collect()
}
/**
/// True if something like #[inline] is found in the list of attrs.
pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr {
// FIXME (#2809)---validate the usage of #[inline] and #[inline]
- do attrs.iter().fold(InlineNone) |ia,attr| {
+ attrs.iter().fold(InlineNone, |ia,attr| {
match attr.node.value.node {
MetaWord(n) if "inline" == n => InlineHint,
MetaList(n, ref items) if "inline" == n => {
}
_ => ia
}
- }
+ })
}
/// Tests if any `cfg(...)` meta items in `metas` match `cfg`. e.g.
// this would be much nicer as a chain of iterator adaptors, but
// this doesn't work.
- let some_cfg_matches = do metas.any |mi| {
+ let some_cfg_matches = metas.any(|mi| {
debug!("testing name: {}", mi.name());
if "cfg" == mi.name() { // it is a #[cfg()] attribute
debug!("is cfg");
match mi.meta_item_list() {
Some(cfg_meta) => {
debug!("is cfg(...)");
- do cfg_meta.iter().all |cfg_mi| {
+ cfg_meta.iter().all(|cfg_mi| {
debug!("cfg({}[...])", cfg_mi.name());
match cfg_mi.node {
ast::MetaList(s, ref not_cfgs) if "not" == s => {
}
_ => contains(cfg, *cfg_mi)
}
- }
+ })
}
None => false
}
} else {
false
}
- };
+ });
debug!("test_cfg (no_cfgs={}, some_cfg_matches={})", no_cfgs, some_cfg_matches);
no_cfgs || some_cfg_matches
}
// Skip is the number of characters we need to skip because they are
// part of the 'filename:line ' part of the previous line.
let skip = fm.name.len() + digits + 3u;
- do skip.times() {
- s.push_char(' ');
- }
+ skip.times(|| s.push_char(' '));
let orig = fm.get_line(lines.lines[0] as int);
for pos in range(0u, left-skip) {
let curChar = (orig[pos] as char);
if hi.col != lo.col {
// the ^ already takes up one space
let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u;
- do num_squigglies.times() {
- s.push_char('~')
- }
+ num_squigglies.times(|| s.push_char('~'));
}
print_maybe_styled(s + "\n", term::attr::ForegroundColor(diagnosticcolor(lvl)));
}
}
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()
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,
},
_ => {
// 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,
name))
};
cx.field_imm(span, ident, subcall(field.self_))
- };
+ });
if fields.is_empty() {
// no fields, so construct like `None`
};
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),
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))],
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)
}
}
}
}
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)
}
}
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))
}
- }
+ })
}
}
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));
- }
+ })
}
}
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)),
}
- }
+ })
}
}
*/
// 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()));
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();
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);
type_ident, generics,
explicit_self, tys,
body)
- };
+ });
self.create_derived_impl(cx, trait_span, type_ident, generics, methods)
}
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);
type_ident, generics,
explicit_self, tys,
body)
- };
+ });
self.create_derived_impl(cx, trait_span, type_ident, generics, methods)
}
// 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);
// 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`") }
}
}
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 => {
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)),
}
};
(ident, summary)
- };
+ });
self.call_substructure_method(cx,
trait_span, type_ident,
self_args, nonself_args,
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!
// 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)
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,
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)
},
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,
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)
- }
+ })
}
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, _) |
}
}
}
- }
+ })
}
}
}
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);
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));
}
}
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)
}
}
-> 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,
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)
}
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)
}
}
}
}
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)
}
}
// 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)) {
},
_ => items,
}
- }
- };
+ })
+ });
ast::_mod {
items: new_items,
"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);
cx.pieces.push(piece);
}
}
- }
+ });
if err { return MRExpr(efmt) }
// Make sure that all arguments were used and all arguments have types.
}
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)
}
cur_eis.push(ei);
- do rust_parser.tokens_consumed.times() || {
- rdr.next_token();
- }
+ rust_parser.tokens_consumed.times(|| {
+ let _ = rdr.next_token();
+ });
}
}
}
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) {
}
PatStruct(ref pth, ref fields, etc) => {
let pth_ = self.fold_path(pth);
- let fs = do fields.map |f| {
+ let fs = fields.map(|f| {
ast::FieldPat {
ident: f.ident,
pat: self.fold_pat(f.pat)
}
- };
+ });
PatStruct(pth_, fs, etc)
}
PatTup(ref elts) => PatTup(elts.map(|x| self.fold_pat(*x))),
// build a new vector of tts by appling the ast_fold's fold_ident to
// all of the identifiers in the token trees.
pub fn fold_tts<T:ast_fold>(tts: &[token_tree], fld: &T) -> ~[token_tree] {
- do tts.map |tt| {
+ tts.map(|tt| {
match *tt {
tt_tok(span, ref tok) =>
tt_tok(span,maybe_fold_ident(tok,fld)),
tt_nonterminal(sp,ref ident) =>
tt_nonterminal(sp,fld.fold_ident(*ident))
}
- }
+ })
}
// apply ident folder if it's an ident, otherwise leave it alone
fn fold_opt_bounds<T:ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &T)
-> Option<OptVec<TyParamBound>> {
- do b.as_ref().map |bounds| {
- do bounds.map |bound| {
+ b.as_ref().map(|bounds| {
+ bounds.map(|bound| {
fold_ty_param_bound(bound, folder)
- }
- }
+ })
+ })
}
fn fold_variant_arg_<T:ast_fold>(va: &variant_arg, folder: &T)
item_enum(ref enum_definition, ref generics) => {
item_enum(
ast::enum_def {
- variants: do enum_definition.variants.map |x| {
+ variants: enum_definition.variants.map(|x| {
folder.fold_variant(x)
- },
+ }),
},
fold_generics(generics, folder))
}
)
}
item_trait(ref generics, ref traits, ref methods) => {
- let methods = do methods.map |method| {
+ let methods = methods.map(|method| {
match *method {
required(ref m) => required(folder.fold_type_method(m)),
provided(method) => provided(folder.fold_method(method))
}
- };
+ });
item_trait(fold_generics(generics, folder),
traits.map(|p| fold_trait_ref(p, folder)),
methods)
}
if can_trim {
- do lines.map |line| {
- line.slice(i + 1, line.len()).to_owned()
- }
+ lines.map(|line| line.slice(i + 1, line.len()).to_owned())
} else {
lines
}
//discard, and look ahead; we're working with internal state
let TokenAndSpan {tok: tok, sp: sp} = rdr.peek();
if token::is_lit(&tok) {
- do with_str_from(rdr, bstart) |s| {
+ with_str_from(rdr, bstart, |s| {
debug!("tok lit: {}", s);
literals.push(lit {lit: s.to_owned(), pos: sp.lo});
- }
+ })
} else {
debug!("tok: {}", token::to_str(get_ident_interner(), &tok));
}
while rdr.curr != '\n' && !is_eof(rdr) {
bump(rdr);
}
- let ret = do with_str_from(rdr, start_bpos) |string| {
+ let ret = with_str_from(rdr, start_bpos, |string| {
// but comments with only more "/"s are not
if !is_line_non_doc_comment(string) {
Some(TokenAndSpan{
} else {
None
}
- };
+ });
if ret.is_some() {
return ret;
}
let res = if is_doc_comment {
- do with_str_from(rdr, start_bpos) |string| {
+ with_str_from(rdr, start_bpos, |string| {
// but comments with only "*"s between two "/"s are not
if !is_block_non_doc_comment(string) {
Some(TokenAndSpan{
} else {
None
}
- }
+ })
} else {
None
};
bump(rdr);
}
- return do with_str_from(rdr, start) |string| {
+ return with_str_from(rdr, start, |string| {
if string == "_" {
token::UNDERSCORE
} else {
// FIXME: perform NFKC normalization here. (Issue #2253)
token::IDENT(str_to_ident(string), is_mod_name)
}
- }
+ })
}
if is_dec_digit(c) {
return scan_number(c, rdr);
while ident_continue(rdr.curr) {
bump(rdr);
}
- return do with_str_from(rdr, start) |lifetime_name| {
+ return with_str_from(rdr, start, |lifetime_name| {
token::LIFETIME(str_to_ident(lifetime_name))
- }
+ })
}
// Otherwise it is a character constant:
// parse the methods in a trait declaration
pub fn parse_trait_methods(&self) -> ~[trait_method] {
- do self.parse_unspanned_seq(
+ self.parse_unspanned_seq(
&token::LBRACE,
&token::RBRACE,
- seq_sep_none()
- ) |p| {
+ seq_sep_none(),
+ |p| {
let attrs = p.parse_outer_attributes();
let lo = p.span.lo;
let generics = p.parse_generics();
- let (explicit_self, d) = do self.parse_fn_decl_with_self() |p| {
+ let (explicit_self, d) = self.parse_fn_decl_with_self(|p| {
// This is somewhat dubious; We don't want to allow argument
// names to be left off if there is a definition...
p.parse_arg_general(false)
- };
+ });
let hi = p.last_span.hi;
debug!("parse_trait_methods(): trait method signature ends in \
);
}
}
- }
+ })
}
// parse a possibly mutable type
let mutbl = self.parse_mutability();
pat = self.parse_pat_ident(BindByRef(mutbl));
} else {
- let can_be_enum_or_struct = do self.look_ahead(1) |t| {
+ let can_be_enum_or_struct = self.look_ahead(1, |t| {
match *t {
token::LPAREN | token::LBRACKET | token::LT |
token::LBRACE | token::MOD_SEP => true,
_ => false,
}
- };
+ });
if self.look_ahead(1, |t| *t == token::DOTDOT) {
let start = self.parse_expr_res(RESTRICT_NO_BAR_OP);
let mut args: ~[@Pat] = ~[];
match *self.token {
token::LPAREN => {
- let is_star = do self.look_ahead(1) |t| {
+ let is_star = self.look_ahead(1, |t| {
match *t {
token::BINOP(token::STAR) => true,
_ => false,
}
- };
- let is_dotdot = do self.look_ahead(1) |t| {
+ });
+ let is_dotdot = self.look_ahead(1, |t| {
match *t {
token::DOTDOT => true,
_ => false,
}
- };
+ });
if is_star | is_dotdot {
// This is a "top constructor only" pat
self.bump();
let pur = self.parse_fn_purity();
let ident = self.parse_ident();
let generics = self.parse_generics();
- let (explicit_self, decl) = do self.parse_fn_decl_with_self() |p| {
+ let (explicit_self, decl) = self.parse_fn_decl_with_self(|p| {
p.parse_arg()
- };
+ });
let (inner_attrs, body) = self.parse_inner_attrs_and_block();
let hi = body.span.hi;
} else if *self.token == token::LPAREN {
// It's a tuple-like struct.
is_tuple_like = true;
- fields = do self.parse_unspanned_seq(
+ fields = self.parse_unspanned_seq(
&token::LPAREN,
&token::RPAREN,
- seq_sep_trailing_allowed(token::COMMA)
- ) |p| {
+ seq_sep_trailing_allowed(token::COMMA),
+ |p| {
let attrs = self.parse_outer_attributes();
let lo = p.span.lo;
let struct_field_ = ast::struct_field_ {
attrs: attrs,
};
@spanned(lo, p.span.hi, struct_field_)
- };
+ });
self.expect(&token::SEMI);
} else if self.eat(&token::SEMI) {
// It's a unit-like struct.
path: Path,
outer_attrs: ~[ast::Attribute],
id_sp: Span) -> (ast::item_, ~[ast::Attribute]) {
- let maybe_i = do self.sess.included_mod_stack.iter().position |p| { *p == path };
+ let maybe_i = self.sess.included_mod_stack.iter().position(|p| *p == path);
match maybe_i {
Some(i) => {
let stack = &self.sess.included_mod_stack;
let mut err = ~"circular modules: ";
for p in stack.slice(i, stack.len()).iter() {
- do p.display().with_str |s| {
- err.push_str(s);
- }
+ p.display().with_str(|s| err.push_str(s));
err.push_str(" -> ");
}
- do path.display().with_str |s| {
- err.push_str(s);
- }
+ path.display().with_str(|s| err.push_str(s));
self.span_fatal(id_sp, err);
}
None => ()
/* Literals */
LIT_CHAR(c) => {
let mut res = ~"'";
- do char::from_u32(c).unwrap().escape_default |c| {
+ char::from_u32(c).unwrap().escape_default(|c| {
res.push_char(c);
- }
+ });
res.push_char('\'');
res
}
if ast_util::struct_def_is_tuple_like(struct_def) {
if !struct_def.fields.is_empty() {
popen(s);
- do commasep(s, inconsistent, struct_def.fields) |s, field| {
+ commasep(s, inconsistent, struct_def.fields, |s, field| {
match field.node.kind {
ast::named_field(*) => fail!("unexpected named field"),
ast::unnamed_field => {
print_type(s, &field.node.ty);
}
}
- }
+ });
pclose(s);
}
word(s.s, ";");
}
ast::PatVec(ref before, slice, ref after) => {
word(s.s, "[");
- do commasep(s, inconsistent, *before) |s, &p| {
- print_pat(s, p);
- }
+ commasep(s, inconsistent, *before, |s, &p| print_pat(s, p));
for &p in slice.iter() {
if !before.is_empty() { word_space(s, ","); }
match p {
print_pat(s, p);
if !after.is_empty() { word_space(s, ","); }
}
- do commasep(s, inconsistent, *after) |s, &p| {
- print_pat(s, p);
- }
+ commasep(s, inconsistent, *after, |s, &p| print_pat(s, p));
word(s.s, "]");
}
}
ast::view_path_list(ref path, ref idents, _) => {
print_path(s, path, false);
word(s.s, "::{");
- do commasep(s, inconsistent, (*idents)) |s, w| {
+ commasep(s, inconsistent, (*idents), |s, w| {
print_ident(s, w.node.name);
- }
+ });
word(s.s, "}");
}
}
match id { Some(id) => { word(s.s, " "); print_ident(s, id); } _ => () }
if opt_sigil != Some(ast::BorrowedSigil) {
- do opt_bounds.as_ref().map |bounds| {
- print_bounds(s, bounds, true);
- };
+ opt_bounds.as_ref().map(|bounds| print_bounds(s, bounds, true));
}
match generics { Some(g) => print_generics(s, g), _ => () }
ast::lit_str(st, style) => print_string(s, st, style),
ast::lit_char(ch) => {
let mut res = ~"'";
- do char::from_u32(ch).unwrap().escape_default |c| {
- res.push_char(c);
- }
+ char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c));
res.push_char('\'');
word(s.s, res);
}