Fixed all valid Clippy warnings. Removed deprecated method call.

This commit is contained in:
Sergio Benitez 2016-04-22 19:48:03 -07:00
parent d1a54e9c0e
commit 9db5f5811f
14 changed files with 71 additions and 72 deletions

View File

@ -62,7 +62,7 @@ impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Result<T, T::Error> {
pub fn form_items<'f>(string: &'f str, items: &mut [(&'f str, &'f str)]) -> usize { pub fn form_items<'f>(string: &'f str, items: &mut [(&'f str, &'f str)]) -> usize {
let mut param_num = 0; let mut param_num = 0;
let mut rest = string; let mut rest = string;
while rest.len() > 0 && param_num < items.len() { while !rest.is_empty() && param_num < items.len() {
let (key, remainder) = match rest.find('=') { let (key, remainder) = match rest.find('=') {
Some(index) => (&rest[..index], &rest[(index + 1)..]), Some(index) => (&rest[..index], &rest[(index + 1)..]),
None => return param_num None => return param_num

View File

@ -1,4 +1,4 @@
#![feature(str_char, question_mark)] #![feature(question_mark)]
#![feature(specialization)] #![feature(specialization)]
extern crate term_painter; extern crate term_painter;

View File

@ -20,16 +20,16 @@ pub enum Method {
impl Method { impl Method {
pub fn from_hyp(method: &HyperMethod) -> Option<Method> { pub fn from_hyp(method: &HyperMethod) -> Option<Method> {
match method { match *method {
&HyperMethod::Get => Some(Get), HyperMethod::Get => Some(Get),
&HyperMethod::Put => Some(Put), HyperMethod::Put => Some(Put),
&HyperMethod::Post => Some(Post), HyperMethod::Post => Some(Post),
&HyperMethod::Delete => Some(Delete), HyperMethod::Delete => Some(Delete),
&HyperMethod::Options => Some(Options), HyperMethod::Options => Some(Options),
&HyperMethod::Head => Some(Head), HyperMethod::Head => Some(Head),
&HyperMethod::Trace => Some(Trace), HyperMethod::Trace => Some(Trace),
&HyperMethod::Connect => Some(Connect), HyperMethod::Connect => Some(Connect),
&HyperMethod::Patch => Some(Patch), HyperMethod::Patch => Some(Patch),
_ => None _ => None
} }
} }

View File

@ -12,25 +12,23 @@ pub enum Outcome<'h> {
impl<'h> Outcome<'h> { impl<'h> Outcome<'h> {
pub fn as_str(&self) -> &'static str { pub fn as_str(&self) -> &'static str {
match self { match *self {
&Outcome::Complete => "Complete", Outcome::Complete => "Complete",
&Outcome::FailStop => "FailStop", Outcome::FailStop => "FailStop",
&Outcome::FailForward(..) => "FailForward", Outcome::FailForward(..) => "FailForward",
} }
} }
pub fn is_forward(&self) -> bool { pub fn is_forward(&self) -> bool {
match self { match *self {
&Outcome::FailForward(_) => true, Outcome::FailForward(_) => true,
_ => false _ => false
} }
} }
pub fn map_forward<F>(self, f: F) pub fn map_forward<F>(self, f: F) where F: FnOnce(FreshHyperResponse<'h>) {
where F: FnOnce(FreshHyperResponse<'h>) { if let Outcome::FailForward(res) = self {
match self { f(res)
Outcome::FailForward(res) => f(res),
_ => { /* nothing */ }
} }
} }
@ -51,10 +49,10 @@ impl<'h> Outcome<'h> {
} }
fn as_int(&self) -> isize { fn as_int(&self) -> isize {
match self { match *self {
&Outcome::Complete => 0, Outcome::Complete => 0,
&Outcome::FailStop => 1, Outcome::FailStop => 1,
&Outcome::FailForward(..) => 2, Outcome::FailForward(..) => 2,
} }
} }
} }
@ -73,14 +71,14 @@ impl<'h> fmt::Debug for Outcome<'h> {
impl<'h> fmt::Display for Outcome<'h> { impl<'h> fmt::Display for Outcome<'h> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match *self {
&Outcome::Complete => { Outcome::Complete => {
write!(f, "{}", Green.paint("Complete")) write!(f, "{}", Green.paint("Complete"))
}, },
&Outcome::FailStop => { Outcome::FailStop => {
write!(f, "{}", Red.paint("Failed")) write!(f, "{}", Red.paint("Failed"))
}, },
&Outcome::FailForward(..) => { Outcome::FailForward(..) => {
write!(f, "{}", Yellow.paint("Forwarding")) write!(f, "{}", Yellow.paint("Forwarding"))
}, },
} }

View File

@ -70,9 +70,9 @@ impl<T: Responder, E: fmt::Debug> Responder for Result<T, E> {
impl<T: Responder, E: Responder + fmt::Debug> Responder for Result<T, E> { impl<T: Responder, E: Responder + fmt::Debug> Responder for Result<T, E> {
fn respond<'a>(&mut self, res: FreshHyperResponse<'a>) -> Outcome<'a> { fn respond<'a>(&mut self, res: FreshHyperResponse<'a>) -> Outcome<'a> {
match self { match *self {
&mut Ok(ref mut responder) => responder.respond(res), Ok(ref mut responder) => responder.respond(res),
&mut Err(ref mut responder) => responder.respond(res) Err(ref mut responder) => responder.respond(res)
} }
} }
} }

View File

@ -21,15 +21,15 @@ pub struct Rocket {
} }
fn uri_is_absolute(uri: &HyperRequestUri) -> bool { fn uri_is_absolute(uri: &HyperRequestUri) -> bool {
match uri { match *uri {
&HyperRequestUri::AbsolutePath(_) => true, HyperRequestUri::AbsolutePath(_) => true,
_ => false _ => false
} }
} }
fn unwrap_absolute_path<'a>(uri: &'a HyperRequestUri) -> &'a str { fn unwrap_absolute_path(uri: &HyperRequestUri) -> &str {
match uri { match *uri {
&HyperRequestUri::AbsolutePath(ref s) => s.as_str(), HyperRequestUri::AbsolutePath(ref s) => s.as_str(),
_ => panic!("Can only accept absolute paths!") _ => panic!("Can only accept absolute paths!")
} }
} }
@ -61,7 +61,7 @@ impl HyperHandler for Rocket {
return finalize(req, res); return finalize(req, res);
} }
return self.dispatch(req, res); self.dispatch(req, res)
} }
} }

View File

@ -11,9 +11,10 @@ pub fn index_match_until(break_c: char, a: &str, b: &str, dir: bool)
(a_len - 1, b_len - 1, -1) (a_len - 1, b_len - 1, -1)
}; };
let break_b = break_c as u8;
while i >= 0 && j >= 0 && i < a_len && j < b_len { while i >= 0 && j >= 0 && i < a_len && j < b_len {
let (c1, c2) = (a.char_at(i as usize), b.char_at(j as usize)); let (c1, c2) = (a.as_bytes()[i as usize], b.as_bytes()[j as usize]);
if c1 == break_c || c2 == break_c { if c1 == break_b || c2 == break_b {
break; break;
} else if c1 != c2 { } else if c1 != c2 {
return None; return None;
@ -23,7 +24,7 @@ pub fn index_match_until(break_c: char, a: &str, b: &str, dir: bool)
} }
} }
return Some((i, j)); Some((i, j))
} }
fn do_match_until(break_c: char, a: &str, b: &str, dir: bool) -> bool { fn do_match_until(break_c: char, a: &str, b: &str, dir: bool) -> bool {

View File

@ -24,7 +24,7 @@ impl Router {
pub fn add(&mut self, route: Route) { pub fn add(&mut self, route: Route) {
let selector = (route.method, route.path.segment_count()); let selector = (route.method, route.path.segment_count());
self.routes.entry(selector).or_insert(vec![]).push(route); self.routes.entry(selector).or_insert_with(|| vec![]).push(route);
} }
// TODO: Make a `Router` trait with this function. Rename this `Router` // TODO: Make a `Router` trait with this function. Rename this `Router`
@ -56,9 +56,8 @@ impl Router {
pub fn has_collisions(&self) -> bool { pub fn has_collisions(&self) -> bool {
let mut result = false; let mut result = false;
for routes in self.routes.values() { for routes in self.routes.values() {
for i in 0..routes.len() { for (i, a_route) in routes.iter().enumerate() {
for j in (i + 1)..routes.len() { for b_route in routes.iter().skip(i + 1) {
let (a_route, b_route) = (&routes[i], &routes[j]);
if a_route.collides_with(b_route) { if a_route.collides_with(b_route) {
result = true; result = true;
println!("{} {} and {} collide!", println!("{} {} and {} collide!",

View File

@ -30,7 +30,7 @@ impl Route {
Route { Route {
method: m, method: m,
handler: handler, handler: handler,
rank: (!path.as_ref().contains("<") as isize), rank: (!path.as_ref().contains('<') as isize),
path: URIBuf::from(path.as_ref()), path: URIBuf::from(path.as_ref()),
} }
} }
@ -48,7 +48,7 @@ impl Route {
let mut result = Vec::with_capacity(self.path.segment_count()); let mut result = Vec::with_capacity(self.path.segment_count());
for (route_seg, uri_seg) in route_components.zip(uri_components) { for (route_seg, uri_seg) in route_components.zip(uri_components) {
if route_seg.starts_with("<") { // FIXME: Here. if route_seg.starts_with('<') { // FIXME: Here.
result.push(uri_seg); result.push(uri_seg);
} }
} }

View File

@ -64,21 +64,21 @@ impl URIBuf {
}) })
} }
pub fn segments<'a>(&'a self) -> Segments<'a> { pub fn segments(&self) -> Segments {
Segments(self.path.as_str()) Segments(self.path.as_str())
} }
fn as_uri_uncached<'a>(&'a self) -> URI<'a> { fn as_uri_uncached(&self) -> URI {
URI::new(self.path.as_str()) URI::new(self.path.as_str())
} }
pub fn as_uri<'a>(&'a self) -> URI<'a> { pub fn as_uri(&self) -> URI {
let mut uri = URI::new(self.path.as_str()); let mut uri = URI::new(self.path.as_str());
uri.segment_count = self.segment_count.clone(); uri.segment_count = self.segment_count.clone();
uri uri
} }
pub fn as_str<'a>(&'a self) -> &'a str { pub fn as_str(&self) -> &str {
self.path.as_str() self.path.as_str()
} }
@ -125,7 +125,7 @@ impl<'a> Collider for URI<'a> {
} }
} }
return true; true
} }
} }

View File

@ -18,8 +18,8 @@ static ONLY_STRUCTS_ERR: &'static str = "`FromForm` can only be derived for \
fn get_struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, span: Span) fn get_struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, span: Span)
-> Option<&'static str> { -> Option<&'static str> {
match item { match *item {
&Annotatable::Item(ref item) => match item.node { Annotatable::Item(ref item) => match item.node {
ItemKind::Struct(_, ref generics) => { ItemKind::Struct(_, ref generics) => {
match generics.lifetimes.len() { match generics.lifetimes.len() {
0 => None, 0 => None,
@ -110,9 +110,9 @@ fn from_form_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct
debug!("argument is: {:?}", arg); debug!("argument is: {:?}", arg);
// Ensure the the fields are from a 'StaticStruct' and extract them. // Ensure the the fields are from a 'StaticStruct' and extract them.
let fields = match substr.fields { let fields = match *substr.fields {
&StaticStruct(var_data, _) => match var_data { StaticStruct(var_data, _) => match *var_data {
&VariantData::Struct(ref fields, _) => fields, VariantData::Struct(ref fields, _) => fields,
_ => cx.span_fatal(trait_span, ONLY_STRUCTS_ERR) _ => cx.span_fatal(trait_span, ONLY_STRUCTS_ERR)
}, },
_ => cx.span_bug(trait_span, "impossible substructure in `from_form`") _ => cx.span_bug(trait_span, "impossible substructure in `from_form`")

View File

@ -40,10 +40,10 @@ fn bad_method_err(ecx: &mut ExtCtxt, dec_sp: Span, message: &str) -> Method {
pub fn get_fn_decl<'a>(ecx: &mut ExtCtxt, sp: Span, annotated: &'a Annotatable) pub fn get_fn_decl<'a>(ecx: &mut ExtCtxt, sp: Span, annotated: &'a Annotatable)
-> (&'a P<Item>, Spanned<&'a FnDecl>) { -> (&'a P<Item>, Spanned<&'a FnDecl>) {
// `annotated` is the AST object for the annotated item. // `annotated` is the AST object for the annotated item.
let item: &P<Item> = match annotated { let item: &P<Item> = match *annotated {
&Annotatable::Item(ref item) => item, Annotatable::Item(ref item) => item,
&Annotatable::TraitItem(ref item) => bad_item_fatal(ecx, sp, item.span), Annotatable::TraitItem(ref item) => bad_item_fatal(ecx, sp, item.span),
&Annotatable::ImplItem(ref item) => bad_item_fatal(ecx, sp, item.span) Annotatable::ImplItem(ref item) => bad_item_fatal(ecx, sp, item.span)
}; };
let fn_decl: &P<FnDecl> = match item.node { let fn_decl: &P<FnDecl> = match item.node {
@ -90,7 +90,7 @@ fn get_route_params(ecx: &mut ExtCtxt, meta_item: &MetaItem) -> Params {
// Ensure we have a path, just to keep parsing and generating errors. // Ensure we have a path, just to keep parsing and generating errors.
let path = kv_pairs.get("path").map_or(dummy_kvspan("/".to_string()), |s| { let path = kv_pairs.get("path").map_or(dummy_kvspan("/".to_string()), |s| {
s.clone().map(|str_string| String::from(str_string)) s.clone().map(String::from)
}); });
// If there's a form parameter, ensure method is POST. // If there's a form parameter, ensure method is POST.
@ -111,7 +111,7 @@ fn get_route_params(ecx: &mut ExtCtxt, meta_item: &MetaItem) -> Params {
ecx.span_err(f.p_span, "`form` must contain exactly one parameter"); ecx.span_err(f.p_span, "`form` must contain exactly one parameter");
} }
Some(f.clone().map(|str_string| String::from(str_string))) Some(f.clone().map(String::from))
}); });
Params { Params {
@ -157,7 +157,7 @@ pub fn gen_params_hashset<'a>(ecx: &ExtCtxt, params: &Spanned<&'a str>)
'>' if matching => { '>' if matching => {
matching = false; matching = false;
let mut param_span = params.span.clone(); let mut param_span = params.span;
param_span.lo = params.span.lo + BytePos(start as u32); param_span.lo = params.span.lo + BytePos(start as u32);
param_span.hi = params.span.lo + BytePos((i + 1) as u32); param_span.hi = params.span.lo + BytePos((i + 1) as u32);
@ -192,7 +192,7 @@ struct SimpleArg {
pub fn gen_kv_string_hashset<'a>(ecx: &ExtCtxt, params: &'a KVSpanned<String>) pub fn gen_kv_string_hashset<'a>(ecx: &ExtCtxt, params: &'a KVSpanned<String>)
-> HashSet<&'a str> { -> HashSet<&'a str> {
let mut param_span = params.v_span.clone(); let mut param_span = params.v_span;
param_span.lo = params.v_span.lo + BytePos(1); param_span.lo = params.v_span.lo + BytePos(1);
let params = Spanned { let params = Spanned {
span: param_span, span: param_span,
@ -254,7 +254,7 @@ fn get_fn_params<'a>(ecx: &ExtCtxt, dec_span: Span, path: &'a KVSpanned<String>,
ecx.span_err(dec_span, msg2.as_str()); ecx.span_err(dec_span, msg2.as_str());
} }
result.push(SimpleArg::new(name, arg.ty.clone(), arg.pat.span.clone())); result.push(SimpleArg::new(name, arg.ty.clone(), arg.pat.span));
} }
// Ensure every param in `path` and `exclude` is in the function declaration. // Ensure every param in `path` and `exclude` is in the function declaration.
@ -347,7 +347,7 @@ pub fn route_decorator(ecx: &mut ExtCtxt, sp: Span, meta_item: &MetaItem,
// Generate the statements that will attempt to parse forms during run-time. // Generate the statements that will attempt to parse forms during run-time.
// let form_span = route_params.form.map_or(DUMMY_SP, |f| f.span.clone()); // let form_span = route_params.form.map_or(DUMMY_SP, |f| f.span.clone());
let form_stmt = get_form_stmt(ecx, &mut fn_params, &mut form_param_hashset); let form_stmt = get_form_stmt(ecx, &mut fn_params, &form_param_hashset);
form_stmt.as_ref().map(|s| debug!("Form stmt: {:?}", stmt_to_string(s))); form_stmt.as_ref().map(|s| debug!("Form stmt: {:?}", stmt_to_string(s)));
// Generate the statements that will attempt to parse the paramaters during // Generate the statements that will attempt to parse the paramaters during

View File

@ -133,7 +133,7 @@ pub fn get_key_values<'b>(ecx: &mut ExtCtxt, sp: Span, required: &[&str],
kv_pairs kv_pairs
} }
pub fn token_separate<T: ToTokens>(ecx: &ExtCtxt, things: &Vec<T>, pub fn token_separate<T: ToTokens>(ecx: &ExtCtxt, things: &[T],
token: Token) -> Vec<TokenTree> { token: Token) -> Vec<TokenTree> {
let mut output: Vec<TokenTree> = vec![]; let mut output: Vec<TokenTree> = vec![];
for (i, thing) in things.iter().enumerate() { for (i, thing) in things.iter().enumerate() {
@ -164,8 +164,8 @@ impl MetaItemExt for MetaItemKind {
} }
fn get_list_items(&self) -> Option<&Vec<P<MetaItem>>> { fn get_list_items(&self) -> Option<&Vec<P<MetaItem>>> {
match self { match *self {
&MetaItemKind::List(_, ref params) => Some(params), MetaItemKind::List(_, ref params) => Some(params),
_ => None _ => None
} }
} }

View File

@ -14,6 +14,7 @@ function build_and_test() {
pushd ${dir} pushd ${dir}
echo ":: Building '${PWD}'..." echo ":: Building '${PWD}'..."
cargo clean
cargo build --verbose cargo build --verbose
echo ":: Running unit tests in '${PWD}'..." echo ":: Running unit tests in '${PWD}'..."