From f93a974558bf09bee475427158150ba6e008cdd8 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 13 Jun 2013 23:16:30 +1000 Subject: syntax: correct the Rand::rand call to select enum variants in #[deriving(Rand)]. Previously, this was not a global call, and so when `#[deriving(Rand)]` was in any module other than the top-level one, it failed (unless there was a `use std;` in scope). Also, fix a minor inconsistency between uints and u32s for this piece of code. --- src/libsyntax/ext/deriving/rand.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index ab5ac6d7847..79aa3469f74 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -78,19 +78,20 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { let variant_count = cx.expr_uint(span, variants.len()); - // need to specify the uint-ness of the random number - let u32_ty = cx.ty_ident(span, cx.ident_of("uint")); + // need to specify the u32-ness of the random number + let u32_ty = cx.ty_ident(span, cx.ident_of("u32")); let r_ty = cx.ty_ident(span, cx.ident_of("R")); - let rand_name = cx.path_all(span, false, copy rand_ident, None, ~[ u32_ty, r_ty ]); + let rand_name = cx.path_all(span, true, copy rand_ident, None, ~[ u32_ty, r_ty ]); let rand_name = cx.expr_path(rand_name); + // ::std::rand::Rand::rand::(rng) let rv_call = cx.expr_call(span, rand_name, ~[ rng[0].duplicate(cx) ]); // rand() % variants.len() let rand_variant = cx.expr_binary(span, ast::rem, - rv_call, variant_count); + rv_call, variant_count); let mut arms = do variants.mapi |i, id_sum| { let i_expr = cx.expr_uint(span, i); -- cgit 1.4.1-3-g733a5 From e6c3e4a000557580e75464f843714bd34ae00c99 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 14 Jun 2013 00:35:06 +1000 Subject: syntax: revert the uint -> u32 "fix"; make the names/comment match. --- src/libsyntax/ext/deriving/rand.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 79aa3469f74..b890623b963 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -78,13 +78,13 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { let variant_count = cx.expr_uint(span, variants.len()); - // need to specify the u32-ness of the random number - let u32_ty = cx.ty_ident(span, cx.ident_of("u32")); + // need to specify the uint-ness of the random number + let uint_ty = cx.ty_ident(span, cx.ident_of("uint")); let r_ty = cx.ty_ident(span, cx.ident_of("R")); - let rand_name = cx.path_all(span, true, copy rand_ident, None, ~[ u32_ty, r_ty ]); + let rand_name = cx.path_all(span, true, copy rand_ident, None, ~[ uint_ty, r_ty ]); let rand_name = cx.expr_path(rand_name); - // ::std::rand::Rand::rand::(rng) + // ::std::rand::Rand::rand::(rng) let rv_call = cx.expr_call(span, rand_name, ~[ rng[0].duplicate(cx) ]); -- cgit 1.4.1-3-g733a5