Apply more Clippy suggestions.

This commit is contained in:
Sean Stangl 2018-07-28 09:58:10 -07:00 committed by Sergio Benitez
parent 0612c644ad
commit 9bf585496c
20 changed files with 33 additions and 45 deletions

View File

@ -113,7 +113,7 @@ impl<T: DeserializeOwned> FromData for Json<T> {
let size_limit = request.limits().get("json").unwrap_or(LIMIT);
from_reader_eager(data.open().take(size_limit))
.map(|val| Json(val))
.map(Json)
.map_err(|e| { error_!("Couldn't parse JSON body: {:?}", e); e })
.into_outcome(Status::BadRequest)
}
@ -137,14 +137,14 @@ impl<T> Deref for Json<T> {
type Target = T;
#[inline(always)]
fn deref<'a>(&'a self) -> &'a T {
fn deref(&self) -> &T {
&self.0
}
}
impl<T> DerefMut for Json<T> {
#[inline(always)]
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}
@ -208,14 +208,14 @@ impl Deref for JsonValue {
type Target = serde_json::Value;
#[inline(always)]
fn deref<'a>(&'a self) -> &'a Self::Target {
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for JsonValue {
#[inline(always)]
fn deref_mut<'a>(&'a mut self) -> &'a mut Self::Target {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

View File

@ -135,7 +135,7 @@ impl<T: DeserializeOwned> FromData for MsgPack<T> {
return Outcome::Failure((Status::BadRequest, e));
};
rmp_serde::from_slice(&buf).map(|val| MsgPack(val))
rmp_serde::from_slice(&buf).map(MsgPack)
.map_err(|e| { error_!("Couldn't parse MessagePack body: {:?}", e); e })
.into_outcome(Status::BadRequest)
}
@ -161,14 +161,14 @@ impl<T> Deref for MsgPack<T> {
type Target = T;
#[inline(always)]
fn deref<'a>(&'a self) -> &'a T {
fn deref(&self) -> &T {
&self.0
}
}
impl<T> DerefMut for MsgPack<T> {
#[inline(always)]
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}

View File

@ -43,7 +43,7 @@ impl Context {
templates.insert(name, TemplateInfo {
path: path.to_path_buf(),
extension: ext.to_string(),
data_type: data_type,
data_type,
});
}
}

View File

@ -29,7 +29,7 @@ use rocket::fairing::Fairing;
use rocket::response::{self, Content, Responder};
use rocket::http::{ContentType, Status};
const DEFAULT_TEMPLATE_DIR: &'static str = "templates";
const DEFAULT_TEMPLATE_DIR: &str = "templates";
/// The Template type implements generic support for template rendering in
/// Rocket.

View File

@ -110,7 +110,7 @@ impl FromStr for Uuid {
impl Deref for Uuid {
type Target = uuid_ext::Uuid;
fn deref<'a>(&'a self) -> &'a Self::Target {
fn deref(&self) -> &Self::Target {
&self.0
}
}

View File

@ -87,12 +87,10 @@ impl RouteParams {
}
fn generate_data_statement(&self, ecx: &ExtCtxt) -> Option<Stmt> {
let param = self.data_param.as_ref().map(|p| &p.value);
let arg = param.and_then(|p| self.annotated_fn.find_input(&p.node.name));
if param.is_none() {
return None;
} else if arg.is_none() {
self.missing_declared_err(ecx, param.unwrap());
let param = self.data_param.as_ref().map(|p| &p.value)?;
let arg = self.annotated_fn.find_input(&param.node.name);
if arg.is_none() {
self.missing_declared_err(ecx, param);
return None;
}

View File

@ -95,7 +95,7 @@ impl Catcher {
/// ```
#[inline(always)]
pub fn new(code: u16, handler: ErrorHandler) -> Catcher {
Catcher { code: code, handler: handler, is_default: false }
Catcher { code, handler, is_default: false }
}
#[inline(always)]
@ -105,7 +105,7 @@ impl Catcher {
#[inline(always)]
fn new_default(code: u16, handler: ErrorHandler) -> Catcher {
Catcher { code: code, handler: handler, is_default: true, }
Catcher { code, handler, is_default: true, }
}
#[inline(always)]

View File

@ -249,7 +249,7 @@ impl Config {
tls: None,
limits: Limits::default(),
extras: HashMap::new(),
config_path: config_path,
config_path,
}
}
Staging => {
@ -264,7 +264,7 @@ impl Config {
tls: None,
limits: Limits::default(),
extras: HashMap::new(),
config_path: config_path,
config_path,
}
}
Production => {
@ -279,7 +279,7 @@ impl Config {
tls: None,
limits: Limits::default(),
extras: HashMap::new(),
config_path: config_path,
config_path,
}
}
})

View File

@ -129,7 +129,7 @@ impl Limits {
"forms" => self.forms = limit,
_ => {
let mut found = false;
for tuple in self.extra.iter_mut() {
for tuple in &mut self.extra {
if tuple.0 == name {
tuple.1 = limit;
found = true;
@ -199,7 +199,7 @@ impl fmt::Display for Limits {
}
pub fn str<'a>(conf: &Config, name: &str, v: &'a Value) -> Result<&'a str> {
v.as_str().ok_or(conf.bad_type(name, v.type_str(), "a string"))
v.as_str().ok_or_else(|| conf.bad_type(name, v.type_str(), "a string"))
}
pub fn u64(conf: &Config, name: &str, value: &Value) -> Result<u64> {

View File

@ -6,7 +6,7 @@ use std::env;
use self::Environment::*;
pub const CONFIG_ENV: &'static str = "ROCKET_ENV";
pub const CONFIG_ENV: &str = "ROCKET_ENV";
/// An enum corresponding to the valid configuration environments.
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy)]

View File

@ -262,10 +262,7 @@ impl RocketConfig {
configs.insert(Production, Config::default(Production, &f).unwrap());
configs.insert(active_env, config);
RocketConfig {
active_env: active_env,
config: configs
}
RocketConfig { active_env, config: configs }
}
/// Read the configuration from the `Rocket.toml` file. The file is search

View File

@ -260,11 +260,7 @@ impl Data {
};
trace_!("Peek bytes: {}/{} bytes.", peek_buf.len(), PEEK_BYTES);
Data {
buffer: peek_buf,
stream: stream,
is_complete: eof,
}
Data { buffer: peek_buf, stream, is_complete: eof }
}
/// This creates a `data` object from a local data source `data`.

View File

@ -99,7 +99,7 @@ pub struct LaunchError {
impl LaunchError {
#[inline(always)]
crate fn new(kind: LaunchErrorKind) -> LaunchError {
LaunchError { handled: AtomicBool::new(false), kind: kind }
LaunchError { handled: AtomicBool::new(false), kind }
}
#[inline(always)]

View File

@ -197,10 +197,7 @@ impl<'f> From<&'f RawStr> for FormItems<'f> {
/// `x-www-form-urlencoded` form `string`.
#[inline(always)]
fn from(string: &'f RawStr) -> FormItems<'f> {
FormItems {
string: string,
next_index: 0
}
FormItems { string, next_index: 0 }
}
}

View File

@ -161,6 +161,6 @@ impl<'f, T: FromForm<'f>> FromData for LenientForm<'f, T> where T::Error: Debug
/// logging format.
#[inline]
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, Self::Error> {
super::from_data(request, data, false).map(|form| LenientForm(form))
super::from_data(request, data, false).map(LenientForm)
}
}

View File

@ -427,7 +427,7 @@ impl Rocket {
}
Rocket {
config: config,
config,
router: Router::new(),
default_catchers: catcher::defaults::get(),
catchers: catcher::defaults::get(),

View File

@ -16,7 +16,7 @@ use rocket::response::content;
use paste_id::PasteID;
const HOST: &'static str = "http://localhost:8000";
const HOST: &str = "http://localhost:8000";
const ID_LENGTH: usize = 3;
#[post("/", data = "<paste>")]

View File

@ -6,7 +6,7 @@ use rocket::http::RawStr;
use rand::{self, Rng};
/// Table to retrieve base62 values from.
const BASE62: &'static [u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const BASE62: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/// A _probably_ unique paste ID.
pub struct PasteID<'a>(Cow<'a, str>);

View File

@ -13,7 +13,7 @@ use std::fs::File;
type LimitedRepeat = Take<Repeat>;
// Generate this file using: head -c BYTES /dev/random > big_file.dat
const FILENAME: &'static str = "big_file.dat";
const FILENAME: &str = "big_file.dat";
#[get("/")]
fn root() -> content::Plain<Stream<LimitedRepeat>> {

View File

@ -35,7 +35,7 @@ fn people(id: Uuid) -> Result<String, String> {
// rocket_contrib::Uuid to uuid::Uuid.
Ok(PEOPLE.get(&id)
.map(|person| format!("We found: {}", person))
.ok_or(format!("Person not found for UUID: {}", id))?)
.ok_or_else(|| format!("Person not found for UUID: {}", id))?)
}
fn rocket() -> rocket::Rocket {