From 2be02ca4eb453d5946f40ce3220b96e33e39bdb3 Mon Sep 17 00:00:00 2001 From: Josh Holmer Date: Wed, 4 Jan 2017 21:00:26 -0500 Subject: [PATCH] Fix clippy lints within rocket_codegen Some of these warnings were in code that rocket's macros would produce, and so would also produce extraneous clippy warnings in crates using rocket's macros. --- codegen/src/decorators/error.rs | 4 ++-- codegen/src/decorators/route.rs | 6 +++--- codegen/src/parser/function.rs | 2 +- codegen/src/parser/param.rs | 18 ++++++++++-------- codegen/src/parser/route.rs | 9 ++++----- codegen/tests/tests.rs | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/codegen/src/decorators/error.rs b/codegen/src/decorators/error.rs index 6b57d5c5..f1b2af71 100644 --- a/codegen/src/decorators/error.rs +++ b/codegen/src/decorators/error.rs @@ -32,8 +32,8 @@ impl ErrorGenerateExt for ErrorParams { // (Imperfectly) inspect the types to figure which params to pass in. let args = input_args.iter().map(|arg| &arg.ty).filter_map(|ty| { match ty.node { - TyKind::Rptr(..) => Some(req.clone()), - TyKind::Path(..) => Some(err.clone()), + TyKind::Rptr(..) => Some(req), + TyKind::Path(..) => Some(err), _ => { ecx.struct_span_err(ty.span, "unexpected error handler argument") .help(arg_help).emit(); diff --git a/codegen/src/decorators/route.rs b/codegen/src/decorators/route.rs index c82967ef..f9a31ea0 100644 --- a/codegen/src/decorators/route.rs +++ b/codegen/src/decorators/route.rs @@ -58,7 +58,7 @@ impl RouteGenerateExt for RouteParams { if param.is_none() { return None; } else if arg.is_none() { - self.missing_declared_err(ecx, ¶m.unwrap()); + self.missing_declared_err(ecx, param.unwrap()); return None; } @@ -80,7 +80,7 @@ impl RouteGenerateExt for RouteParams { if param.is_none() { return None; } else if arg.is_none() { - self.missing_declared_err(ecx, ¶m.unwrap()); + self.missing_declared_err(ecx, param.unwrap()); return None; } @@ -120,7 +120,7 @@ impl RouteGenerateExt for RouteParams { // Generate a statement for every declared paramter in the path. let mut declared_set = HashSet::new(); for (i, param) in self.path_params(ecx).enumerate() { - declared_set.insert(param.ident().name.clone()); + declared_set.insert(param.ident().name); let ty = match self.annotated_fn.find_input(¶m.ident().name) { Some(arg) => strip_ty_lifetimes(arg.ty.clone()), None => { diff --git a/codegen/src/parser/function.rs b/codegen/src/parser/function.rs index d57f763e..418d43b9 100644 --- a/codegen/src/parser/function.rs +++ b/codegen/src/parser/function.rs @@ -35,7 +35,7 @@ impl Function { } pub fn find_input<'a>(&'a self, name: &Name) -> Option<&'a Arg> { - self.decl().inputs.iter().filter(|arg| arg.named(name)).next() + self.decl().inputs.iter().find(|arg| arg.named(name)) } } diff --git a/codegen/src/parser/param.rs b/codegen/src/parser/param.rs index ee1c5aee..6bc9dea2 100644 --- a/codegen/src/parser/param.rs +++ b/codegen/src/parser/param.rs @@ -46,7 +46,7 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> { fn next(&mut self) -> Option { let err = |ecx: &ExtCtxt, sp: Span, msg: &str| { ecx.span_err(sp, msg); - return None; + None }; // Find the start and end indexes for the next parameter, if any. @@ -65,9 +65,10 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> { // Calculate the parameter's ident. let full_param = &self.string[(start + 1)..end]; - let (is_many, param) = match full_param.ends_with("..") { - true => (true, &full_param[..(full_param.len() - 2)]), - false => (false, full_param) + let (is_many, param) = if full_param.ends_with("..") { + (true, &full_param[..(full_param.len() - 2)]) + } else { + (false, full_param) }; let mut param_span = self.span; @@ -83,7 +84,7 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> { err(self.ctxt, param_span, "parameter names cannot be empty") } else if !is_valid_ident(param) { err(self.ctxt, param_span, "parameter names must be valid identifiers") - } else if param.starts_with("_") { + } else if param.starts_with('_') { err(self.ctxt, param_span, "parameters cannot be ignored") } else if is_many && !self.string.is_empty() { let sp = self.span.shorten_to(self.string.len()); @@ -93,9 +94,10 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> { None } else { let spanned_ident = span(Ident::from_str(param), param_span); - match is_many { - true => Some(Param::Many(spanned_ident)), - false => Some(Param::Single(spanned_ident)) + if is_many { + Some(Param::Many(spanned_ident)) + } else { + Some(Param::Single(spanned_ident)) } } diff --git a/codegen/src/parser/route.rs b/codegen/src/parser/route.rs index fd74f0eb..eb4eed23 100644 --- a/codegen/src/parser/route.rs +++ b/codegen/src/parser/route.rs @@ -75,7 +75,7 @@ impl RouteParams { let mut seen_keys = HashSet::new(); let (mut rank, mut data, mut format) = Default::default(); for param in &attr_params[1..] { - let kv_opt = kv_from_nested(¶m); + let kv_opt = kv_from_nested(param); if kv_opt.is_none() { ecx.span_err(param.span(), "expected key = value"); continue; @@ -183,7 +183,7 @@ fn parse_method(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned { .help("valid methods are: GET, PUT, POST, DELETE, PATCH") .emit(); - return dummy_spanned(Method::Get); + dummy_spanned(Method::Get) } fn parse_path(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> (Spanned, Option>) { @@ -230,9 +230,8 @@ fn parse_data(ecx: &ExtCtxt, kv: &KVSpanned) -> Ident { let mut ident = Ident::from_str("unknown"); if let LitKind::Str(ref s, _) = *kv.value() { ident = Ident::from_str(&s.as_str()); - match param_string_to_ident(ecx, span(&s.as_str(), kv.value.span)) { - Some(ident) => return ident, - _ => { /* fall through if not an ident */ } + if let Some(ident) = param_string_to_ident(ecx, span(&s.as_str(), kv.value.span)) { + return ident; } } diff --git a/codegen/tests/tests.rs b/codegen/tests/tests.rs index 81ba66ec..fb6767f5 100644 --- a/codegen/tests/tests.rs +++ b/codegen/tests/tests.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; fn run_mode(mode: &'static str) { let mut config = compiletest::default_config(); - let cfg_mode = mode.parse().ok().expect("Invalid mode"); + let cfg_mode = mode.parse().expect("Invalid mode"); config.mode = cfg_mode; config.src_base = PathBuf::from(format!("tests/{}", mode));