Skip to content

Commit

Permalink
Deny rust_2018_idioms lints in all crates except for examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
jebrosen committed May 25, 2019
1 parent 1f46b9f commit b7f39ec
Show file tree
Hide file tree
Showing 82 changed files with 286 additions and 297 deletions.
3 changes: 2 additions & 1 deletion contrib/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![feature(crate_visibility_modifier)]
#![recursion_limit="256"]

#![deny(rust_2018_idioms)]

//! # Rocket Contrib - Code Generation
//! This crate implements the code generation portion of the Rocket Contrib
//! crate. This is for officially sanctioned contributor libraries that require
Expand All @@ -24,7 +26,6 @@
//! DATABASE_NAME := (string literal)
//! </pre>
extern crate devise;
extern crate proc_macro;

#[allow(unused_imports)]
Expand Down
4 changes: 2 additions & 2 deletions contrib/lib/src/compression/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ impl Fairing for Compression {
Ok(rocket.manage(ctxt))
}

fn on_response(&self, request: &Request, response: &mut Response) {
fn on_response(&self, request: &Request<'_>, response: &mut Response<'_>) {
let context = request
.guard::<::rocket::State<Context>>()
.guard::<::rocket::State<'_, Context>>()
.expect("Compression Context registered in on_attach");

super::CompressionUtils::compress_response(request, response, &context.exclusions);
Expand Down
6 changes: 3 additions & 3 deletions contrib/lib/src/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use self::flate2::read::GzEncoder;
struct CompressionUtils;

impl CompressionUtils {
fn accepts_encoding(request: &Request, encoding: &str) -> bool {
fn accepts_encoding(request: &Request<'_>, encoding: &str) -> bool {
request
.headers()
.get("Accept-Encoding")
Expand All @@ -55,7 +55,7 @@ impl CompressionUtils {
.any(|accept| accept == encoding)
}

fn already_encoded(response: &Response) -> bool {
fn already_encoded(response: &Response<'_>) -> bool {
response.headers().get("Content-Encoding").next().is_some()
}

Expand Down Expand Up @@ -84,7 +84,7 @@ impl CompressionUtils {
}
}

fn compress_response(request: &Request, response: &mut Response, exclusions: &[MediaType]) {
fn compress_response(request: &Request<'_>, response: &mut Response<'_>, exclusions: &[MediaType]) {
if CompressionUtils::already_encoded(response) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/lib/src/compression/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Compress<R>(pub R);

impl<'r, R: Responder<'r>> Responder<'r> for Compress<R> {
#[inline(always)]
fn respond_to(self, request: &Request) -> response::Result<'r> {
fn respond_to(self, request: &Request<'_>) -> response::Result<'r> {
let mut response = Response::build()
.merge(self.0.respond_to(request)?)
.finalize();
Expand Down
26 changes: 13 additions & 13 deletions contrib/lib/src/databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
//! [request guards]: rocket::request::FromRequest
//! [`Poolable`]: databases::Poolable
pub extern crate r2d2;
pub use r2d2;

#[cfg(any(feature = "diesel_sqlite_pool",
feature = "diesel_postgres_pool",
Expand Down Expand Up @@ -594,7 +594,7 @@ pub fn database_config<'a>(
}

impl<'a> Display for ConfigError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
ConfigError::MissingTable => {
write!(f, "A table named `databases` was not found for this configuration")
Expand Down Expand Up @@ -717,15 +717,15 @@ pub trait Poolable: Send + Sized + 'static {

/// Creates an `r2d2` connection pool for `Manager::Connection`, returning
/// the pool on success.
fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error>;
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error>;
}

#[cfg(feature = "diesel_sqlite_pool")]
impl Poolable for diesel::SqliteConnection {
type Manager = diesel::r2d2::ConnectionManager<diesel::SqliteConnection>;
type Error = r2d2::Error;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = diesel::r2d2::ConnectionManager::new(config.url);
r2d2::Pool::builder().max_size(config.pool_size).build(manager)
}
Expand All @@ -736,7 +736,7 @@ impl Poolable for diesel::PgConnection {
type Manager = diesel::r2d2::ConnectionManager<diesel::PgConnection>;
type Error = r2d2::Error;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = diesel::r2d2::ConnectionManager::new(config.url);
r2d2::Pool::builder().max_size(config.pool_size).build(manager)
}
Expand All @@ -747,7 +747,7 @@ impl Poolable for diesel::MysqlConnection {
type Manager = diesel::r2d2::ConnectionManager<diesel::MysqlConnection>;
type Error = r2d2::Error;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = diesel::r2d2::ConnectionManager::new(config.url);
r2d2::Pool::builder().max_size(config.pool_size).build(manager)
}
Expand All @@ -759,7 +759,7 @@ impl Poolable for postgres::Connection {
type Manager = r2d2_postgres::PostgresConnectionManager;
type Error = DbError<postgres::Error>;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = r2d2_postgres::PostgresConnectionManager::new(config.url, r2d2_postgres::TlsMode::None)
.map_err(DbError::Custom)?;

Expand All @@ -773,7 +773,7 @@ impl Poolable for mysql::Conn {
type Manager = r2d2_mysql::MysqlConnectionManager;
type Error = r2d2::Error;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let opts = mysql::OptsBuilder::from_opts(config.url);
let manager = r2d2_mysql::MysqlConnectionManager::new(opts);
r2d2::Pool::builder().max_size(config.pool_size).build(manager)
Expand All @@ -785,7 +785,7 @@ impl Poolable for rusqlite::Connection {
type Manager = r2d2_sqlite::SqliteConnectionManager;
type Error = r2d2::Error;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = r2d2_sqlite::SqliteConnectionManager::file(config.url);

r2d2::Pool::builder().max_size(config.pool_size).build(manager)
Expand All @@ -797,7 +797,7 @@ impl Poolable for rusted_cypher::GraphClient {
type Manager = r2d2_cypher::CypherConnectionManager;
type Error = r2d2::Error;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = r2d2_cypher::CypherConnectionManager { url: config.url.to_string() };
r2d2::Pool::builder().max_size(config.pool_size).build(manager)
}
Expand All @@ -808,7 +808,7 @@ impl Poolable for redis::Connection {
type Manager = r2d2_redis::RedisConnectionManager;
type Error = DbError<redis::RedisError>;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = r2d2_redis::RedisConnectionManager::new(config.url).map_err(DbError::Custom)?;
r2d2::Pool::builder().max_size(config.pool_size).build(manager)
.map_err(DbError::PoolError)
Expand All @@ -820,7 +820,7 @@ impl Poolable for mongodb::db::Database {
type Manager = r2d2_mongodb::MongodbConnectionManager;
type Error = DbError<mongodb::Error>;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = r2d2_mongodb::MongodbConnectionManager::new_with_uri(config.url).map_err(DbError::Custom)?;
r2d2::Pool::builder().max_size(config.pool_size).build(manager).map_err(DbError::PoolError)
}
Expand All @@ -831,7 +831,7 @@ impl Poolable for memcache::Client {
type Manager = r2d2_memcache::MemcacheConnectionManager;
type Error = DbError<memcache::MemcacheError>;

fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
fn pool(config: DatabaseConfig<'_>) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
let manager = r2d2_memcache::MemcacheConnectionManager::new(config.url);
r2d2::Pool::builder().max_size(config.pool_size).build(manager).map_err(DbError::PoolError)
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/lib/src/helmet/helmet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl SpaceHelmet {

/// Sets all of the headers in `self.policies` in `response` as long as the
/// header is not already in the response.
fn apply(&self, response: &mut Response) {
fn apply(&self, response: &mut Response<'_>) {
for policy in self.policies.values() {
let name = policy.name();
if response.headers().contains(name.as_str()) {
Expand Down Expand Up @@ -196,7 +196,7 @@ impl Fairing for SpaceHelmet {
}
}

fn on_response(&self, _request: &Request, response: &mut Response) {
fn on_response(&self, _request: &Request<'_>, response: &mut Response<'_>) {
self.apply(response);
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/lib/src/helmet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
//!
//! [OWASP]: https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#tab=Headers
extern crate time;
use time;

mod helmet;
mod policy;
Expand Down
12 changes: 6 additions & 6 deletions contrib/lib/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//! features = ["json"]
//! ```
extern crate serde;
extern crate serde_json;
use serde;
use serde_json;

use std::ops::{Deref, DerefMut};
use std::io::{self, Read};
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for Json<T> {
type Owned = String;
type Borrowed = str;

fn transform(r: &Request, d: Data) -> Transform<Outcome<Self::Owned, Self::Error>> {
fn transform(r: &Request<'_>, d: Data) -> Transform<Outcome<Self::Owned, Self::Error>> {
let size_limit = r.limits().get("json").unwrap_or(LIMIT);
let mut s = String::with_capacity(512);
match d.open().take(size_limit).read_to_string(&mut s) {
Expand All @@ -145,7 +145,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for Json<T> {
}
}

fn from_data(_: &Request, o: Transformed<'a, Self>) -> Outcome<Self, Self::Error> {
fn from_data(_: &Request<'_>, o: Transformed<'a, Self>) -> Outcome<Self, Self::Error> {
let string = o.borrowed()?;
match serde_json::from_str(&string) {
Ok(v) => Success(Json(v)),
Expand All @@ -165,7 +165,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for Json<T> {
/// JSON and a fixed-size body with the serialized value. If serialization
/// fails, an `Err` of `Status::InternalServerError` is returned.
impl<'a, T: Serialize> Responder<'a> for Json<T> {
fn respond_to(self, req: &Request) -> response::Result<'a> {
fn respond_to(self, req: &Request<'_>) -> response::Result<'a> {
serde_json::to_string(&self.0).map(|string| {
content::Json(string).respond_to(req).unwrap()
}).map_err(|e| {
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<T> FromIterator<T> for JsonValue where serde_json::Value: FromIterator<T> {
/// and a fixed-size body with the serialized value.
impl<'a> Responder<'a> for JsonValue {
#[inline]
fn respond_to(self, req: &Request) -> response::Result<'a> {
fn respond_to(self, req: &Request<'_>) -> response::Result<'a> {
content::Json(self.0.to_string()).respond_to(req)
}
}
Expand Down
3 changes: 2 additions & 1 deletion contrib/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#![doc(html_favicon_url = "https://rocket.rs/v0.5/images/favicon.ico")]
#![doc(html_logo_url = "https://rocket.rs/v0.5/images/logo-boxed.png")]

#![deny(rust_2018_idioms)]

//! This crate contains officially sanctioned contributor libraries that provide
//! functionality commonly used by Rocket applications.
//!
Expand Down Expand Up @@ -54,5 +56,4 @@
#[cfg(feature = "helmet")] pub mod helmet;
#[cfg(any(feature="brotli_compression", feature="gzip_compression"))] pub mod compression;

#[cfg(feature="databases")] extern crate rocket_contrib_codegen;
#[cfg(feature="databases")] #[doc(hidden)] pub use rocket_contrib_codegen::*;
10 changes: 5 additions & 5 deletions contrib/lib/src/msgpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
//! default-features = false
//! features = ["msgpack"]
//! ```
extern crate serde;
extern crate rmp_serde;
use serde;
use rmp_serde;

use std::io::Read;
use std::ops::{Deref, DerefMut};
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack<T> {
type Owned = Vec<u8>;
type Borrowed = [u8];

fn transform(r: &Request, d: Data) -> Transform<Outcome<Self::Owned, Self::Error>> {
fn transform(r: &Request<'_>, d: Data) -> Transform<Outcome<Self::Owned, Self::Error>> {
let mut buf = Vec::new();
let size_limit = r.limits().get("msgpack").unwrap_or(LIMIT);
match d.open().take(size_limit).read_to_end(&mut buf) {
Expand All @@ -130,7 +130,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack<T> {
}
}

fn from_data(_: &Request, o: Transformed<'a, Self>) -> Outcome<Self, Self::Error> {
fn from_data(_: &Request<'_>, o: Transformed<'a, Self>) -> Outcome<Self, Self::Error> {
use self::Error::*;

let buf = o.borrowed()?;
Expand All @@ -153,7 +153,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack<T> {
/// Content-Type `MsgPack` and a fixed-size body with the serialization. If
/// serialization fails, an `Err` of `Status::InternalServerError` is returned.
impl<T: Serialize> Responder<'static> for MsgPack<T> {
fn respond_to(self, req: &Request) -> response::Result<'static> {
fn respond_to(self, req: &Request<'_>) -> response::Result<'static> {
rmp_serde::to_vec(&self.0).map_err(|e| {
error_!("MsgPack failed to serialize: {:?}", e);
Status::InternalServerError
Expand Down
6 changes: 3 additions & 3 deletions contrib/lib/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ impl Into<Vec<Route>> for StaticFiles {
}

impl Handler for StaticFiles {
fn handle<'r>(&self, req: &'r Request, _: Data) -> Outcome<'r> {
fn handle_index<'r>(opt: Options, r: &'r Request, path: &Path) -> Outcome<'r> {
fn handle<'r>(&self, req: &'r Request<'_>, _: Data) -> Outcome<'r> {
fn handle_index<'r>(opt: Options, r: &'r Request<'_>, path: &Path) -> Outcome<'r> {
if !opt.contains(Options::Index) {
return Outcome::failure(Status::NotFound);
}
Expand All @@ -292,7 +292,7 @@ impl Handler for StaticFiles {
// Otherwise, we're handling segments. Get the segments as a `PathBuf`,
// only allowing dotfiles if the user allowed it.
let allow_dotfiles = self.options.contains(Options::DotFiles);
let path = req.get_segments::<Segments>(0)
let path = req.get_segments::<Segments<'_>>(0)
.and_then(|res| res.ok())
.and_then(|segments| segments.into_path_buf(allow_dotfiles).ok())
.map(|path| self.root.join(path))
Expand Down
4 changes: 2 additions & 2 deletions contrib/lib/src/templates/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use std::collections::HashMap;

use crate::templates::{glob, Engines, TemplateInfo};
use crate::templates::{Engines, TemplateInfo};

use rocket::http::ContentType;

Expand All @@ -25,7 +25,7 @@ impl Context {
glob_path.set_extension(ext);
let glob_path = glob_path.to_str().expect("valid glob path string");

for path in glob(glob_path).unwrap().filter_map(Result::ok) {
for path in glob::glob(glob_path).unwrap().filter_map(Result::ok) {
let (name, data_type_str) = split_path(&root, &path);
if let Some(info) = templates.get(&*name) {
warn_!("Template name '{}' does not have a unique path.", name);
Expand Down
8 changes: 4 additions & 4 deletions contrib/lib/src/templates/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod context {

#[cfg(debug_assertions)]
mod context {
extern crate notify;
use notify;

use std::ops::{Deref, DerefMut};
use std::sync::{RwLock, Mutex};
Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct TemplateFairing {
/// The user-provided customization callback, allowing the use of
/// functionality specific to individual template engines. In debug mode,
/// this callback might be run multiple times as templates are reloaded.
crate custom_callback: Box<Fn(&mut Engines) + Send + Sync + 'static>,
crate custom_callback: Box<dyn Fn(&mut Engines) + Send + Sync + 'static>,
}

impl Fairing for TemplateFairing {
Expand Down Expand Up @@ -165,8 +165,8 @@ impl Fairing for TemplateFairing {
}

#[cfg(debug_assertions)]
fn on_request(&self, req: &mut ::rocket::Request, _data: &::rocket::Data) {
let cm = req.guard::<::rocket::State<ContextManager>>()
fn on_request(&self, req: &mut ::rocket::Request<'_>, _data: &::rocket::Data) {
let cm = req.guard::<::rocket::State<'_, ContextManager>>()
.expect("Template ContextManager registered in on_attach");

cm.reload_if_needed(&*self.custom_callback);
Expand Down
4 changes: 2 additions & 2 deletions contrib/lib/src/templates/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ impl<'a> Metadata<'a> {
impl<'a, 'r> FromRequest<'a, 'r> for Metadata<'a> {
type Error = ();

fn from_request(request: &'a Request) -> request::Outcome<Self, ()> {
request.guard::<State<ContextManager>>()
fn from_request(request: &'a Request<'_>) -> request::Outcome<Self, ()> {
request.guard::<State<'_, ContextManager>>()
.succeeded()
.and_then(|cm| Some(Outcome::Success(Metadata(cm.inner()))))
.unwrap_or_else(|| {
Expand Down
Loading

0 comments on commit b7f39ec

Please sign in to comment.