diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index f00ff9bcbe5e5..1ad841d1274be 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -90,7 +90,7 @@ pub fn parse_config(args: Vec ) -> Config { assert!(!args.is_empty()); let argv0 = args[0].clone(); - let args_ = args.tail(); + let args_ = args.tail().unwrap(); if args[1] == "-h" || args[1] == "--help" { let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0); println!("{}", getopts::usage(&message, &groups)); diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 8622b8cd93568..be19ec2cc0200 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -462,7 +462,7 @@ impl [T] { /// Returns all but the first element of a slice. #[unstable(feature = "collections", reason = "likely to be renamed")] #[inline] - pub fn tail(&self) -> &[T] { + pub fn tail(&self) -> Option<&[T]> { core_slice::SliceExt::tail(self) } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 70e60adf64c2a..76a2339c3e535 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -78,7 +78,7 @@ pub trait SliceExt { fn chunks<'a>(&'a self, size: usize) -> Chunks<'a, Self::Item>; fn get<'a>(&'a self, index: usize) -> Option<&'a Self::Item>; fn first<'a>(&'a self) -> Option<&'a Self::Item>; - fn tail<'a>(&'a self) -> &'a [Self::Item]; + fn tail<'a>(&'a self) -> Option<&'a [Self::Item]>; fn init<'a>(&'a self) -> &'a [Self::Item]; fn last<'a>(&'a self) -> Option<&'a Self::Item>; unsafe fn get_unchecked<'a>(&'a self, index: usize) -> &'a Self::Item; @@ -207,7 +207,9 @@ impl SliceExt for [T] { } #[inline] - fn tail(&self) -> &[T] { &self[1..] } + fn tail(&self) -> Option<&[T]> { + if self.len() == 0 { None } else { Some(&self[1..]) } + } #[inline] fn init(&self) -> &[T] { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 14df040fb79ed..f401f307c11a1 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -693,12 +693,12 @@ fn is_useful(cx: &MatchCheckCtxt, Some(constructor) => { let matrix = rows.iter().filter_map(|r| { if pat_is_binding_or_wild(&cx.tcx.def_map, raw_pat(r[0])) { - Some(r.tail().to_vec()) + Some(r.tail().unwrap().to_vec()) } else { None } }).collect(); - match is_useful(cx, &matrix, v.tail(), witness) { + match is_useful(cx, &matrix, v.tail().unwrap(), witness) { UsefulWithWitness(pats) => { let arity = constructor_arity(cx, &constructor, left_ty); let wild_pats: Vec<_> = repeat(DUMMY_WILD_PAT).take(arity).collect(); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index bdee53cd00964..00a2a236c5552 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -192,7 +192,7 @@ pub fn usage(argv0: &str) { } pub fn main_args(args: &[String]) -> isize { - let matches = match getopts::getopts(args.tail(), &opts()) { + let matches = match getopts::getopts(args.tail().unwrap(), &opts()) { Ok(m) => m, Err(err) => { println!("{}", err); diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 953b442bb3ceb..0bc82332c8525 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -352,7 +352,7 @@ pub fn unindent(s: &str) -> String { if lines.len() >= 1 { let mut unindented = vec![ lines[0].trim().to_string() ]; - unindented.push_all(&lines.tail().iter().map(|&line| { + unindented.push_all(&lines.tail().unwrap().iter().map(|&line| { if line.chars().all(|c| c.is_whitespace()) { line.to_string() } else { diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 397775fdbfec3..f46b9cc6e9ecc 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1081,7 +1081,7 @@ impl<'a> MethodDef<'a> { subpats.push(p); idents }; - for self_arg_name in self_arg_names.tail() { + for self_arg_name in self_arg_names.tail().unwrap() { let (p, idents) = mk_self_pat(cx, &self_arg_name[..]); subpats.push(p); self_pats_idents.push(idents); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index c84703b93ed26..fe5c51757f9ae 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -364,7 +364,7 @@ Test Attributes: // Parses command line arguments into test options pub fn parse_opts(args: &[String]) -> Option { - let args_ = args.tail(); + let args_ = args.tail().unwrap(); let matches = match getopts::getopts(args_, &optgroups()) { Ok(m) => m,