Skip to content

Commit b06730f

Browse files
committed
---
yaml --- r: 130175 b: refs/heads/master c: 85e2e5a h: refs/heads/master i: 130173: ec4f8b0 130171: f70bbd5 130167: e763a61 130159: b28fa37 130143: f1c8b82 130111: bf7d74c 130047: 7a2c647 v: v3
1 parent d872969 commit b06730f

File tree

31 files changed

+687
-463
lines changed

31 files changed

+687
-463
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d90921a9d87b17df5eeab9e5f18581e8b04a1ba9
2+
refs/heads/master: 85e2e5a900eb1113b2cea1a4c828c64139692149
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
55
refs/heads/try: 28d5878c1f0465c11c8e7a3085008b0c592d48d0

trunk/src/libcollections/bitv.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ fn match_words <'a,'b>(a: &'a Bitv, b: &'b Bitv) -> (MatchWords<'a>, MatchWords<
9595
static TRUE: bool = true;
9696
static FALSE: bool = false;
9797

98-
#[deriving(Clone)]
99-
struct SmallBitv {
100-
/// only the lowest nbits of this value are used. the rest is undefined.
101-
bits: uint
102-
}
103-
104-
#[deriving(Clone)]
105-
struct BigBitv {
106-
storage: Vec<uint>
107-
}
108-
109-
#[deriving(Clone)]
110-
enum BitvVariant { Big(BigBitv), Small(SmallBitv) }
111-
11298
/// The bitvector type.
11399
///
114100
/// # Example
@@ -1653,6 +1639,7 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
16531639
#[cfg(test)]
16541640
mod tests {
16551641
use std::prelude::*;
1642+
use std::iter::range_step;
16561643
use std::uint;
16571644
use std::rand;
16581645
use std::rand::Rng;
@@ -2046,12 +2033,14 @@ mod tests {
20462033

20472034
#[test]
20482035
fn test_bitv_iterator() {
2049-
let bools = [true, false, true, true];
2036+
let bools = vec![true, false, true, true];
20502037
let bitv: Bitv = bools.iter().map(|n| *n).collect();
20512038

2052-
for (act, &ex) in bitv.iter().zip(bools.iter()) {
2053-
assert_eq!(ex, act);
2054-
}
2039+
assert_eq!(bitv.iter().collect::<Vec<bool>>(), bools)
2040+
2041+
let long = Vec::from_fn(10000, |i| i % 2 == 0);
2042+
let bitv: Bitv = long.iter().map(|n| *n).collect();
2043+
assert_eq!(bitv.iter().collect::<Vec<bool>>(), long)
20552044
}
20562045

20572046
#[test]
@@ -2061,6 +2050,12 @@ mod tests {
20612050

20622051
let idxs: Vec<uint> = bitv.iter().collect();
20632052
assert_eq!(idxs, vec!(0, 2, 3));
2053+
2054+
let long: BitvSet = range(0u, 10000).map(|n| n % 2 == 0).collect();
2055+
let real = range_step(0, 10000, 2).collect::<Vec<uint>>();
2056+
2057+
let idxs: Vec<uint> = long.iter().collect();
2058+
assert_eq!(idxs, real);
20642059
}
20652060

20662061
#[test]
@@ -2574,7 +2569,7 @@ mod tests {
25742569
}
25752570

25762571
#[bench]
2577-
fn bench_bitv_big(b: &mut Bencher) {
2572+
fn bench_bitv_set_big_fixed(b: &mut Bencher) {
25782573
let mut r = rng();
25792574
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
25802575
b.iter(|| {
@@ -2586,7 +2581,19 @@ mod tests {
25862581
}
25872582

25882583
#[bench]
2589-
fn bench_bitv_small(b: &mut Bencher) {
2584+
fn bench_bitv_set_big_variable(b: &mut Bencher) {
2585+
let mut r = rng();
2586+
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
2587+
b.iter(|| {
2588+
for i in range(0u, 100) {
2589+
bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen());
2590+
}
2591+
&bitv
2592+
})
2593+
}
2594+
2595+
#[bench]
2596+
fn bench_bitv_set_small(b: &mut Bencher) {
25902597
let mut r = rng();
25912598
let mut bitv = Bitv::with_capacity(uint::BITS, false);
25922599
b.iter(|| {
@@ -2598,7 +2605,7 @@ mod tests {
25982605
}
25992606

26002607
#[bench]
2601-
fn bench_bitv_set_small(b: &mut Bencher) {
2608+
fn bench_bitvset_small(b: &mut Bencher) {
26022609
let mut r = rng();
26032610
let mut bitv = BitvSet::new();
26042611
b.iter(|| {
@@ -2610,7 +2617,7 @@ mod tests {
26102617
}
26112618

26122619
#[bench]
2613-
fn bench_bitv_set_big(b: &mut Bencher) {
2620+
fn bench_bitvset_big(b: &mut Bencher) {
26142621
let mut r = rng();
26152622
let mut bitv = BitvSet::new();
26162623
b.iter(|| {

trunk/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T> Rawlink<T> {
9090
/// Convert the `Rawlink` into an Option value
9191
fn resolve_immut<'a>(&self) -> Option<&'a T> {
9292
unsafe {
93-
mem::transmute(self.p.to_option())
93+
self.p.as_ref()
9494
}
9595
}
9696

trunk/src/libcore/ptr.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,46 @@ pub unsafe fn position<T>(buf: *const T, f: |&T| -> bool) -> uint {
256256
pub trait RawPtr<T> {
257257
/// Returns the null pointer.
258258
fn null() -> Self;
259+
259260
/// Returns true if the pointer is equal to the null pointer.
260261
fn is_null(&self) -> bool;
262+
261263
/// Returns true if the pointer is not equal to the null pointer.
262264
fn is_not_null(&self) -> bool { !self.is_null() }
265+
263266
/// Returns the value of this pointer (ie, the address it points to)
264267
fn to_uint(&self) -> uint;
265-
/// Returns `None` if the pointer is null, or else returns the value wrapped
266-
/// in `Some`.
268+
269+
/// Returns `None` if the pointer is null, or else returns a reference to the
270+
/// value wrapped in `Some`.
267271
///
268272
/// # Safety Notes
269273
///
270-
/// While this method is useful for null-safety, it is important to note
271-
/// that this is still an unsafe operation because the returned value could
272-
/// be pointing to invalid memory.
273-
unsafe fn to_option(&self) -> Option<&T>;
274+
/// While this method and its mutable counterpart are useful for null-safety,
275+
/// it is important to note that this is still an unsafe operation because
276+
/// the returned value could be pointing to invalid memory.
277+
unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
278+
279+
/// A synonym for `as_ref`, except with incorrect lifetime semantics
280+
#[deprecated="Use `as_ref` instead"]
281+
unsafe fn to_option<'a>(&'a self) -> Option<&'a T> {
282+
mem::transmute(self.as_ref())
283+
}
284+
274285
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
275286
/// the object, or one-byte-past-the-end. `count` is in units of T; e.g. a
276287
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
277288
unsafe fn offset(self, count: int) -> Self;
278289
}
279290

291+
/// Methods on mutable raw pointers
292+
pub trait RawMutPtr<T>{
293+
/// Returns `None` if the pointer is null, or else returns a mutable reference
294+
/// to the value wrapped in `Some`. As with `as_ref`, this is unsafe because
295+
/// it cannot verify the validity of the returned pointer.
296+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T>;
297+
}
298+
280299
impl<T> RawPtr<T> for *const T {
281300
#[inline]
282301
fn null() -> *const T { null() }
@@ -293,7 +312,7 @@ impl<T> RawPtr<T> for *const T {
293312
}
294313

295314
#[inline]
296-
unsafe fn to_option(&self) -> Option<&T> {
315+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
297316
if self.is_null() {
298317
None
299318
} else {
@@ -318,7 +337,7 @@ impl<T> RawPtr<T> for *mut T {
318337
}
319338

320339
#[inline]
321-
unsafe fn to_option(&self) -> Option<&T> {
340+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
322341
if self.is_null() {
323342
None
324343
} else {
@@ -327,6 +346,17 @@ impl<T> RawPtr<T> for *mut T {
327346
}
328347
}
329348

349+
impl<T> RawMutPtr<T> for *mut T {
350+
#[inline]
351+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
352+
if self.is_null() {
353+
None
354+
} else {
355+
Some(&mut **self)
356+
}
357+
}
358+
}
359+
330360
// Equality for pointers
331361
impl<T> PartialEq for *const T {
332362
#[inline]

trunk/src/libcoretest/ptr.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,44 @@ fn test_is_null() {
102102
}
103103

104104
#[test]
105-
fn test_to_option() {
105+
fn test_as_ref() {
106106
unsafe {
107107
let p: *const int = null();
108-
assert_eq!(p.to_option(), None);
108+
assert_eq!(p.as_ref(), None);
109109

110110
let q: *const int = &2;
111-
assert_eq!(q.to_option().unwrap(), &2);
111+
assert_eq!(q.as_ref().unwrap(), &2);
112112

113113
let p: *mut int = mut_null();
114-
assert_eq!(p.to_option(), None);
114+
assert_eq!(p.as_ref(), None);
115115

116116
let q: *mut int = &mut 2;
117-
assert_eq!(q.to_option().unwrap(), &2);
117+
assert_eq!(q.as_ref().unwrap(), &2);
118+
119+
// Lifetime inference
120+
let u = 2i;
121+
{
122+
let p: *const int = &u as *const _;
123+
assert_eq!(p.as_ref().unwrap(), &2);
124+
}
125+
}
126+
}
127+
128+
#[test]
129+
fn test_as_mut() {
130+
unsafe {
131+
let p: *mut int = mut_null();
132+
assert!(p.as_mut() == None);
133+
134+
let q: *mut int = &mut 2;
135+
assert!(q.as_mut().unwrap() == &mut 2);
136+
137+
// Lifetime inference
138+
let mut u = 2i;
139+
{
140+
let p: *mut int = &mut u as *mut _;
141+
assert!(p.as_mut().unwrap() == &mut 2);
142+
}
118143
}
119144
}
120145

trunk/src/liblibc/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,12 +2965,14 @@ pub mod consts {
29652965
pub static AF_INET6: c_int = 10;
29662966
pub static SOCK_STREAM: c_int = 2;
29672967
pub static SOCK_DGRAM: c_int = 1;
2968+
pub static SOCK_RAW: c_int = 3;
29682969
pub static IPPROTO_TCP: c_int = 6;
29692970
pub static IPPROTO_IP: c_int = 0;
29702971
pub static IPPROTO_IPV6: c_int = 41;
29712972
pub static IP_MULTICAST_TTL: c_int = 33;
29722973
pub static IP_MULTICAST_LOOP: c_int = 34;
29732974
pub static IP_TTL: c_int = 2;
2975+
pub static IP_HDRINCL: c_int = 3;
29742976
pub static IP_ADD_MEMBERSHIP: c_int = 35;
29752977
pub static IP_DROP_MEMBERSHIP: c_int = 36;
29762978
pub static IPV6_ADD_MEMBERSHIP: c_int = 20;
@@ -3021,8 +3023,12 @@ pub mod consts {
30213023
pub mod extra {
30223024
use types::os::arch::c95::c_int;
30233025

3026+
pub static AF_PACKET : c_int = 17;
3027+
pub static IPPROTO_RAW : c_int = 255;
3028+
30243029
pub static O_RSYNC : c_int = 16400;
30253030
pub static O_DSYNC : c_int = 16;
3031+
pub static O_NONBLOCK : c_int = 128;
30263032
pub static O_SYNC : c_int = 16400;
30273033

30283034
pub static PROT_GROWSDOWN : c_int = 0x01000000;

trunk/src/liblog/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl Drop for DefaultLogger {
282282
pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) {
283283
// Test the literal string from args against the current filter, if there
284284
// is one.
285-
match unsafe { FILTER.to_option() } {
285+
match unsafe { FILTER.as_ref() } {
286286
Some(filter) if filter.is_match(args.to_string().as_slice()) => return,
287287
_ => {}
288288
}

trunk/src/librustc/middle/check_match.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use syntax::codemap::{Span, Spanned, DUMMY_SP};
2828
use syntax::fold::{Folder, noop_fold_pat};
2929
use syntax::print::pprust::pat_to_string;
3030
use syntax::parse::token;
31-
use syntax::visit;
32-
use syntax::visit::{Visitor, FnKind};
31+
use syntax::visit::{mod, Visitor, FnKind};
3332
use util::ppaux::ty_to_string;
3433

3534
struct Matrix(Vec<Vec<Gc<Pat>>>);
@@ -103,7 +102,9 @@ pub enum Constructor {
103102
/// Ranges of literal values (2..5).
104103
ConstantRange(const_val, const_val),
105104
/// Array patterns of length n.
106-
Slice(uint)
105+
Slice(uint),
106+
/// Array patterns with a subslice.
107+
SliceWithSubslice(uint, uint)
107108
}
108109

109110
#[deriving(Clone, PartialEq)]
@@ -270,13 +271,6 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
270271
}
271272
}
272273

273-
fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
274-
match p.node {
275-
PatIdent(_, _, Some(s)) => { raw_pat(s) }
276-
_ => { p }
277-
}
278-
}
279-
280274
fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
281275
match is_useful(cx, matrix, [wild()], ConstructWitness) {
282276
UsefulWithWitness(pats) => {
@@ -821,6 +815,14 @@ pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
821815
pats.push_all(after.as_slice());
822816
Some(pats)
823817
},
818+
SliceWithSubslice(prefix, suffix)
819+
if before.len() == prefix
820+
&& after.len() == suffix
821+
&& slice.is_some() => {
822+
let mut pats = before.clone();
823+
pats.push_all(after.as_slice());
824+
Some(pats)
825+
}
824826
_ => None
825827
}
826828
}

trunk/src/librustc/middle/kind.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
use middle::freevars::freevar_entry;
1312
use middle::freevars;
1413
use middle::subst;
@@ -587,15 +586,15 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
587586
match aty.node {
588587
TyPath(_, _, id) => {
589588
match cx.tcx.item_substs.borrow().find(&id) {
590-
None => { }
589+
None => {}
591590
Some(ref item_substs) => {
592591
let def_map = cx.tcx.def_map.borrow();
593592
let did = def_map.get_copy(&id).def_id();
594593
let generics = ty::lookup_item_type(cx.tcx, did).generics;
595594
for def in generics.types.iter() {
596595
let ty = *item_substs.substs.types.get(def.space,
597596
def.index);
598-
check_typaram_bounds(cx, aty.span, ty, def)
597+
check_typaram_bounds(cx, aty.span, ty, def);
599598
}
600599
}
601600
}
@@ -668,7 +667,7 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
668667
.zip(polytype.generics
669668
.types
670669
.iter()) {
671-
check_typaram_bounds(cx, span, *ty, type_param_def)
670+
check_typaram_bounds(cx, span, *ty, type_param_def);
672671
}
673672

674673
// Check trait bounds.

trunk/src/librustc/middle/pat_util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ pub fn wild() -> Gc<Pat> {
119119
box (GC) Pat { id: 0, node: PatWild(PatWildSingle), span: DUMMY_SP }
120120
}
121121

122+
pub fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
123+
match p.node {
124+
PatIdent(_, _, Some(s)) => { raw_pat(s) }
125+
_ => { p }
126+
}
127+
}
128+
122129
pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
123130
ty::with_path(tcx, id, |mut path| Path {
124131
global: false,

0 commit comments

Comments
 (0)