Skip to content

Commit 48c79a3

Browse files
committed
---
yaml --- r: 81567 b: refs/heads/snap-stage3 c: 0bad7e1 h: refs/heads/master i: 81565: 91db617 81563: f07758a 81559: 8a12344 81551: 1fa57ea 81535: e477cbc v: v3
1 parent d5cd4a5 commit 48c79a3

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 4c6bf4872012c010f84dc7fa2cdfe87522533f89
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 95609699e3796f4911dc433e5a6edbe17847b0e1
4+
refs/heads/snap-stage3: 0bad7e1a37c21668ff4f4d4f4b629218b9f47538
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/trans/adt.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: Disr,
505505
}
506506
Univariant(ref st, _dro) => {
507507
assert_eq!(discr, 0);
508-
let contents = build_const_struct(ccx, st, vals);
509-
if st.packed {
510-
C_packed_struct(contents)
511-
} else {
512-
C_struct(contents)
513-
}
508+
C_struct(build_const_struct(ccx, st, vals))
514509
}
515510
General(ref cases) => {
516511
let case = &cases[discr];

branches/snap-stage3/src/libstd/vec.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ pub trait ImmutableVector<'self, T> {
840840
fn window_iter(self, size: uint) -> WindowIter<'self, T>;
841841
fn chunk_iter(self, size: uint) -> ChunkIter<'self, T>;
842842

843+
fn get_opt(&self, index: uint) -> Option<&'self T>;
843844
fn head(&self) -> &'self T;
844845
fn head_opt(&self) -> Option<&'self T>;
845846
fn tail(&self) -> &'self [T];
@@ -1019,6 +1020,13 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
10191020
ChunkIter { v: self, size: size }
10201021
}
10211022

1023+
/// Returns the element of a vector at the given index, or `None` if the
1024+
/// index is out of bounds
1025+
#[inline]
1026+
fn get_opt(&self, index: uint) -> Option<&'self T> {
1027+
if index < self.len() { Some(&self[index]) } else { None }
1028+
}
1029+
10221030
/// Returns the first element of a vector, failing if the vector is empty.
10231031
#[inline]
10241032
fn head(&self) -> &'self T {
@@ -2574,6 +2582,16 @@ mod tests {
25742582
assert_eq!(v2.len(), 2);
25752583
}
25762584

2585+
#[test]
2586+
fn test_get_opt() {
2587+
let mut a = ~[11];
2588+
assert_eq!(a.get_opt(1), None);
2589+
a = ~[11, 12];
2590+
assert_eq!(a.get_opt(1).unwrap(), &12);
2591+
a = ~[11, 12, 13];
2592+
assert_eq!(a.get_opt(1).unwrap(), &12);
2593+
}
2594+
25772595
#[test]
25782596
fn test_head() {
25792597
let mut a = ~[11];

branches/snap-stage3/src/test/run-pass/packed-struct-size.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ struct S7_Option {
5050
d: Option<@mut f64>
5151
}
5252

53-
// Placing packed structs in statics should work
54-
static TEST_S4: S4 = S4 { a: 1, b: [2, 3, 4] };
55-
static TEST_S5: S5 = S5 { a: 3, b: 67 };
56-
static TEST_S3_Foo: S3_Foo = S3_Foo { a: 1, b: 2, c: Baz };
57-
5853

5954
pub fn main() {
6055
assert_eq!(sys::size_of::<S4>(), 4);

0 commit comments

Comments
 (0)