Skip to content

Commit 4beff38

Browse files
committed
---
yaml --- r: 153215 b: refs/heads/try2 c: e2e237a h: refs/heads/master i: 153213: ee11dd8 153211: 37e8203 153207: c3f146a 153199: 5d04e62 153183: a109fa1 153151: f48ee66 153087: dd4e80a v: v3
1 parent 8b34c10 commit 4beff38

File tree

17 files changed

+243
-101
lines changed

17 files changed

+243
-101
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: 8121c39a3ef6225c8500cdd9f4f14e6e4cc1456f
8+
refs/heads/try2: e2e237afc1f9887699414c33332faa1efaba41ce
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/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/try2/src/librustc/middle/check_match.rs

Lines changed: 4 additions & 2 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
}

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ enum BareIdentifierPatternResolution {
307307
#[deriving(PartialEq)]
308308
enum DuplicateCheckingMode {
309309
ForbidDuplicateModules,
310-
ForbidDuplicateTypes,
310+
ForbidDuplicateTypesAndModules,
311311
ForbidDuplicateValues,
312312
ForbidDuplicateTypesAndValues,
313313
OverwriteDuplicates
@@ -792,10 +792,9 @@ impl PrimitiveTypeTable {
792792

793793
fn namespace_error_to_str(ns: NamespaceError) -> &'static str {
794794
match ns {
795-
NoError => "",
796-
ModuleError => "module",
797-
TypeError => "type",
798-
ValueError => "value",
795+
NoError => "",
796+
ModuleError | TypeError => "type or module",
797+
ValueError => "value",
799798
}
800799
}
801800

@@ -1033,9 +1032,12 @@ impl<'a> Resolver<'a> {
10331032
}
10341033
Some(TypeNS)
10351034
}
1036-
ForbidDuplicateTypes => {
1035+
ForbidDuplicateTypesAndModules => {
10371036
match child.def_for_namespace(TypeNS) {
1038-
Some(DefMod(_)) | None => {}
1037+
None => {}
1038+
Some(_) if child.get_module_if_available()
1039+
.map(|m| m.kind.get()) ==
1040+
Some(ImplModuleKind) => {}
10391041
Some(_) => duplicate_type = TypeError
10401042
}
10411043
Some(TypeNS)
@@ -1177,7 +1179,10 @@ impl<'a> Resolver<'a> {
11771179
// These items live in the type namespace.
11781180
ItemTy(..) => {
11791181
let name_bindings =
1180-
self.add_child(ident, parent.clone(), ForbidDuplicateTypes, sp);
1182+
self.add_child(ident,
1183+
parent.clone(),
1184+
ForbidDuplicateTypesAndModules,
1185+
sp);
11811186

11821187
name_bindings.define_type
11831188
(DefTy(local_def(item.id)), sp, is_public);
@@ -1186,7 +1191,10 @@ impl<'a> Resolver<'a> {
11861191

11871192
ItemEnum(ref enum_definition, _) => {
11881193
let name_bindings =
1189-
self.add_child(ident, parent.clone(), ForbidDuplicateTypes, sp);
1194+
self.add_child(ident,
1195+
parent.clone(),
1196+
ForbidDuplicateTypesAndModules,
1197+
sp);
11901198

11911199
name_bindings.define_type
11921200
(DefTy(local_def(item.id)), sp, is_public);
@@ -1206,7 +1214,7 @@ impl<'a> Resolver<'a> {
12061214
// Adding to both Type and Value namespaces or just Type?
12071215
let (forbid, ctor_id) = match struct_def.ctor_id {
12081216
Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
1209-
None => (ForbidDuplicateTypes, None)
1217+
None => (ForbidDuplicateTypesAndModules, None)
12101218
};
12111219

12121220
let name_bindings = self.add_child(ident, parent.clone(), forbid, sp);
@@ -1327,7 +1335,10 @@ impl<'a> Resolver<'a> {
13271335

13281336
ItemTrait(_, _, _, ref methods) => {
13291337
let name_bindings =
1330-
self.add_child(ident, parent.clone(), ForbidDuplicateTypes, sp);
1338+
self.add_child(ident,
1339+
parent.clone(),
1340+
ForbidDuplicateTypesAndModules,
1341+
sp);
13311342

13321343
// Add all the methods within to a new module.
13331344
let parent_link = self.get_parent_link(parent.clone(), ident);

0 commit comments

Comments
 (0)