Skip to content

Commit 538d21f

Browse files
---
yaml --- r: 101375 b: refs/heads/master c: d9fadbc h: refs/heads/master i: 101373: 1e97014 101371: 3d97ddc 101367: 0843e89 101359: 8ec0cc9 101343: 01c8185 101311: f9f430e 101247: f3721cf 101119: 4763a69 100863: 696ce11 100351: bd2855e v: v3
1 parent ffd2dea commit 538d21f

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 339603426e65896a06fcebf63f3d751f242ee820
2+
refs/heads/master: d9fadbc04f5bbd520e4ce8665ac128288e9846c0
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/librustc/middle/trans/cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
662662
// Check if a landing pad block exists; if not, create one.
663663
{
664664
let mut scopes = self.scopes.borrow_mut();
665-
let last_scope = scopes.get().mut_last();
665+
let last_scope = scopes.get().mut_last().unwrap();
666666
match last_scope.cached_landing_pad {
667667
Some(llbb) => { return llbb; }
668668
None => {

trunk/src/libstd/vec.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ pub trait MutableVector<'a, T> {
20312031
fn mut_iter(self) -> MutItems<'a, T>;
20322032

20332033
/// Returns a mutable pointer to the last item in the vector.
2034-
fn mut_last(self) -> &'a mut T;
2034+
fn mut_last(self) -> Option<&'a mut T>;
20352035

20362036
/// Returns a reversed iterator that allows modifying each value
20372037
fn mut_rev_iter(self) -> RevMutItems<'a, T>;
@@ -2298,10 +2298,10 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
22982298
}
22992299

23002300
#[inline]
2301-
fn mut_last(self) -> &'a mut T {
2301+
fn mut_last(self) -> Option<&'a mut T> {
23022302
let len = self.len();
2303-
if len == 0 { fail!("mut_last: empty vector") }
2304-
&mut self[len - 1]
2303+
if len == 0 { return None; }
2304+
Some(&mut self[len - 1])
23052305
}
23062306

23072307
#[inline]
@@ -4305,6 +4305,16 @@ mod tests {
43054305
let mut y: &mut [int] = [];
43064306
assert!(y.mut_pop_ref().is_none());
43074307
}
4308+
4309+
#[test]
4310+
fn test_mut_last() {
4311+
let mut x = [1, 2, 3, 4, 5];
4312+
let h = x.mut_last();
4313+
assert_eq!(*h.unwrap(), 5);
4314+
4315+
let mut y: &mut [int] = [];
4316+
assert!(y.mut_last().is_none());
4317+
}
43084318
}
43094319

43104320
#[cfg(test)]

trunk/src/libsyntax/opt_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ impl<T> OptVec<T> {
6262
}
6363
}
6464

65-
pub fn mut_last<'a>(&'a mut self) -> &'a mut T {
65+
pub fn mut_last<'a>(&'a mut self) -> Option<&'a mut T> {
6666
match *self {
6767
Vec(ref mut v) => v.mut_last(),
68-
Empty => fail!("mut_last on empty opt_vec")
68+
Empty => None
6969
}
7070
}
7171

0 commit comments

Comments
 (0)