Skip to content

Commit 1325ed2

Browse files
committed
---
yaml --- r: 83083 b: refs/heads/auto c: 0bad7e1 h: refs/heads/master i: 83081: 0d1a708 83079: a6fcd7d v: v3
1 parent a8e07fe commit 1325ed2

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
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 95609699e3796f4911dc433e5a6edbe17847b0e1
16+
refs/heads/auto: 0bad7e1a37c21668ff4f4d4f4b629218b9f47538
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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/auto/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/auto/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)