Skip to content

Commit 1d69674

Browse files
author
Jakub Wieczorek
committed
---
yaml --- r: 123661 b: refs/heads/try c: 947942e h: refs/heads/master i: 123659: f9d54c4 v: v3
1 parent 64914bf commit 1d69674

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+303
-828
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: 6f46621b335d398f3c837750d31797014f63578b
5+
refs/heads/try: 947942e42c3856f4a673fe2e853e8c3f57e0993a
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 IndexMut
68+
syn keyword rustTrait Shl Shr Index
6969
syn keyword rustEnum Option
7070
syn keyword rustEnumVariant Some None
7171
syn keyword rustEnum Result

branches/try/src/libcollections/bitv.rs

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

2324
use {Collection, Mutable, Set, MutableSet};
2425
use vec::Vec;
2526

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-
4927
/// The bitvector type
5028
///
5129
/// # Example
@@ -80,18 +58,6 @@ pub struct Bitv {
8058
nbits: uint
8159
}
8260

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-
9561
struct MaskWords<'a> {
9662
iter: slice::Items<'a, uint>,
9763
next_word: Option<&'a uint>,
@@ -302,7 +268,7 @@ impl Bitv {
302268
if offset >= bitv.nbits {
303269
0
304270
} else {
305-
bitv.get(offset) as u8 << (7 - bit)
271+
bitv[offset] as u8 << (7 - bit)
306272
}
307273
}
308274

@@ -320,13 +286,6 @@ impl Bitv {
320286
)
321287
}
322288

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-
330289
/**
331290
* Compare a bitvector to a vector of `bool`.
332291
*
@@ -545,6 +504,13 @@ impl Clone for Bitv {
545504
}
546505
}
547506

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

14111377
#[test]
@@ -1417,9 +1383,9 @@ mod tests {
14171383
b2.set(40, true);
14181384
b2.set(80, true);
14191385
assert!(b1.difference(&b2));
1420-
assert!(b1.get(0));
1421-
assert!(!b1.get(40));
1422-
assert!(!b1.get(80));
1386+
assert!(b1[0]);
1387+
assert!(!b1[40]);
1388+
assert!(!b1[80]);
14231389
}
14241390

14251391
#[test]

branches/try/src/libcollections/vec.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ 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-
3430
/// An owned, growable vector.
3531
///
3632
/// # Examples
@@ -75,11 +71,7 @@ impl<T> Vec<T> {
7571
/// ```
7672
#[inline]
7773
pub fn new() -> Vec<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 }
74+
Vec { len: 0, cap: 0, ptr: 0 as *mut T }
8375
}
8476

8577
/// Constructs a new, empty `Vec` with the specified capacity.
@@ -96,7 +88,7 @@ impl<T> Vec<T> {
9688
#[inline]
9789
pub fn with_capacity(capacity: uint) -> Vec<T> {
9890
if mem::size_of::<T>() == 0 {
99-
Vec { len: 0, cap: uint::MAX, ptr: &PTR_MARKER as *const _ as *mut T }
91+
Vec { len: 0, cap: uint::MAX, ptr: 0 as *mut T }
10092
} else if capacity == 0 {
10193
Vec::new()
10294
} else {
@@ -1214,7 +1206,15 @@ impl<T> Vec<T> {
12141206
/// would also make any pointers to it invalid.
12151207
#[inline]
12161208
pub fn as_ptr(&self) -> *const T {
1217-
self.ptr as *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+
}
12181218
}
12191219

12201220
/// Returns a mutable unsafe pointer to the vector's buffer.
@@ -1226,7 +1226,12 @@ 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-
self.ptr
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+
}
12301235
}
12311236

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

branches/try/src/libcore/ops.rs

Lines changed: 4 additions & 37 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]` when used in an immutable context.
616+
* like `arr[idx]`.
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<'a>(&'a self, _rhs: &Foo) -> &'a Foo {
627+
* fn index(&self, _rhs: &Foo) -> Foo {
628628
* println!("Indexing!");
629-
* self
629+
* *self
630630
* }
631631
* }
632632
*
@@ -636,42 +636,9 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
636636
* ```
637637
*/
638638
#[lang="index"]
639-
#[cfg(not(stage0))]
640639
pub trait Index<Index,Result> {
641640
/// The method for the indexing (`Foo[Bar]`) operation
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;
641+
fn index(&self, index: &Index) -> Result;
675642
}
676643

677644
/**

branches/try/src/libcore/prelude.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ 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};
37-
#[cfg(not(stage0))]
38-
pub use ops::{Index, IndexMut};
36+
pub use ops::{Shl, Shr, Index};
3937
pub use option::{Option, Some, None};
4038
pub use result::{Result, Ok, Err};
4139

branches/try/src/libcore/slice.rs

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

899-
Some(transmute(old))
900-
}
897+
Some(transmute(old))
901898
}
902899
}
903900
}
@@ -919,17 +916,13 @@ macro_rules! iterator {
919916
if self.end == self.ptr {
920917
None
921918
} else {
922-
if mem::size_of::<T>() == 0 {
919+
self.end = if mem::size_of::<T>() == 0 {
923920
// See above for why 'ptr.offset' isn't used
924-
self.end = transmute(self.end as uint - 1);
925-
926-
// Use a non-null pointer value
927-
Some(transmute(1u))
921+
transmute(self.end as uint - 1)
928922
} else {
929-
self.end = self.end.offset(-1);
930-
931-
Some(transmute(self.end))
932-
}
923+
self.end.offset(-1)
924+
};
925+
Some(transmute(self.end))
933926
}
934927
}
935928
}
@@ -963,12 +956,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
963956
fn idx(&mut self, index: uint) -> Option<&'a T> {
964957
unsafe {
965958
if index < self.indexable() {
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-
}
959+
transmute(self.ptr.offset(index as int))
972960
} else {
973961
None
974962
}

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(' ').filter(|s| !s.is_empty()) {
199+
for s in args.split(' ') {
200200
self.used_link_args.borrow_mut().push(s.to_string());
201201
}
202202
}

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,15 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
283283
};
284284
if is_structure {
285285
let fields = ty::lookup_struct_fields(cx.tcx, vid);
286-
let field_pats = fields.move_iter()
286+
let field_pats: Vec<FieldPat> = fields.move_iter()
287287
.zip(pats.iter())
288+
.filter(|&(_, pat)| pat.node != PatWild)
288289
.map(|(field, pat)| FieldPat {
289290
ident: Ident::new(field.name),
290291
pat: pat.clone()
291292
}).collect();
292-
PatStruct(def_to_path(cx.tcx, vid), field_pats, false)
293+
let has_more_fields = field_pats.len() < pats.len();
294+
PatStruct(def_to_path(cx.tcx, vid), field_pats, has_more_fields)
293295
} else {
294296
PatEnum(def_to_path(cx.tcx, vid), Some(pats))
295297
}
@@ -671,17 +673,8 @@ pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
671673
} else {
672674
None
673675
},
674-
_ => {
675-
// Assume this is a struct.
676-
match ty::ty_to_def_id(node_id_to_type(cx.tcx, pat_id)) {
677-
None => {
678-
cx.tcx.sess.span_bug(pat_span,
679-
"struct pattern wasn't of a \
680-
type with a def ID?!")
681-
}
682-
Some(def_id) => Some(def_id),
683-
}
684-
}
676+
DefStruct(struct_id) => Some(struct_id),
677+
_ => None
685678
};
686679
class_id.map(|variant_id| {
687680
let struct_fields = ty::lookup_struct_fields(cx.tcx, variant_id);

0 commit comments

Comments
 (0)