Skip to content

Add checkup in tail function and return Option type #24172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn parse_config(args: Vec<String> ) -> 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));
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<T> [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)
}

Expand Down
6 changes: 4 additions & 2 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -207,7 +207,9 @@ impl<T> 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] {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Test Attributes:

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