Skip to content

Commit 2bdd6f6

Browse files
Add checkup in tail function and return Option type
1 parent 9266d59 commit 2bdd6f6

File tree

8 files changed

+12
-10
lines changed

8 files changed

+12
-10
lines changed

Diff for: src/compiletest/compiletest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
9090

9191
assert!(!args.is_empty());
9292
let argv0 = args[0].clone();
93-
let args_ = args.tail();
93+
let args_ = args.tail().unwrap();
9494
if args[1] == "-h" || args[1] == "--help" {
9595
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
9696
println!("{}", getopts::usage(&message, &groups));

Diff for: src/libcollections/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<T> [T] {
462462
/// Returns all but the first element of a slice.
463463
#[unstable(feature = "collections", reason = "likely to be renamed")]
464464
#[inline]
465-
pub fn tail(&self) -> &[T] {
465+
pub fn tail(&self) -> Option<&[T]> {
466466
core_slice::SliceExt::tail(self)
467467
}
468468

Diff for: src/libcore/slice.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub trait SliceExt {
7878
fn chunks<'a>(&'a self, size: usize) -> Chunks<'a, Self::Item>;
7979
fn get<'a>(&'a self, index: usize) -> Option<&'a Self::Item>;
8080
fn first<'a>(&'a self) -> Option<&'a Self::Item>;
81-
fn tail<'a>(&'a self) -> &'a [Self::Item];
81+
fn tail<'a>(&'a self) -> Option<&'a [Self::Item]>;
8282
fn init<'a>(&'a self) -> &'a [Self::Item];
8383
fn last<'a>(&'a self) -> Option<&'a Self::Item>;
8484
unsafe fn get_unchecked<'a>(&'a self, index: usize) -> &'a Self::Item;
@@ -207,7 +207,9 @@ impl<T> SliceExt for [T] {
207207
}
208208

209209
#[inline]
210-
fn tail(&self) -> &[T] { &self[1..] }
210+
fn tail(&self) -> Option<&[T]> {
211+
if self.len() == 0 { None } else { Some(&self[1..]) }
212+
}
211213

212214
#[inline]
213215
fn init(&self) -> &[T] {

Diff for: src/librustc/middle/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ fn is_useful(cx: &MatchCheckCtxt,
693693
Some(constructor) => {
694694
let matrix = rows.iter().filter_map(|r| {
695695
if pat_is_binding_or_wild(&cx.tcx.def_map, raw_pat(r[0])) {
696-
Some(r.tail().to_vec())
696+
Some(r.tail().unwrap().to_vec())
697697
} else {
698698
None
699699
}
700700
}).collect();
701-
match is_useful(cx, &matrix, v.tail(), witness) {
701+
match is_useful(cx, &matrix, v.tail().unwrap(), witness) {
702702
UsefulWithWitness(pats) => {
703703
let arity = constructor_arity(cx, &constructor, left_ty);
704704
let wild_pats: Vec<_> = repeat(DUMMY_WILD_PAT).take(arity).collect();

Diff for: src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub fn usage(argv0: &str) {
192192
}
193193

194194
pub fn main_args(args: &[String]) -> isize {
195-
let matches = match getopts::getopts(args.tail(), &opts()) {
195+
let matches = match getopts::getopts(args.tail().unwrap(), &opts()) {
196196
Ok(m) => m,
197197
Err(err) => {
198198
println!("{}", err);

Diff for: src/librustdoc/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub fn unindent(s: &str) -> String {
352352

353353
if lines.len() >= 1 {
354354
let mut unindented = vec![ lines[0].trim().to_string() ];
355-
unindented.push_all(&lines.tail().iter().map(|&line| {
355+
unindented.push_all(&lines.tail().unwrap().iter().map(|&line| {
356356
if line.chars().all(|c| c.is_whitespace()) {
357357
line.to_string()
358358
} else {

Diff for: src/libsyntax/ext/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ impl<'a> MethodDef<'a> {
10811081
subpats.push(p);
10821082
idents
10831083
};
1084-
for self_arg_name in self_arg_names.tail() {
1084+
for self_arg_name in self_arg_names.tail().unwrap() {
10851085
let (p, idents) = mk_self_pat(cx, &self_arg_name[..]);
10861086
subpats.push(p);
10871087
self_pats_idents.push(idents);

Diff for: src/libtest/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Test Attributes:
364364

365365
// Parses command line arguments into test options
366366
pub fn parse_opts(args: &[String]) -> Option<OptRes> {
367-
let args_ = args.tail();
367+
let args_ = args.tail().unwrap();
368368
let matches =
369369
match getopts::getopts(args_, &optgroups()) {
370370
Ok(m) => m,

0 commit comments

Comments
 (0)