libsyntax -- fix unsafe sharing in closures

This commit is contained in:
Niko Matsakis 2014-02-09 07:37:33 -05:00
parent c7560387af
commit 56c5d4cec3
3 changed files with 12 additions and 10 deletions

View File

@ -580,10 +580,12 @@ impl<'a> MethodDef<'a> {
ast::SelfStatic => None,
_ => Some(ast::Arg::new_self(trait_.span, ast::MutImmutable))
};
let args = arg_types.move_iter().map(|(name, ty)| {
cx.arg(trait_.span, name, ty)
});
let args = self_arg.move_iter().chain(args).collect();
let args = {
let args = arg_types.move_iter().map(|(name, ty)| {
cx.arg(trait_.span, name, ty)
});
self_arg.move_iter().chain(args).collect()
};
let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident);

View File

@ -60,7 +60,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
cx.ident_of("Rand"),
cx.ident_of("rand")
];
let rand_call = |span| {
let rand_call = |cx: &mut ExtCtxt, span| {
cx.expr_call_global(span,
rand_ident.clone(),
~[ rng[0] ])
@ -111,7 +111,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
let i_expr = cx.expr_uint(v_span, i);
let pat = cx.pat_lit(v_span, i_expr);
let thing = rand_thing(cx, v_span, ident, summary, |sp| rand_call(sp));
let thing = rand_thing(cx, v_span, ident, summary, |cx, sp| rand_call(cx, sp));
cx.arm(v_span, ~[ pat ], thing)
}).collect::<~[ast::Arm]>();
@ -130,20 +130,21 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
trait_span: Span,
ctor_ident: Ident,
summary: &StaticFields,
rand_call: |Span| -> @Expr)
rand_call: |&mut ExtCtxt, Span| -> @Expr)
-> @Expr {
match *summary {
Unnamed(ref fields) => {
if fields.is_empty() {
cx.expr_ident(trait_span, ctor_ident)
} else {
let exprs = fields.map(|span| rand_call(*span));
let exprs = fields.map(|span| rand_call(cx, *span));
cx.expr_call_ident(trait_span, ctor_ident, exprs)
}
}
Named(ref fields) => {
let rand_fields = fields.map(|&(ident, span)| {
cx.field_imm(span, ident, rand_call(span))
let e = rand_call(cx, span);
cx.field_imm(span, ident, e)
});
cx.expr_struct_ident(trait_span, ctor_ident, rand_fields)
}

View File

@ -21,7 +21,6 @@ use rsparse = parse;
use std::fmt::parse;
use std::hashmap::{HashMap, HashSet};
use std::vec;
use std::cell::RefCell;
#[deriving(Eq)]
enum ArgumentType {