Navigation Menu

Skip to content

Commit

Permalink
libsyntax -- fix unsafe sharing in closures
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Feb 11, 2014
1 parent c756038 commit 56c5d4c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/libsyntax/ext/deriving/generic.rs
Expand Up @@ -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);

Expand Down
11 changes: 6 additions & 5 deletions src/libsyntax/ext/deriving/rand.rs
Expand Up @@ -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] ])
Expand Down Expand Up @@ -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]>();

Expand All @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/format.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit 56c5d4c

Please sign in to comment.