From 72868450df54ff1ec80e92e3f2fc827cfb1e9f02 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 8 May 2013 12:26:34 -0700 Subject: [PATCH] libcore: Fix more merge fallout. --- src/libcore/rt/local_services.rs | 4 ++-- src/libsyntax/ext/build.rs | 18 ++++++++++++++++++ src/libsyntax/ext/deriving/rand.rs | 15 ++++++++++----- src/libsyntax/fold.rs | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/libcore/rt/local_services.rs b/src/libcore/rt/local_services.rs index b83e1d24648..5ca7a72e84e 100644 --- a/src/libcore/rt/local_services.rs +++ b/src/libcore/rt/local_services.rs @@ -225,8 +225,8 @@ mod test { fn rng() { do run_in_newsched_task() { use rand::{rng, Rng}; - let r = rng(); + let mut r = rng(); let _ = r.next(); } } -} \ No newline at end of file +} diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c1163fda844..3097cb799a2 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -11,6 +11,7 @@ use ast; use codemap; use codemap::span; +use fold; use ext::base::ext_ctxt; use ext::build; @@ -516,3 +517,20 @@ pub fn mk_unreachable(cx: @ext_ctxt, span: span) -> @ast::expr { pub fn mk_unreachable_arm(cx: @ext_ctxt, span: span) -> ast::arm { mk_arm(cx, span, ~[mk_pat_wild(cx, span)], mk_unreachable(cx, span)) } + +// +// Duplication functions +// +// These functions just duplicate AST nodes. +// + +pub fn duplicate_expr(cx: @ext_ctxt, expr: @ast::expr) -> @ast::expr { + let folder = fold::default_ast_fold(); + let folder = @fold::AstFoldFns { + new_id: |_| cx.next_id(), + ..*folder + }; + let folder = fold::make_fold(folder); + folder.fold_expr(expr) +} + diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 03202801d20..604686f442f 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -35,7 +35,7 @@ pub fn expand_deriving_rand(cx: @ext_ctxt, self_ty: None, args: ~[ Ptr(~Literal(Path::new_local(~"R")), - Borrowed(None, ast::m_imm)) + Borrowed(None, ast::m_mutbl)) ], ret_ty: Self, const_nonmatching: false, @@ -59,8 +59,10 @@ fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr cx.ident_of(~"rand") ]; let rand_call = || { - build::mk_call_global(cx, span, - copy rand_ident, copy rng) + build::mk_call_global(cx, + span, + copy rand_ident, + ~[ build::duplicate_expr(cx, rng[0]) ]) }; return match *substr.fields { @@ -80,7 +82,10 @@ fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr let rand_name = build::mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); let rand_name = build::mk_path_raw(cx, span, rand_name); - let rv_call = build::mk_call_(cx, span, rand_name, copy rng); + let rv_call = build::mk_call_(cx, + span, + rand_name, + ~[ build::duplicate_expr(cx, rng[0]) ]); // rand() % variants.len() let rand_variant = build::mk_binary(cx, span, ast::rem, @@ -133,4 +138,4 @@ fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr } } } -} \ No newline at end of file +} diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 229a8664d0c..d181dd87e38 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -859,3 +859,4 @@ impl AstFoldExtensions for @ast_fold { pub fn make_fold(afp: ast_fold_fns) -> @ast_fold { afp as @ast_fold } +