diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-05-08 12:26:34 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-05-08 17:04:03 -0700 |
| commit | 72868450df54ff1ec80e92e3f2fc827cfb1e9f02 (patch) | |
| tree | 7d827575b36c5cab6efd869d2138e4386f43de0f /src/libsyntax | |
| parent | 3affc6ed4071a183da81bcc2048fff82d3e35e81 (diff) | |
| download | rust-72868450df54ff1ec80e92e3f2fc827cfb1e9f02.tar.gz rust-72868450df54ff1ec80e92e3f2fc827cfb1e9f02.zip | |
libcore: Fix more merge fallout.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/build.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/rand.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 |
3 files changed, 29 insertions, 5 deletions
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 } + |
