Skip to content

Commit

Permalink
Apply more Clippy suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sstangl authored and SergioBenitez committed Aug 12, 2018
1 parent 0612c64 commit 9bf5854
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 45 deletions.
10 changes: 5 additions & 5 deletions contrib/lib/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/lib/src/msgpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion contrib/lib/src/templates/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/lib/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion contrib/lib/src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 4 additions & 6 deletions core/codegen/src/decorators/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions core/lib/src/catcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions core/lib/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl Config {
tls: None,
limits: Limits::default(),
extras: HashMap::new(),
config_path: config_path,
config_path,
}
}
Staging => {
Expand All @@ -264,7 +264,7 @@ impl Config {
tls: None,
limits: Limits::default(),
extras: HashMap::new(),
config_path: config_path,
config_path,
}
}
Production => {
Expand All @@ -279,7 +279,7 @@ impl Config {
tls: None,
limits: Limits::default(),
extras: HashMap::new(),
config_path: config_path,
config_path,
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions core/lib/src/config/custom_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/config/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 1 addition & 4 deletions core/lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions core/lib/src/data/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 1 addition & 4 deletions core/lib/src/request/form/form_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/request/form/lenient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion core/lib/src/rocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl Rocket {
}

Rocket {
config: config,
config,
router: Router::new(),
default_catchers: catcher::defaults::get(),
catchers: catcher::defaults::get(),
Expand Down
2 changes: 1 addition & 1 deletion examples/pastebin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>")]
Expand Down
2 changes: 1 addition & 1 deletion examples/pastebin/src/paste_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>);
Expand Down
2 changes: 1 addition & 1 deletion examples/stream/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand Down
2 changes: 1 addition & 1 deletion examples/uuid/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9bf5854

Please sign in to comment.