Skip to content

Commit 6b4d074

Browse files
committed
---
yaml --- r: 123662 b: refs/heads/try c: 6959931 h: refs/heads/master v: v3
1 parent 1d69674 commit 6b4d074

39 files changed

+820
-291
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: da4e4e4e0a7778a85748aa4a303b13f603e96b4b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 8ddd286ea4ba4384a0dc9eae393ed515460a986e
5-
refs/heads/try: 947942e42c3856f4a673fe2e853e8c3f57e0993a
5+
refs/heads/try: 6959931498820b2b784168164b53a79dceafc4da
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/etc/vim/syntax/rust.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ syn keyword rustTrait Copy Send Sized Share
6565
syn keyword rustTrait Add Sub Mul Div Rem Neg Not
6666
syn keyword rustTrait BitAnd BitOr BitXor
6767
syn keyword rustTrait Drop Deref DerefMut
68-
syn keyword rustTrait Shl Shr Index
68+
syn keyword rustTrait Shl Shr Index IndexMut
6969
syn keyword rustEnum Option
7070
syn keyword rustEnumVariant Some None
7171
syn keyword rustEnum Result

branches/try/src/libcollections/bitv.rs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,36 @@ use core::cmp;
1616
use core::default::Default;
1717
use core::fmt;
1818
use core::iter::Take;
19-
use core::ops;
2019
use core::slice;
2120
use core::uint;
2221
use std::hash;
2322

2423
use {Collection, Mutable, Set, MutableSet};
2524
use vec::Vec;
2625

26+
#[cfg(not(stage0))]
27+
use core::ops::Index;
28+
29+
#[cfg(not(stage0))]
30+
static TRUE: bool = true;
31+
32+
#[cfg(not(stage0))]
33+
static FALSE: bool = false;
34+
35+
#[deriving(Clone)]
36+
struct SmallBitv {
37+
/// only the lowest nbits of this value are used. the rest is undefined.
38+
bits: uint
39+
}
40+
41+
#[deriving(Clone)]
42+
struct BigBitv {
43+
storage: Vec<uint>
44+
}
45+
46+
#[deriving(Clone)]
47+
enum BitvVariant { Big(BigBitv), Small(SmallBitv) }
48+
2749
/// The bitvector type
2850
///
2951
/// # Example
@@ -58,6 +80,18 @@ pub struct Bitv {
5880
nbits: uint
5981
}
6082

83+
#[cfg(not(stage0))]
84+
impl Index<uint,bool> for Bitv {
85+
#[inline]
86+
fn index<'a>(&'a self, i: &uint) -> &'a bool {
87+
if self.get(*i) {
88+
&TRUE
89+
} else {
90+
&FALSE
91+
}
92+
}
93+
}
94+
6195
struct MaskWords<'a> {
6296
iter: slice::Items<'a, uint>,
6397
next_word: Option<&'a uint>,
@@ -268,7 +302,7 @@ impl Bitv {
268302
if offset >= bitv.nbits {
269303
0
270304
} else {
271-
bitv[offset] as u8 << (7 - bit)
305+
bitv.get(offset) as u8 << (7 - bit)
272306
}
273307
}
274308

@@ -286,6 +320,13 @@ impl Bitv {
286320
)
287321
}
288322

323+
/**
324+
* Transform `self` into a `Vec<bool>` by turning each bit into a `bool`.
325+
*/
326+
pub fn to_bools(&self) -> Vec<bool> {
327+
Vec::from_fn(self.nbits, |i| self.get(i))
328+
}
329+
289330
/**
290331
* Compare a bitvector to a vector of `bool`.
291332
*
@@ -504,13 +545,6 @@ impl Clone for Bitv {
504545
}
505546
}
506547

507-
impl ops::Index<uint,bool> for Bitv {
508-
#[inline]
509-
fn index(&self, i: &uint) -> bool {
510-
self.get(*i)
511-
}
512-
}
513-
514548
impl fmt::Show for Bitv {
515549
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
516550
for bit in self.iter() {
@@ -1369,9 +1403,9 @@ mod tests {
13691403
b2.set(1, true);
13701404
b2.set(2, true);
13711405
assert!(b1.difference(&b2));
1372-
assert!(b1[0]);
1373-
assert!(!b1[1]);
1374-
assert!(!b1[2]);
1406+
assert!(b1.get(0));
1407+
assert!(!b1.get(1));
1408+
assert!(!b1.get(2));
13751409
}
13761410

13771411
#[test]
@@ -1383,9 +1417,9 @@ mod tests {
13831417
b2.set(40, true);
13841418
b2.set(80, true);
13851419
assert!(b1.difference(&b2));
1386-
assert!(b1[0]);
1387-
assert!(!b1[40]);
1388-
assert!(!b1[80]);
1420+
assert!(b1.get(0));
1421+
assert!(!b1.get(40));
1422+
assert!(!b1.get(80));
13891423
}
13901424

13911425
#[test]

branches/try/src/libcollections/vec.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ use {Collection, Mutable};
2727
use slice::{MutableOrdVector, MutableVectorAllocating, CloneableVector};
2828
use slice::{Items, MutItems};
2929

30+
31+
#[doc(hidden)]
32+
pub static PTR_MARKER: u8 = 0;
33+
3034
/// An owned, growable vector.
3135
///
3236
/// # Examples
@@ -71,7 +75,11 @@ impl<T> Vec<T> {
7175
/// ```
7276
#[inline]
7377
pub fn new() -> Vec<T> {
74-
Vec { len: 0, cap: 0, ptr: 0 as *mut T }
78+
// We want ptr to never be NULL so instead we set it to some arbitrary
79+
// non-null value which is fine since we never call deallocate on the ptr
80+
// if cap is 0. The reason for this is because the pointer of a slice
81+
// being NULL would break the null pointer optimization for enums.
82+
Vec { len: 0, cap: 0, ptr: &PTR_MARKER as *const _ as *mut T }
7583
}
7684

7785
/// Constructs a new, empty `Vec` with the specified capacity.
@@ -88,7 +96,7 @@ impl<T> Vec<T> {
8896
#[inline]
8997
pub fn with_capacity(capacity: uint) -> Vec<T> {
9098
if mem::size_of::<T>() == 0 {
91-
Vec { len: 0, cap: uint::MAX, ptr: 0 as *mut T }
99+
Vec { len: 0, cap: uint::MAX, ptr: &PTR_MARKER as *const _ as *mut T }
92100
} else if capacity == 0 {
93101
Vec::new()
94102
} else {
@@ -1206,15 +1214,7 @@ impl<T> Vec<T> {
12061214
/// would also make any pointers to it invalid.
12071215
#[inline]
12081216
pub fn as_ptr(&self) -> *const T {
1209-
// If we have a 0-sized vector, then the base pointer should not be NULL
1210-
// because an iterator over the slice will attempt to yield the base
1211-
// pointer as the first element in the vector, but this will end up
1212-
// being Some(NULL) which is optimized to None.
1213-
if mem::size_of::<T>() == 0 {
1214-
1 as *const T
1215-
} else {
1216-
self.ptr as *const T
1217-
}
1217+
self.ptr as *const T
12181218
}
12191219

12201220
/// Returns a mutable unsafe pointer to the vector's buffer.
@@ -1226,12 +1226,7 @@ impl<T> Vec<T> {
12261226
/// would also make any pointers to it invalid.
12271227
#[inline]
12281228
pub fn as_mut_ptr(&mut self) -> *mut T {
1229-
// see above for the 0-size check
1230-
if mem::size_of::<T>() == 0 {
1231-
1 as *mut T
1232-
} else {
1233-
self.ptr
1234-
}
1229+
self.ptr
12351230
}
12361231

12371232
/// Retains only the elements specified by the predicate.

branches/try/src/libcore/ops.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
613613
/**
614614
*
615615
* The `Index` trait is used to specify the functionality of indexing operations
616-
* like `arr[idx]`.
616+
* like `arr[idx]` when used in an immutable context.
617617
*
618618
* # Example
619619
*
@@ -624,9 +624,9 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
624624
* struct Foo;
625625
*
626626
* impl Index<Foo, Foo> for Foo {
627-
* fn index(&self, _rhs: &Foo) -> Foo {
627+
* fn index<'a>(&'a self, _rhs: &Foo) -> &'a Foo {
628628
* println!("Indexing!");
629-
* *self
629+
* self
630630
* }
631631
* }
632632
*
@@ -636,9 +636,42 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
636636
* ```
637637
*/
638638
#[lang="index"]
639+
#[cfg(not(stage0))]
639640
pub trait Index<Index,Result> {
640641
/// The method for the indexing (`Foo[Bar]`) operation
641-
fn index(&self, index: &Index) -> Result;
642+
fn index<'a>(&'a self, index: &Index) -> &'a Result;
643+
}
644+
645+
/**
646+
*
647+
* The `IndexMut` trait is used to specify the functionality of indexing
648+
* operations like `arr[idx]`, when used in a mutable context.
649+
*
650+
* # Example
651+
*
652+
* A trivial implementation of `IndexMut`. When `Foo[Foo]` happens, it ends up
653+
* calling `index`, and therefore, `main` prints `Indexing!`.
654+
*
655+
* ```
656+
* struct Foo;
657+
*
658+
* impl IndexMut<Foo, Foo> for Foo {
659+
* fn index_mut<'a>(&'a mut self, _rhs: &Foo) -> &'a mut Foo {
660+
* println!("Indexing!");
661+
* self
662+
* }
663+
* }
664+
*
665+
* fn main() {
666+
* &mut Foo[Foo];
667+
* }
668+
* ```
669+
*/
670+
#[lang="index_mut"]
671+
#[cfg(not(stage0))]
672+
pub trait IndexMut<Index,Result> {
673+
/// The method for the indexing (`Foo[Bar]`) operation
674+
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result;
642675
}
643676

644677
/**

branches/try/src/libcore/prelude.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ pub use kinds::{Copy, Send, Sized, Share};
3333
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
3434
pub use ops::{BitAnd, BitOr, BitXor};
3535
pub use ops::{Drop, Deref, DerefMut};
36-
pub use ops::{Shl, Shr, Index};
36+
pub use ops::{Shl, Shr};
37+
#[cfg(not(stage0))]
38+
pub use ops::{Index, IndexMut};
3739
pub use option::{Option, Some, None};
3840
pub use result::{Result, Ok, Err};
3941

branches/try/src/libcore/slice.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -884,17 +884,20 @@ macro_rules! iterator {
884884
if self.ptr == self.end {
885885
None
886886
} else {
887-
let old = self.ptr;
888-
self.ptr = if mem::size_of::<T>() == 0 {
887+
if mem::size_of::<T>() == 0 {
889888
// purposefully don't use 'ptr.offset' because for
890889
// vectors with 0-size elements this would return the
891890
// same pointer.
892-
transmute(self.ptr as uint + 1)
891+
self.ptr = transmute(self.ptr as uint + 1);
892+
893+
// Use a non-null pointer value
894+
Some(transmute(1u))
893895
} else {
894-
self.ptr.offset(1)
895-
};
896+
let old = self.ptr;
897+
self.ptr = self.ptr.offset(1);
896898

897-
Some(transmute(old))
899+
Some(transmute(old))
900+
}
898901
}
899902
}
900903
}
@@ -916,13 +919,17 @@ macro_rules! iterator {
916919
if self.end == self.ptr {
917920
None
918921
} else {
919-
self.end = if mem::size_of::<T>() == 0 {
922+
if mem::size_of::<T>() == 0 {
920923
// See above for why 'ptr.offset' isn't used
921-
transmute(self.end as uint - 1)
924+
self.end = transmute(self.end as uint - 1);
925+
926+
// Use a non-null pointer value
927+
Some(transmute(1u))
922928
} else {
923-
self.end.offset(-1)
924-
};
925-
Some(transmute(self.end))
929+
self.end = self.end.offset(-1);
930+
931+
Some(transmute(self.end))
932+
}
926933
}
927934
}
928935
}
@@ -956,7 +963,12 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
956963
fn idx(&mut self, index: uint) -> Option<&'a T> {
957964
unsafe {
958965
if index < self.indexable() {
959-
transmute(self.ptr.offset(index as int))
966+
if mem::size_of::<T>() == 0 {
967+
// Use a non-null pointer value
968+
Some(transmute(1u))
969+
} else {
970+
Some(transmute(self.ptr.offset(index as int)))
971+
}
960972
} else {
961973
None
962974
}

branches/try/src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl CStore {
196196
}
197197

198198
pub fn add_used_link_args(&self, args: &str) {
199-
for s in args.split(' ') {
199+
for s in args.split(' ').filter(|s| !s.is_empty()) {
200200
self.used_link_args.borrow_mut().push(s.to_string());
201201
}
202202
}

branches/try/src/librustc/middle/check_match.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,17 @@ pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
673673
} else {
674674
None
675675
},
676-
DefStruct(struct_id) => Some(struct_id),
677-
_ => None
676+
_ => {
677+
// Assume this is a struct.
678+
match ty::ty_to_def_id(node_id_to_type(cx.tcx, pat_id)) {
679+
None => {
680+
cx.tcx.sess.span_bug(pat_span,
681+
"struct pattern wasn't of a \
682+
type with a def ID?!")
683+
}
684+
Some(def_id) => Some(def_id),
685+
}
686+
}
678687
};
679688
class_id.map(|variant_id| {
680689
let struct_fields = ty::lookup_struct_fields(cx.tcx, variant_id);

0 commit comments

Comments
 (0)