Skip to content

Commit b5e6573

Browse files
committed
[std::vec] Rename .shift_opt() to .shift(), drop the old .shift() behavior
1 parent bada25e commit b5e6573

File tree

9 files changed

+16
-31
lines changed

9 files changed

+16
-31
lines changed

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) ->
788788
let exe_file = make_exe_name(config, testfile);
789789
// FIXME (#9639): This needs to handle non-utf8 paths
790790
args.push(exe_file.as_str().unwrap().to_owned());
791-
let prog = args.shift();
791+
let prog = args.shift().unwrap();
792792
return ProcArgs {prog: prog, args: args};
793793
}
794794

src/libextra/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ mod tests {
10531053
}
10541054
1 => {
10551055
m.pop_front();
1056-
if v.len() > 0 { v.shift(); }
1056+
v.shift();
10571057
}
10581058
2 | 4 => {
10591059
m.push_front(-i);

src/librustc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn describe_debug_flags() {
190190

191191
pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
192192
let mut args = args.to_owned();
193-
let binary = args.shift();
193+
let binary = args.shift().unwrap();
194194

195195
if args.is_empty() { usage(binary); return; }
196196

src/librustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<'a> Context<'a> {
524524
// rollback
525525
self.is_doc_hidden = old_is_doc_hidden;
526526
pushed.times(|| {
527-
let (lint, lvl, src) = self.lint_stack.pop();
527+
let (lint, lvl, src) = self.lint_stack.pop().unwrap();
528528
self.set_level(lint, lvl, src);
529529
})
530530
}

src/libstd/io/buffered.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ mod test {
370370

371371
impl Reader for ShortReader {
372372
fn read(&mut self, _: &mut [u8]) -> Option<uint> {
373-
self.lengths.shift_opt()
373+
self.lengths.shift()
374374
}
375375
}
376376

src/libstd/io/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub struct Directories {
519519

520520
impl Iterator<Path> for Directories {
521521
fn next(&mut self) -> Option<Path> {
522-
match self.stack.shift_opt() {
522+
match self.stack.shift() {
523523
Some(path) => {
524524
if path.is_dir() {
525525
self.stack.push_all_move(readdir(&path));

src/libstd/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl<'a> Iterator<char> for Normalizations<'a> {
703703
self.sorted = true;
704704
}
705705

706-
match self.buffer.shift_opt() {
706+
match self.buffer.shift() {
707707
Some((c, 0)) => {
708708
self.sorted = false;
709709
Some(c)

src/libstd/vec.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,8 @@ pub trait OwnedVector<T> {
13831383
fn push_all_move(&mut self, rhs: ~[T]);
13841384
/// Remove the last element from a vector and return it, or `None` if it is empty
13851385
fn pop(&mut self) -> Option<T>;
1386-
/// Removes the first element from a vector and return it
1387-
fn shift(&mut self) -> T;
13881386
/// Removes the first element from a vector and return it, or `None` if it is empty
1389-
fn shift_opt(&mut self) -> Option<T>;
1387+
fn shift(&mut self) -> Option<T>;
13901388
/// Prepend an element to the vector
13911389
fn unshift(&mut self, x: T);
13921390

@@ -1578,14 +1576,11 @@ impl<T> OwnedVector<T> for ~[T] {
15781576

15791577

15801578
#[inline]
1581-
fn shift(&mut self) -> T {
1582-
self.shift_opt().expect("shift: empty vector")
1583-
}
1584-
1585-
fn shift_opt(&mut self) -> Option<T> {
1579+
fn shift(&mut self) -> Option<T> {
15861580
self.remove_opt(0)
15871581
}
15881582

1583+
#[inline]
15891584
fn unshift(&mut self, x: T) {
15901585
self.insert(0, x)
15911586
}
@@ -1645,7 +1640,7 @@ impl<T> OwnedVector<T> for ~[T] {
16451640
if index < ln - 1 {
16461641
self.swap(index, ln - 1);
16471642
}
1648-
self.pop()
1643+
self.pop().unwrap()
16491644
}
16501645
fn truncate(&mut self, newlen: uint) {
16511646
let oldlen = self.len();
@@ -3580,21 +3575,11 @@ mod tests {
35803575
#[test]
35813576
fn test_shift() {
35823577
let mut x = ~[1, 2, 3];
3583-
assert_eq!(x.shift(), 1);
3584-
assert_eq!(&x, &~[2, 3]);
3585-
assert_eq!(x.shift(), 2);
3586-
assert_eq!(x.shift(), 3);
3587-
assert_eq!(x.len(), 0);
3588-
}
3589-
3590-
#[test]
3591-
fn test_shift_opt() {
3592-
let mut x = ~[1, 2, 3];
3593-
assert_eq!(x.shift_opt(), Some(1));
3578+
assert_eq!(x.shift(), Some(1));
35943579
assert_eq!(&x, &~[2, 3]);
3595-
assert_eq!(x.shift_opt(), Some(2));
3596-
assert_eq!(x.shift_opt(), Some(3));
3597-
assert_eq!(x.shift_opt(), None);
3580+
assert_eq!(x.shift(), Some(2));
3581+
assert_eq!(x.shift(), Some(3));
3582+
assert_eq!(x.shift(), None);
35983583
assert_eq!(x.len(), 0);
35993584
}
36003585

src/test/bench/core-std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn shift_push() {
6565
let mut v2 = ~[];
6666

6767
while v1.len() > 0 {
68-
v2.push(v1.shift());
68+
v2.push(v1.shift().unwrap());
6969
}
7070
}
7171

0 commit comments

Comments
 (0)