Skip to content

Commit f8b6539

Browse files
committed
---
yaml --- r: 128890 b: refs/heads/try c: 0d8738f h: refs/heads/master v: v3
1 parent d0f2ce8 commit f8b6539

File tree

6 files changed

+99
-15
lines changed

6 files changed

+99
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 61b9036bb8612d6330f9cb6bb3b52219bebe1802
5+
refs/heads/try: 0d8738f9b52b62991e9c7b44a9d01a13c1398475
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libnum/bigint.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
use Integer;
6060
use rand::Rng;
6161

62-
use std::{cmp, fmt};
62+
use std::{cmp, fmt, hash};
6363
use std::default::Default;
6464
use std::from_str::FromStr;
6565
use std::num::CheckedDiv;
@@ -150,6 +150,22 @@ impl Default for BigUint {
150150
fn default() -> BigUint { Zero::zero() }
151151
}
152152

153+
impl<S: hash::Writer> hash::Hash<S> for BigUint {
154+
fn hash(&self, state: &mut S) {
155+
// hash 0 in case it's all 0's
156+
0u32.hash(state);
157+
158+
let mut found_first_value = false;
159+
for elem in self.data.iter().rev() {
160+
// don't hash any leading 0's, they shouldn't affect the hash
161+
if found_first_value || *elem != 0 {
162+
found_first_value = true;
163+
elem.hash(state);
164+
}
165+
}
166+
}
167+
}
168+
153169
impl fmt::Show for BigUint {
154170
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
155171
write!(f, "{}", self.to_str_radix(10))
@@ -881,6 +897,13 @@ impl fmt::Show for BigInt {
881897
}
882898
}
883899

900+
impl<S: hash::Writer> hash::Hash<S> for BigInt {
901+
fn hash(&self, state: &mut S) {
902+
(self.sign == Plus).hash(state);
903+
self.data.hash(state);
904+
}
905+
}
906+
884907
impl FromStr for BigInt {
885908
#[inline]
886909
fn from_str(s: &str) -> Option<BigInt> {
@@ -1409,6 +1432,7 @@ mod biguint_tests {
14091432
use std::num::CheckedDiv;
14101433
use std::rand::task_rng;
14111434
use std::u64;
1435+
use std::hash::hash;
14121436

14131437
#[test]
14141438
fn test_from_slice() {
@@ -1460,6 +1484,19 @@ mod biguint_tests {
14601484
}
14611485
}
14621486

1487+
#[test]
1488+
fn test_hash() {
1489+
let a = BigUint::new(vec!());
1490+
let b = BigUint::new(vec!(0));
1491+
let c = BigUint::new(vec!(1));
1492+
let d = BigUint::new(vec!(1,0,0,0,0,0));
1493+
let e = BigUint::new(vec!(0,0,0,0,0,1));
1494+
assert!(hash(&a) == hash(&b));
1495+
assert!(hash(&b) != hash(&c));
1496+
assert!(hash(&c) == hash(&d));
1497+
assert!(hash(&d) != hash(&e));
1498+
}
1499+
14631500
#[test]
14641501
fn test_bitand() {
14651502
fn check(left: &[BigDigit],
@@ -2257,6 +2294,7 @@ mod bigint_tests {
22572294
use std::num::{ToPrimitive, FromPrimitive};
22582295
use std::rand::task_rng;
22592296
use std::u64;
2297+
use std::hash::hash;
22602298

22612299
#[test]
22622300
fn test_from_biguint() {
@@ -2314,6 +2352,21 @@ mod bigint_tests {
23142352
}
23152353
}
23162354

2355+
#[test]
2356+
fn test_hash() {
2357+
let a = BigInt::new(Zero, vec!());
2358+
let b = BigInt::new(Zero, vec!(0));
2359+
let c = BigInt::new(Plus, vec!(1));
2360+
let d = BigInt::new(Plus, vec!(1,0,0,0,0,0));
2361+
let e = BigInt::new(Plus, vec!(0,0,0,0,0,1));
2362+
let f = BigInt::new(Minus, vec!(1));
2363+
assert!(hash(&a) == hash(&b));
2364+
assert!(hash(&b) != hash(&c));
2365+
assert!(hash(&c) == hash(&d));
2366+
assert!(hash(&d) != hash(&e));
2367+
assert!(hash(&c) != hash(&f));
2368+
}
2369+
23172370
#[test]
23182371
fn test_convert_i64() {
23192372
fn check(b1: BigInt, i: i64) {

branches/try/src/libnum/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
//! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
4444
4545
#![feature(macro_rules)]
46+
#![feature(default_type_params)]
4647

4748
#![crate_name = "num"]
4849
#![experimental]

branches/try/src/librustc/middle/typeck/check/_match.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
355355
}
356356
}
357357

358-
pub fn check_struct_pat(pcx: &pat_ctxt, _pat_id: ast::NodeId, span: Span,
359-
_expected: ty::t, _path: &ast::Path,
358+
pub fn check_struct_pat(pcx: &pat_ctxt, span: Span,
360359
fields: &[ast::FieldPat], etc: bool,
361360
struct_id: ast::DefId,
362361
substitutions: &subst::Substs) {
@@ -529,8 +528,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
529528
},
530529
}
531530

532-
check_struct_pat(pcx, pat.id, pat.span, expected, path,
533-
fields.as_slice(), etc, cid, substs);
531+
check_struct_pat(pcx, pat.span, fields.as_slice(), etc, cid, substs);
534532
}
535533
ty::ty_enum(eid, ref substs) => {
536534
check_struct_like_enum_variant_pat(pcx,
@@ -557,15 +555,11 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
557555
None);
558556
match tcx.def_map.borrow().find(&pat.id) {
559557
Some(def) => {
560-
check_struct_pat(pcx,
561-
pat.id,
562-
pat.span,
563-
ty::mk_err(),
564-
path,
565-
fields.as_slice(),
566-
etc,
567-
def.def_id(),
568-
&subst::Substs::empty());
558+
let item_type = ty::lookup_item_type(tcx, def.def_id());
559+
let substitutions = fcx.infcx().fresh_substs_for_type(
560+
pat.span, &item_type.generics);
561+
check_struct_pat(pcx, pat.span, fields.as_slice(),
562+
etc, def.def_id(), &substitutions);
569563
}
570564
None => {
571565
tcx.sess.span_bug(pat.span,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::raw::Slice;
12+
13+
fn main() {
14+
let Slice { data: data, len: len } = "foo";
15+
//~^ ERROR mismatched types: expected `&'static str` but found a structure pattern
16+
}
17+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::raw::Slice;
12+
13+
fn main() {
14+
match () {
15+
Slice { data: data, len: len } => (),
16+
//~^ ERROR mismatched types: expected `()` but found a structure pattern
17+
_ => unreachable!()
18+
}
19+
}

0 commit comments

Comments
 (0)