From 5bbbf610828e975fd308b90543359a85ef59b67f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 1 Dec 2018 17:49:30 -0800 Subject: lint: Resolve the easier clippy lints Hopefully the changes are self-explanatory and uncontroversial. This eliminates much of the noise from `cargo clippy` and, for my purposes, gives me a reasonable way to use it as a tool when writing and reviewing code. Here is the Clippy invocation I was using: cargo +nightly clippy -- -W clippy::correctness -A renamed_and_removed_lints -Aclippy::{blacklisted_name,borrowed_box,cast_lossless,cast_ptr_alignment,enum_variant_names,identity_op,if_same_then_else,mut_from_ref,needless_pass_by_value,new_without_default,new_without_default_derive,or_fun_call,ptr_arg,should_implement_trait,single_match,too_many_arguments,trivially_copy_pass_by_ref,unreadable_literal,unsafe_vector_initialization,useless_transmute} TEST=cargo check --features wl-dmabuf,gpu,usb-emulation TEST=boot linux Change-Id: I55eb1b4a72beb2f762480e3333a921909314a0a2 Reviewed-on: https://chromium-review.googlesource.com/1356911 Commit-Ready: David Tolnay Tested-by: David Tolnay Reviewed-by: Dylan Reid --- src/argument.rs | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/argument.rs') diff --git a/src/argument.rs b/src/argument.rs index edcaadc..baadb02 100644 --- a/src/argument.rs +++ b/src/argument.rs @@ -67,16 +67,15 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - &Error::Syntax(ref s) => write!(f, "syntax error: {}", s), - &Error::UnknownArgument(ref s) => write!(f, "unknown argument: {}", s), - &Error::ExpectedArgument(ref s) => write!(f, "expected argument: {}", s), - &Error::InvalidValue { - ref value, - expected, - } => write!(f, "invalid value {:?}: {}", value, expected), - &Error::TooManyArguments(ref s) => write!(f, "too many arguments: {}", s), - &Error::ExpectedValue(ref s) => write!(f, "expected parameter value: {}", s), - &Error::PrintHelp => write!(f, "help was requested"), + Error::Syntax(s) => write!(f, "syntax error: {}", s), + Error::UnknownArgument(s) => write!(f, "unknown argument: {}", s), + Error::ExpectedArgument(s) => write!(f, "expected argument: {}", s), + Error::InvalidValue { value, expected } => { + write!(f, "invalid value {:?}: {}", value, expected) + } + Error::TooManyArguments(s) => write!(f, "too many arguments: {}", s), + Error::ExpectedValue(s) => write!(f, "expected parameter value: {}", s), + Error::PrintHelp => write!(f, "help was requested"), } } } @@ -217,20 +216,18 @@ where } f(name, Some(value))?; State::Top - } else { - if let Err(e) = f(param, None) { - if let Error::ExpectedValue(_) = e { - State::Value { - name: param.to_owned(), - } - } else { - return Err(e); + } else if let Err(e) = f(param, None) { + if let Error::ExpectedValue(_) = e { + State::Value { + name: param.to_owned(), } } else { - State::Top + return Err(e); } + } else { + State::Top } - } else if arg.starts_with("-") { + } else if arg.starts_with('-') { if arg.len() == 1 { return Err(Error::Syntax( "expected argument short name after `-`".to_owned(), -- cgit 1.4.1