Skip to content

Commit c83bced

Browse files
committed
auto merge of #7121 : huonw/rust/rand-call, r=pnkfelix
r? @pnkfelix
2 parents 1ba6fa4 + 8431e60 commit c83bced

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/libsyntax/ext/deriving/rand.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,19 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
7979
let variant_count = cx.expr_uint(span, variants.len());
8080

8181
// need to specify the uint-ness of the random number
82-
let u32_ty = cx.ty_ident(span, cx.ident_of("uint"));
82+
let uint_ty = cx.ty_ident(span, cx.ident_of("uint"));
8383
let r_ty = cx.ty_ident(span, cx.ident_of("R"));
84-
let rand_name = cx.path_all(span, false, copy rand_ident, None, ~[ u32_ty, r_ty ]);
84+
let rand_name = cx.path_all(span, true, copy rand_ident, None, ~[ uint_ty, r_ty ]);
8585
let rand_name = cx.expr_path(rand_name);
8686

87+
// ::std::rand::Rand::rand::<uint>(rng)
8788
let rv_call = cx.expr_call(span,
8889
rand_name,
8990
~[ rng[0].duplicate(cx) ]);
9091

9192
// rand() % variants.len()
9293
let rand_variant = cx.expr_binary(span, ast::rem,
93-
rv_call, variant_count);
94+
rv_call, variant_count);
9495

9596
let mut arms = do variants.mapi |i, id_sum| {
9697
let i_expr = cx.expr_uint(span, i);

src/test/run-pass/deriving-global.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// xfail-test #7103 `extern mod` does not work on windows
2+
3+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
4+
// file at the top-level directory of this distribution and at
5+
// http://rust-lang.org/COPYRIGHT.
6+
//
7+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
// option. This file may not be copied, modified, or distributed
11+
// except according to those terms.
12+
13+
extern mod extra; // {En,De}codable
14+
mod submod {
15+
// if any of these are implemented without global calls for any
16+
// function calls, then being in a submodule will (correctly)
17+
// cause errors about unrecognised module `std` (or `extra`)
18+
#[deriving(Eq, Ord, TotalEq, TotalOrd,
19+
IterBytes,
20+
Clone, DeepClone,
21+
ToStr, Rand,
22+
Encodable, Decodable)]
23+
enum A { A1(uint), A2(int) }
24+
25+
#[deriving(Eq, Ord, TotalEq, TotalOrd,
26+
IterBytes,
27+
Clone, DeepClone,
28+
ToStr, Rand,
29+
Encodable, Decodable)]
30+
struct B { x: uint, y: int }
31+
32+
#[deriving(Eq, Ord, TotalEq, TotalOrd,
33+
IterBytes,
34+
Clone, DeepClone,
35+
ToStr, Rand,
36+
Encodable, Decodable)]
37+
struct C(uint, int);
38+
39+
}
40+
41+
fn main() {}

0 commit comments

Comments
 (0)