Skip to content

Commit 6c12d84

Browse files
committed
---
yaml --- r: 144950 b: refs/heads/try2 c: d14bd08 h: refs/heads/master v: v3
1 parent 5489965 commit 6c12d84

File tree

15 files changed

+454
-795
lines changed

15 files changed

+454
-795
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ad43613346a5702b84e3a32b39395258e32b1037
8+
refs/heads/try2: d14bd0879d7357598f4f7f49dae6661559e10745
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/num/bigint.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2323
use std::int;
2424
use std::num;
2525
use std::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
26+
use std::rand::{Rng, RngUtil};
2627
use std::str;
2728
use std::uint;
2829
use std::vec;
@@ -1088,6 +1089,53 @@ impl FromStrRadix for BigInt {
10881089
}
10891090
}
10901091
1092+
trait RandBigInt {
1093+
/// Generate a random BigUint of the given bit size.
1094+
fn gen_biguint(&mut self, bit_size: uint) -> BigUint;
1095+
1096+
/// Generate a random BigInt of the given bit size.
1097+
fn gen_bigint(&mut self, bit_size: uint) -> BigInt;
1098+
}
1099+
1100+
impl<R: Rng> RandBigInt for R {
1101+
/// Generate a random BigUint of the given bit size.
1102+
fn gen_biguint(&mut self, bit_size: uint) -> BigUint {
1103+
let (digits, rem) = bit_size.div_rem(&BigDigit::bits);
1104+
let mut data = vec::with_capacity(digits+1);
1105+
for _ in range(0, digits) {
1106+
data.push(self.gen());
1107+
}
1108+
if rem > 0 {
1109+
let final_digit: BigDigit = self.gen();
1110+
data.push(final_digit >> (BigDigit::bits - rem));
1111+
}
1112+
return BigUint::new(data);
1113+
}
1114+
1115+
/// Generate a random BigInt of the given bit size.
1116+
fn gen_bigint(&mut self, bit_size: uint) -> BigInt {
1117+
// Generate a random BigUint...
1118+
let biguint = self.gen_biguint(bit_size);
1119+
// ...and then randomly assign it a Sign...
1120+
let sign = if biguint.is_zero() {
1121+
// ...except that if the BigUint is zero, we need to try
1122+
// again with probability 0.5. This is because otherwise,
1123+
// the probability of generating a zero BigInt would be
1124+
// double that of any other number.
1125+
if self.gen() {
1126+
return self.gen_bigint(bit_size);
1127+
} else {
1128+
Zero
1129+
}
1130+
} else if self.gen() {
1131+
Plus
1132+
} else {
1133+
Minus
1134+
};
1135+
return BigInt::from_biguint(sign, biguint);
1136+
}
1137+
}
1138+
10911139
impl BigInt {
10921140
/// Creates and initializes an BigInt.
10931141
#[inline]
@@ -1149,6 +1197,7 @@ mod biguint_tests {
11491197
use std::cmp::{Less, Equal, Greater};
11501198
use std::int;
11511199
use std::num::{IntConvertible, Zero, One, FromStrRadix};
1200+
use std::rand::{task_rng};
11521201
use std::str;
11531202
use std::uint;
11541203
use std::vec;
@@ -1656,6 +1705,13 @@ mod biguint_tests {
16561705
check(20, "2432902008176640000");
16571706
check(30, "265252859812191058636308480000000");
16581707
}
1708+
1709+
#[test]
1710+
fn test_rand() {
1711+
let mut rng = task_rng();
1712+
let _n: BigUint = rng.gen_biguint(137);
1713+
assert!(rng.gen_biguint(0).is_zero());
1714+
}
16591715
}
16601716

16611717
#[cfg(test)]
@@ -1665,6 +1721,7 @@ mod bigint_tests {
16651721
use std::cmp::{Less, Equal, Greater};
16661722
use std::int;
16671723
use std::num::{IntConvertible, Zero, One, FromStrRadix};
1724+
use std::rand::{task_rng};
16681725
use std::uint;
16691726

16701727
#[test]
@@ -2085,6 +2142,13 @@ mod bigint_tests {
20852142
let zero: BigInt = Zero::zero();
20862143
assert_eq!(-zero, zero);
20872144
}
2145+
2146+
#[test]
2147+
fn test_rand() {
2148+
let mut rng = task_rng();
2149+
let _n: BigInt = rng.gen_bigint(137);
2150+
assert!(rng.gen_bigint(0).is_zero());
2151+
}
20882152
}
20892153

20902154
#[cfg(test)]

branches/try2/src/librustc/middle/effect.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ impl Visitor<()> for EffectCheckVisitor {
102102
fn visit_block(&mut self, block:&Block, _:()) {
103103

104104
let old_unsafe_context = self.context.unsafe_context;
105-
if block.rules == ast::UnsafeBlock &&
106-
self.context.unsafe_context == SafeContext {
105+
let is_unsafe = match block.rules {
106+
ast::UnsafeBlock(*) => true, ast::DefaultBlock => false
107+
};
108+
if is_unsafe && self.context.unsafe_context == SafeContext {
107109
self.context.unsafe_context = UnsafeBlock(block.id)
108110
}
109111

branches/try2/src/librustc/middle/lint.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,11 @@ impl Visitor<@mut Context> for UnusedUnsafeLintVisitor {
11311131
fn visit_expr(&mut self, e:@ast::Expr, cx:@mut Context) {
11321132

11331133
match e.node {
1134-
ast::ExprBlock(ref blk) if blk.rules == ast::UnsafeBlock => {
1135-
if !cx.tcx.used_unsafe.contains(&blk.id) {
1134+
// Don't warn about generated blocks, that'll just pollute the
1135+
// output.
1136+
ast::ExprBlock(ref blk) => {
1137+
if blk.rules == ast::UnsafeBlock(ast::UserProvided) &&
1138+
!cx.tcx.used_unsafe.contains(&blk.id) {
11361139
cx.span_lint(unused_unsafe, blk.span,
11371140
"unnecessary `unsafe` block");
11381141
}

branches/try2/src/librustc/middle/ty.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,8 +4266,7 @@ pub fn is_binopable(cx: ctxt, ty: t, op: ast::BinOp) -> bool {
42664266
static tycat_char: int = 2;
42674267
static tycat_int: int = 3;
42684268
static tycat_float: int = 4;
4269-
static tycat_struct: int = 5;
4270-
static tycat_bot: int = 6;
4269+
static tycat_bot: int = 5;
42714270

42724271
static opcat_add: int = 0;
42734272
static opcat_sub: int = 1;
@@ -4310,7 +4309,6 @@ pub fn is_binopable(cx: ctxt, ty: t, op: ast::BinOp) -> bool {
43104309
ty_bool => tycat_bool,
43114310
ty_int(_) | ty_uint(_) | ty_infer(IntVar(_)) => tycat_int,
43124311
ty_float(_) | ty_infer(FloatVar(_)) => tycat_float,
4313-
ty_tup(_) | ty_enum(_, _) => tycat_struct,
43144312
ty_bot => tycat_bot,
43154313
_ => tycat_other
43164314
}
@@ -4326,8 +4324,7 @@ pub fn is_binopable(cx: ctxt, ty: t, op: ast::BinOp) -> bool {
43264324
/*char*/ [f, f, f, f, t, t, f, f],
43274325
/*int*/ [t, t, t, t, t, t, t, f],
43284326
/*float*/ [t, t, t, f, t, t, f, f],
4329-
/*bot*/ [f, f, f, f, f, f, f, f],
4330-
/*struct*/ [t, t, t, t, f, f, t, t]];
4327+
/*bot*/ [t, t, t, t, f, f, t, t]];
43314328

43324329
return tbl[tycat(cx, ty)][opcat(op)];
43334330
}

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl PurityState {
200200

201201
purity => {
202202
let (purity, def) = match blk.rules {
203-
ast::UnsafeBlock => (ast::unsafe_fn, blk.id),
203+
ast::UnsafeBlock(*) => (ast::unsafe_fn, blk.id),
204204
ast::DefaultBlock => (purity, self.def),
205205
};
206206
PurityState{ def: def,

0 commit comments

Comments
 (0)