1
Fork 0

use slicing sugar

This commit is contained in:
Jorge Aparicio 2015-01-07 11:58:31 -05:00
parent 6e2bfe4ae8
commit 517f1cc63c
198 changed files with 2383 additions and 2405 deletions

View file

@ -510,15 +510,15 @@ impl<'a> TraitDef<'a> {
self,
struct_def,
type_ident,
self_args.index(&FullRange),
nonself_args.index(&FullRange))
&self_args[],
&nonself_args[])
} else {
method_def.expand_struct_method_body(cx,
self,
struct_def,
type_ident,
self_args.index(&FullRange),
nonself_args.index(&FullRange))
&self_args[],
&nonself_args[])
};
method_def.create_method(cx,
@ -550,15 +550,15 @@ impl<'a> TraitDef<'a> {
self,
enum_def,
type_ident,
self_args.index(&FullRange),
nonself_args.index(&FullRange))
&self_args[],
&nonself_args[])
} else {
method_def.expand_enum_method_body(cx,
self,
enum_def,
type_ident,
self_args,
nonself_args.index(&FullRange))
&nonself_args[])
};
method_def.create_method(cx,
@ -645,7 +645,7 @@ impl<'a> MethodDef<'a> {
for (i, ty) in self.args.iter().enumerate() {
let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics);
let ident = cx.ident_of(format!("__arg_{}", i).index(&FullRange));
let ident = cx.ident_of(&format!("__arg_{}", i)[]);
arg_tys.push((ident, ast_ty));
let arg_expr = cx.expr_ident(trait_.span, ident);
@ -751,8 +751,8 @@ impl<'a> MethodDef<'a> {
trait_.create_struct_pattern(cx,
struct_path,
struct_def,
format!("__self_{}",
i).index(&FullRange),
&format!("__self_{}",
i)[],
ast::MutImmutable);
patterns.push(pat);
raw_fields.push(ident_expr);
@ -908,22 +908,22 @@ impl<'a> MethodDef<'a> {
.collect::<Vec<String>>();
let self_arg_idents = self_arg_names.iter()
.map(|name|cx.ident_of(name.index(&FullRange)))
.map(|name|cx.ident_of(&name[]))
.collect::<Vec<ast::Ident>>();
// The `vi_idents` will be bound, solely in the catch-all, to
// a series of let statements mapping each self_arg to a uint
// corresponding to its variant index.
let vi_idents: Vec<ast::Ident> = self_arg_names.iter()
.map(|name| { let vi_suffix = format!("{}_vi", name.index(&FullRange));
cx.ident_of(vi_suffix.index(&FullRange)) })
.map(|name| { let vi_suffix = format!("{}_vi", &name[]);
cx.ident_of(&vi_suffix[]) })
.collect::<Vec<ast::Ident>>();
// Builds, via callback to call_substructure_method, the
// delegated expression that handles the catch-all case,
// using `__variants_tuple` to drive logic if necessary.
let catch_all_substructure = EnumNonMatchingCollapsed(
self_arg_idents, variants.index(&FullRange), vi_idents.index(&FullRange));
self_arg_idents, &variants[], &vi_idents[]);
// These arms are of the form:
// (Variant1, Variant1, ...) => Body1
@ -945,12 +945,12 @@ impl<'a> MethodDef<'a> {
let mut subpats = Vec::with_capacity(self_arg_names.len());
let mut self_pats_idents = Vec::with_capacity(self_arg_names.len() - 1);
let first_self_pat_idents = {
let (p, idents) = mk_self_pat(cx, self_arg_names[0].index(&FullRange));
let (p, idents) = mk_self_pat(cx, &self_arg_names[0][]);
subpats.push(p);
idents
};
for self_arg_name in self_arg_names.tail().iter() {
let (p, idents) = mk_self_pat(cx, self_arg_name.index(&FullRange));
let (p, idents) = mk_self_pat(cx, &self_arg_name[]);
subpats.push(p);
self_pats_idents.push(idents);
}
@ -1006,7 +1006,7 @@ impl<'a> MethodDef<'a> {
&**variant,
field_tuples);
let arm_expr = self.call_substructure_method(
cx, trait_, type_ident, self_args.index(&FullRange), nonself_args,
cx, trait_, type_ident, &self_args[], nonself_args,
&substructure);
cx.arm(sp, vec![single_pat], arm_expr)
@ -1059,7 +1059,7 @@ impl<'a> MethodDef<'a> {
}
let arm_expr = self.call_substructure_method(
cx, trait_, type_ident, self_args.index(&FullRange), nonself_args,
cx, trait_, type_ident, &self_args[], nonself_args,
&catch_all_substructure);
// Builds the expression:
@ -1263,7 +1263,7 @@ impl<'a> TraitDef<'a> {
cx.span_bug(sp, "a struct with named and unnamed fields in `derive`");
}
};
let ident = cx.ident_of(format!("{}_{}", prefix, i).index(&FullRange));
let ident = cx.ident_of(&format!("{}_{}", prefix, i)[]);
paths.push(codemap::Spanned{span: sp, node: ident});
let val = cx.expr(
sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident)))));
@ -1309,7 +1309,7 @@ impl<'a> TraitDef<'a> {
let mut ident_expr = Vec::new();
for (i, va) in variant_args.iter().enumerate() {
let sp = self.set_expn_info(cx, va.ty.span);
let ident = cx.ident_of(format!("{}_{}", prefix, i).index(&FullRange));
let ident = cx.ident_of(&format!("{}_{}", prefix, i)[]);
let path1 = codemap::Spanned{span: sp, node: ident};
paths.push(path1);
let expr_path = cx.expr_path(cx.path_ident(sp, ident));
@ -1352,7 +1352,7 @@ pub fn cs_fold<F>(use_foldl: bool,
field.span,
old,
field.self_.clone(),
field.other.index(&FullRange))
&field.other[])
})
} else {
all_fields.iter().rev().fold(base, |old, field| {
@ -1360,12 +1360,12 @@ pub fn cs_fold<F>(use_foldl: bool,
field.span,
old,
field.self_.clone(),
field.other.index(&FullRange))
&field.other[])
})
}
},
EnumNonMatchingCollapsed(ref all_args, _, tuple) =>
enum_nonmatch_f(cx, trait_span, (all_args.index(&FullRange), tuple),
enum_nonmatch_f(cx, trait_span, (&all_args[], tuple),
substructure.nonself_args),
StaticEnum(..) | StaticStruct(..) => {
cx.span_bug(trait_span, "static function in `derive`")
@ -1405,7 +1405,7 @@ pub fn cs_same_method<F>(f: F,
f(cx, trait_span, called)
},
EnumNonMatchingCollapsed(ref all_self_args, _, tuple) =>
enum_nonmatch_f(cx, trait_span, (all_self_args.index(&FullRange), tuple),
enum_nonmatch_f(cx, trait_span, (&all_self_args[], tuple),
substructure.nonself_args),
StaticEnum(..) | StaticStruct(..) => {
cx.span_bug(trait_span, "static function in `derive`")