From 6fa7f1133bbbea4dda4eca61cb6ff37720e9f726 Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Sat, 25 May 2019 15:51:47 -0700 Subject: [PATCH] Deny rust_2018_idioms lints in all crates except for examples. --- contrib/codegen/src/lib.rs | 3 ++- contrib/lib/src/compression/fairing.rs | 4 ++-- contrib/lib/src/compression/mod.rs | 6 ++--- contrib/lib/src/compression/responder.rs | 2 +- contrib/lib/src/databases.rs | 26 ++++++++++---------- contrib/lib/src/helmet/helmet.rs | 4 ++-- contrib/lib/src/helmet/mod.rs | 2 +- contrib/lib/src/json.rs | 12 +++++----- contrib/lib/src/lib.rs | 3 ++- contrib/lib/src/msgpack.rs | 10 ++++---- contrib/lib/src/serve.rs | 6 ++--- contrib/lib/src/templates/context.rs | 4 ++-- contrib/lib/src/templates/fairing.rs | 8 +++---- contrib/lib/src/templates/metadata.rs | 4 ++-- contrib/lib/src/templates/mod.rs | 10 ++++---- contrib/lib/src/uuid.rs | 4 ++-- core/codegen/src/attribute/segments.rs | 8 +++---- core/codegen/src/bang/uri.rs | 8 +++---- core/codegen/src/bang/uri_parsing.rs | 12 +++++----- core/codegen/src/derive/from_form.rs | 4 ++-- core/codegen/src/derive/uri_display.rs | 6 ++--- core/codegen/src/http_codegen.rs | 16 ++++++------- core/codegen/src/lib.rs | 7 +++--- core/http/src/accept.rs | 2 +- core/http/src/content_type.rs | 2 +- core/http/src/cookies.rs | 8 +++---- core/http/src/ext.rs | 4 ++-- core/http/src/header.rs | 4 ++-- core/http/src/hyper.rs | 2 +- core/http/src/lib.rs | 9 ++----- core/http/src/media_type.rs | 2 +- core/http/src/method.rs | 2 +- core/http/src/parse/accept.rs | 2 +- core/http/src/parse/checkers.rs | 2 +- core/http/src/parse/indexed.rs | 8 +++---- core/http/src/parse/media_type.rs | 2 +- core/http/src/parse/uri/error.rs | 4 ++-- core/http/src/parse/uri/mod.rs | 10 ++++---- core/http/src/raw_str.rs | 8 +++---- core/http/src/route.rs | 8 +++---- core/http/src/status.rs | 2 +- core/http/src/tls.rs | 4 ++-- core/http/src/uncased.rs | 4 ++-- core/http/src/uri/absolute.rs | 2 +- core/http/src/uri/authority.rs | 2 +- core/http/src/uri/encoding.rs | 4 ++-- core/http/src/uri/origin.rs | 8 +++---- core/http/src/uri/uri.rs | 12 +++++----- core/http/src/uri/uri_display.rs | 30 ++++++++++++------------ core/lib/src/catcher.rs | 6 ++--- core/lib/src/codegen.rs | 2 +- core/lib/src/config/config.rs | 2 +- core/lib/src/config/custom_values.rs | 6 ++--- core/lib/src/config/environment.rs | 2 +- core/lib/src/config/error.rs | 2 +- core/lib/src/config/toml_ext.rs | 4 ++-- core/lib/src/data/data.rs | 8 +++---- core/lib/src/data/from_data.rs | 26 ++++++++++---------- core/lib/src/error.rs | 10 ++++---- core/lib/src/fairing/ad_hoc.rs | 12 +++++----- core/lib/src/fairing/fairings.rs | 10 ++++---- core/lib/src/fairing/mod.rs | 8 +++---- core/lib/src/handler.rs | 18 +++++++------- core/lib/src/lib.rs | 11 ++------- core/lib/src/local/request.rs | 10 ++++---- core/lib/src/logger.rs | 6 ++--- core/lib/src/outcome.rs | 4 ++-- core/lib/src/request/form/form.rs | 4 ++-- core/lib/src/request/form/lenient.rs | 4 ++-- core/lib/src/request/request.rs | 16 ++++++------- core/lib/src/response/content.rs | 4 ++-- core/lib/src/response/flash.rs | 2 +- core/lib/src/response/named_file.rs | 2 +- core/lib/src/response/redirect.rs | 2 +- core/lib/src/response/responder.rs | 22 ++++++++--------- core/lib/src/response/response.rs | 14 +++++------ core/lib/src/response/status.rs | 12 +++++----- core/lib/src/response/stream.rs | 4 ++-- core/lib/src/rocket.rs | 10 ++++---- core/lib/src/router/collider.rs | 8 +++---- core/lib/src/router/mod.rs | 4 ++-- core/lib/src/router/route.rs | 12 +++++----- 82 files changed, 286 insertions(+), 297 deletions(-) diff --git a/contrib/codegen/src/lib.rs b/contrib/codegen/src/lib.rs index 1a1df0d442..a2cd5a389a 100644 --- a/contrib/codegen/src/lib.rs +++ b/contrib/codegen/src/lib.rs @@ -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 @@ -24,7 +26,6 @@ //! DATABASE_NAME := (string literal) //! -extern crate devise; extern crate proc_macro; #[allow(unused_imports)] diff --git a/contrib/lib/src/compression/fairing.rs b/contrib/lib/src/compression/fairing.rs index 2e10d5e25b..6930f2de8a 100644 --- a/contrib/lib/src/compression/fairing.rs +++ b/contrib/lib/src/compression/fairing.rs @@ -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>() + .guard::<::rocket::State<'_, Context>>() .expect("Compression Context registered in on_attach"); super::CompressionUtils::compress_response(request, response, &context.exclusions); diff --git a/contrib/lib/src/compression/mod.rs b/contrib/lib/src/compression/mod.rs index 9d64455676..1ee7abd4f5 100644 --- a/contrib/lib/src/compression/mod.rs +++ b/contrib/lib/src/compression/mod.rs @@ -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") @@ -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() } @@ -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; } diff --git a/contrib/lib/src/compression/responder.rs b/contrib/lib/src/compression/responder.rs index 8130b59483..05a6bfa81f 100644 --- a/contrib/lib/src/compression/responder.rs +++ b/contrib/lib/src/compression/responder.rs @@ -36,7 +36,7 @@ pub struct Compress(pub R); impl<'r, R: Responder<'r>> Responder<'r> for Compress { #[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(); diff --git a/contrib/lib/src/databases.rs b/contrib/lib/src/databases.rs index b98f579321..c5f2b189a1 100644 --- a/contrib/lib/src/databases.rs +++ b/contrib/lib/src/databases.rs @@ -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", @@ -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") @@ -717,7 +717,7 @@ pub trait Poolable: Send + Sized + 'static { /// Creates an `r2d2` connection pool for `Manager::Connection`, returning /// the pool on success. - fn pool(config: DatabaseConfig) -> Result, Self::Error>; + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error>; } #[cfg(feature = "diesel_sqlite_pool")] @@ -725,7 +725,7 @@ impl Poolable for diesel::SqliteConnection { type Manager = diesel::r2d2::ConnectionManager; type Error = r2d2::Error; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { let manager = diesel::r2d2::ConnectionManager::new(config.url); r2d2::Pool::builder().max_size(config.pool_size).build(manager) } @@ -736,7 +736,7 @@ impl Poolable for diesel::PgConnection { type Manager = diesel::r2d2::ConnectionManager; type Error = r2d2::Error; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { let manager = diesel::r2d2::ConnectionManager::new(config.url); r2d2::Pool::builder().max_size(config.pool_size).build(manager) } @@ -747,7 +747,7 @@ impl Poolable for diesel::MysqlConnection { type Manager = diesel::r2d2::ConnectionManager; type Error = r2d2::Error; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { let manager = diesel::r2d2::ConnectionManager::new(config.url); r2d2::Pool::builder().max_size(config.pool_size).build(manager) } @@ -759,7 +759,7 @@ impl Poolable for postgres::Connection { type Manager = r2d2_postgres::PostgresConnectionManager; type Error = DbError; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { let manager = r2d2_postgres::PostgresConnectionManager::new(config.url, r2d2_postgres::TlsMode::None) .map_err(DbError::Custom)?; @@ -773,7 +773,7 @@ impl Poolable for mysql::Conn { type Manager = r2d2_mysql::MysqlConnectionManager; type Error = r2d2::Error; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, 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) @@ -785,7 +785,7 @@ impl Poolable for rusqlite::Connection { type Manager = r2d2_sqlite::SqliteConnectionManager; type Error = r2d2::Error; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { let manager = r2d2_sqlite::SqliteConnectionManager::file(config.url); r2d2::Pool::builder().max_size(config.pool_size).build(manager) @@ -797,7 +797,7 @@ impl Poolable for rusted_cypher::GraphClient { type Manager = r2d2_cypher::CypherConnectionManager; type Error = r2d2::Error; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { let manager = r2d2_cypher::CypherConnectionManager { url: config.url.to_string() }; r2d2::Pool::builder().max_size(config.pool_size).build(manager) } @@ -808,7 +808,7 @@ impl Poolable for redis::Connection { type Manager = r2d2_redis::RedisConnectionManager; type Error = DbError; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, 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) @@ -820,7 +820,7 @@ impl Poolable for mongodb::db::Database { type Manager = r2d2_mongodb::MongodbConnectionManager; type Error = DbError; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, 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) } @@ -831,7 +831,7 @@ impl Poolable for memcache::Client { type Manager = r2d2_memcache::MemcacheConnectionManager; type Error = DbError; - fn pool(config: DatabaseConfig) -> Result, Self::Error> { + fn pool(config: DatabaseConfig<'_>) -> Result, Self::Error> { let manager = r2d2_memcache::MemcacheConnectionManager::new(config.url); r2d2::Pool::builder().max_size(config.pool_size).build(manager).map_err(DbError::PoolError) } diff --git a/contrib/lib/src/helmet/helmet.rs b/contrib/lib/src/helmet/helmet.rs index 2b57caa603..c18251d87f 100644 --- a/contrib/lib/src/helmet/helmet.rs +++ b/contrib/lib/src/helmet/helmet.rs @@ -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()) { @@ -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); } diff --git a/contrib/lib/src/helmet/mod.rs b/contrib/lib/src/helmet/mod.rs index 7aa34b210e..00c3b10d16 100644 --- a/contrib/lib/src/helmet/mod.rs +++ b/contrib/lib/src/helmet/mod.rs @@ -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; diff --git a/contrib/lib/src/json.rs b/contrib/lib/src/json.rs index 0605e48fd1..ef61410de1 100644 --- a/contrib/lib/src/json.rs +++ b/contrib/lib/src/json.rs @@ -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}; @@ -136,7 +136,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for Json { type Owned = String; type Borrowed = str; - fn transform(r: &Request, d: Data) -> Transform> { + fn transform(r: &Request<'_>, d: Data) -> Transform> { 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) { @@ -145,7 +145,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for Json { } } - fn from_data(_: &Request, o: Transformed<'a, Self>) -> Outcome { + fn from_data(_: &Request<'_>, o: Transformed<'a, Self>) -> Outcome { let string = o.borrowed()?; match serde_json::from_str(&string) { Ok(v) => Success(Json(v)), @@ -165,7 +165,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for Json { /// 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 { - 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| { @@ -288,7 +288,7 @@ impl FromIterator for JsonValue where serde_json::Value: FromIterator { /// 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) } } diff --git a/contrib/lib/src/lib.rs b/contrib/lib/src/lib.rs index 7b877cd13f..5b216e8bff 100644 --- a/contrib/lib/src/lib.rs +++ b/contrib/lib/src/lib.rs @@ -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. //! @@ -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::*; diff --git a/contrib/lib/src/msgpack.rs b/contrib/lib/src/msgpack.rs index 8be0fe9f0e..6ac5db8453 100644 --- a/contrib/lib/src/msgpack.rs +++ b/contrib/lib/src/msgpack.rs @@ -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}; @@ -121,7 +121,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack { type Owned = Vec; type Borrowed = [u8]; - fn transform(r: &Request, d: Data) -> Transform> { + fn transform(r: &Request<'_>, d: Data) -> Transform> { 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) { @@ -130,7 +130,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack { } } - fn from_data(_: &Request, o: Transformed<'a, Self>) -> Outcome { + fn from_data(_: &Request<'_>, o: Transformed<'a, Self>) -> Outcome { use self::Error::*; let buf = o.borrowed()?; @@ -153,7 +153,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack { /// Content-Type `MsgPack` and a fixed-size body with the serialization. If /// serialization fails, an `Err` of `Status::InternalServerError` is returned. impl Responder<'static> for MsgPack { - 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 diff --git a/contrib/lib/src/serve.rs b/contrib/lib/src/serve.rs index c33ab2aa7f..e29bd08947 100644 --- a/contrib/lib/src/serve.rs +++ b/contrib/lib/src/serve.rs @@ -272,8 +272,8 @@ impl Into> 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); } @@ -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::(0) + let path = req.get_segments::>(0) .and_then(|res| res.ok()) .and_then(|segments| segments.into_path_buf(allow_dotfiles).ok()) .map(|path| self.root.join(path)) diff --git a/contrib/lib/src/templates/context.rs b/contrib/lib/src/templates/context.rs index 2fe3010a14..ed73ea26b6 100644 --- a/contrib/lib/src/templates/context.rs +++ b/contrib/lib/src/templates/context.rs @@ -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; @@ -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); diff --git a/contrib/lib/src/templates/fairing.rs b/contrib/lib/src/templates/fairing.rs index a4008079f2..9318cf36e4 100644 --- a/contrib/lib/src/templates/fairing.rs +++ b/contrib/lib/src/templates/fairing.rs @@ -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}; @@ -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, + crate custom_callback: Box, } impl Fairing for TemplateFairing { @@ -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>() + 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); diff --git a/contrib/lib/src/templates/metadata.rs b/contrib/lib/src/templates/metadata.rs index 52c89ac4f7..ce29a69ba0 100644 --- a/contrib/lib/src/templates/metadata.rs +++ b/contrib/lib/src/templates/metadata.rs @@ -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 { - request.guard::>() + fn from_request(request: &'a Request<'_>) -> request::Outcome { + request.guard::>() .succeeded() .and_then(|cm| Some(Outcome::Success(Metadata(cm.inner())))) .unwrap_or_else(|| { diff --git a/contrib/lib/src/templates/mod.rs b/contrib/lib/src/templates/mod.rs index 14c10f8787..ca1e8e7a49 100644 --- a/contrib/lib/src/templates/mod.rs +++ b/contrib/lib/src/templates/mod.rs @@ -111,9 +111,8 @@ //! [`Template::custom()`]: templates::Template::custom() //! [`Template::render()`]: templates::Template::render() -extern crate serde; -extern crate serde_json; -extern crate glob; +use serde; +use serde_json; #[cfg(feature = "tera_templates")] pub extern crate tera; #[cfg(feature = "tera_templates")] mod tera_templates; @@ -135,7 +134,6 @@ use self::engine::Engine; use self::fairing::TemplateFairing; use self::serde::Serialize; use self::serde_json::{Value, to_value}; -use self::glob::glob; use std::borrow::Cow; use std::path::PathBuf; @@ -387,8 +385,8 @@ impl Template { /// extension and a fixed-size body containing the rendered template. If /// rendering fails, an `Err` of `Status::InternalServerError` is returned. impl Responder<'static> for Template { - fn respond_to(self, req: &Request) -> response::Result<'static> { - let ctxt = req.guard::>().succeeded().ok_or_else(|| { + fn respond_to(self, req: &Request<'_>) -> response::Result<'static> { + let ctxt = req.guard::>().succeeded().ok_or_else(|| { error_!("Uninitialized template context: missing fairing."); info_!("To use templates, you must attach `Template::fairing()`."); info_!("See the `Template` documentation for more information."); diff --git a/contrib/lib/src/uuid.rs b/contrib/lib/src/uuid.rs index 0b2625fdaa..1cd28d7d18 100644 --- a/contrib/lib/src/uuid.rs +++ b/contrib/lib/src/uuid.rs @@ -14,7 +14,7 @@ //! features = ["uuid"] //! ``` -pub extern crate uuid as uuid_crate; +pub use uuid as uuid_crate; use std::fmt; use std::str::FromStr; @@ -95,7 +95,7 @@ impl Uuid { impl fmt::Display for Uuid { #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } diff --git a/core/codegen/src/attribute/segments.rs b/core/codegen/src/attribute/segments.rs index 7f870759da..eabb807795 100644 --- a/core/codegen/src/attribute/segments.rs +++ b/core/codegen/src/attribute/segments.rs @@ -19,7 +19,7 @@ crate struct Segment { } impl Segment { - fn from(segment: RouteSegment

, span: Span) -> Segment { + fn from(segment: RouteSegment<'_, P>, span: Span) -> Segment { let source = match P::DELIMITER { '/' => Source::Path, '&' => Source::Query, @@ -76,7 +76,7 @@ fn into_diagnostic( segment: &str, // The segment that failed. source: &str, // The haystack where `segment` can be found. span: Span, // The `Span` of `Source`. - error: &Error, // The error. + error: &Error<'_>, // The error. ) -> Diagnostic { let seg_span = subspan(segment, source, span); match error { @@ -116,7 +116,7 @@ fn into_diagnostic( } crate fn parse_data_segment(segment: &str, span: Span) -> PResult { - >::parse_one(segment) + >::parse_one(segment) .map(|segment| { let mut seg = Segment::from(segment, span); seg.source = Source::Data; @@ -133,7 +133,7 @@ crate fn parse_segments( let mut segments = vec![]; let mut diags = Diagnostics::new(); - for result in >::parse_many(string) { + for result in >::parse_many(string) { if let Err((segment_string, error)) = result { diags.push(into_diagnostic(segment_string, string, span, &error)); if let Error::Trailing(..) = error { diff --git a/core/codegen/src/bang/uri.rs b/core/codegen/src/bang/uri.rs index d2407da971..8b0c7fc6c1 100644 --- a/core/codegen/src/bang/uri.rs +++ b/core/codegen/src/bang/uri.rs @@ -122,7 +122,7 @@ fn add_binding(to: &mut Vec, ident: &Ident, ty: &Type, expr: &Expr } fn explode_path<'a, I: Iterator>( - uri: &Origin, + uri: &Origin<'_>, bindings: &mut Vec, mut items: I ) -> TokenStream2 { @@ -132,7 +132,7 @@ fn explode_path<'a, I: Iterator>( } let uri_display = quote!(#uri_mod::UriDisplay<#uri_mod::Path>); - let dyn_exprs = >::parse(uri).map(|segment| { + let dyn_exprs = >::parse(uri).map(|segment| { let segment = segment.expect("segment okay; prechecked on parse"); match segment.kind { Kind::Static => { @@ -151,7 +151,7 @@ fn explode_path<'a, I: Iterator>( } fn explode_query<'a, I: Iterator>( - uri: &Origin, + uri: &Origin<'_>, bindings: &mut Vec, mut items: I ) -> Option { @@ -162,7 +162,7 @@ fn explode_query<'a, I: Iterator>( let query_arg = quote!(#uri_mod::UriQueryArgument); let uri_display = quote!(#uri_mod::UriDisplay<#uri_mod::Query>); - let dyn_exprs = >::parse(uri)?.filter_map(|segment| { + let dyn_exprs = >::parse(uri)?.filter_map(|segment| { let segment = segment.expect("segment okay; prechecked on parse"); if segment.kind == Kind::Static { let string = &segment.string; diff --git a/core/codegen/src/bang/uri_parsing.rs b/core/codegen/src/bang/uri_parsing.rs index 08406c5381..ab6edf8be7 100644 --- a/core/codegen/src/bang/uri_parsing.rs +++ b/core/codegen/src/bang/uri_parsing.rs @@ -79,7 +79,7 @@ pub struct InternalUriParams { } impl Parse for ArgExpr { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { if input.peek(Token![_]) { return Ok(ArgExpr::Ignored(input.parse::()?)); } @@ -89,7 +89,7 @@ impl Parse for ArgExpr { } impl Parse for Arg { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { let has_key = input.peek2(Token![=]); if has_key { let ident = input.parse::()?; @@ -109,7 +109,7 @@ fn err>(span: Span, s: S) -> parse::Result { impl Parse for UriParams { // Parses the mount point, if any, route identifier, and arguments. - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { if input.is_empty() { return Err(input.error("call to `uri!` cannot be empty")); } @@ -176,7 +176,7 @@ impl Parse for UriParams { } impl Parse for FnArg { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { let ident = input.parse::()?; input.parse::()?; let mut ty = input.parse::()?; @@ -186,7 +186,7 @@ impl Parse for FnArg { } impl Parse for InternalUriParams { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { let route_uri_str = input.parse::()?; input.parse::()?; @@ -215,7 +215,7 @@ impl InternalUriParams { .join(", ") } - pub fn validate(&self) -> Validation { + pub fn validate(&self) -> Validation<'_> { let args = &self.uri_params.arguments; match args { Args::Unnamed(inner) => { diff --git a/core/codegen/src/derive/from_form.rs b/core/codegen/src/derive/from_form.rs index 27b84875ee..5a6835323e 100644 --- a/core/codegen/src/derive/from_form.rs +++ b/core/codegen/src/derive/from_form.rs @@ -23,7 +23,7 @@ fn is_valid_field_name(s: &str) -> bool { } impl FromMeta for FormField { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { let string = String::from_meta(meta)?; if !is_valid_field_name(&string) { return Err(meta.value_span().error("invalid form field name")); @@ -33,7 +33,7 @@ impl FromMeta for FormField { } } -fn validate_struct(gen: &DeriveGenerator, data: Struct) -> Result<()> { +fn validate_struct(gen: &DeriveGenerator, data: Struct<'_>) -> Result<()> { if data.fields().is_empty() { return Err(gen.input.span().error("at least one field is required")); } diff --git a/core/codegen/src/derive/uri_display.rs b/core/codegen/src/derive/uri_display.rs index db646c73e1..aaf0fb9499 100644 --- a/core/codegen/src/derive/uri_display.rs +++ b/core/codegen/src/derive/uri_display.rs @@ -10,7 +10,7 @@ const NO_EMPTY_ENUMS: &str = "empty enums are not supported"; const ONLY_ONE_UNNAMED: &str = "tuple structs or variants must have exactly one field"; const EXACTLY_ONE_FIELD: &str = "struct must have exactly one field"; -fn validate_fields(fields: Fields, parent_span: Span) -> Result<()> { +fn validate_fields(fields: Fields<'_>, parent_span: Span) -> Result<()> { if fields.count() == 0 { return Err(parent_span.error(NO_EMPTY_FIELDS)) } else if fields.are_unnamed() && fields.count() > 1 { @@ -22,11 +22,11 @@ fn validate_fields(fields: Fields, parent_span: Span) -> Result<()> { Ok(()) } -fn validate_struct(gen: &DeriveGenerator, data: Struct) -> Result<()> { +fn validate_struct(gen: &DeriveGenerator, data: Struct<'_>) -> Result<()> { validate_fields(data.fields(), gen.input.span()) } -fn validate_enum(gen: &DeriveGenerator, data: Enum) -> Result<()> { +fn validate_enum(gen: &DeriveGenerator, data: Enum<'_>) -> Result<()> { if data.variants().count() == 0 { return Err(gen.input.span().error(NO_EMPTY_ENUMS)); } diff --git a/core/codegen/src/http_codegen.rs b/core/codegen/src/http_codegen.rs index 2ff470b705..782394282c 100644 --- a/core/codegen/src/http_codegen.rs +++ b/core/codegen/src/http_codegen.rs @@ -29,7 +29,7 @@ crate struct DataSegment(crate Segment); crate struct Optional(crate Option); impl FromMeta for StringLit { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { Ok(StringLit::new(String::from_meta(meta)?, meta.value_span())) } } @@ -42,7 +42,7 @@ crate struct RoutePath { } impl FromMeta for Status { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { let num = usize::from_meta(meta)?; if num < 100 || num >= 600 { return Err(meta.value_span().error("status must be in range [100, 599]")); @@ -60,7 +60,7 @@ impl ToTokens for Status { } impl FromMeta for ContentType { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { http::ContentType::parse_flexible(&String::from_meta(meta)?) .map(ContentType) .ok_or(meta.value_span().error("invalid or unknown content type")) @@ -76,7 +76,7 @@ impl ToTokens for ContentType { } impl FromMeta for MediaType { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { let mt = http::MediaType::parse_flexible(&String::from_meta(meta)?) .ok_or(meta.value_span().error("invalid or unknown media type"))?; @@ -126,7 +126,7 @@ const VALID_METHODS: &[http::Method] = &[ ]; impl FromMeta for Method { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { let span = meta.value_span(); let help_text = format!("method must be one of: {}", VALID_METHODS_STR); @@ -166,7 +166,7 @@ impl ToTokens for Method { } impl FromMeta for Origin { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { let string = StringLit::from_meta(meta)?; let uri = http::uri::Origin::parse_route(&string) @@ -190,7 +190,7 @@ impl FromMeta for Origin { } impl FromMeta for DataSegment { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { let string = StringLit::from_meta(meta)?; let span = string.subspan(1..(string.len() + 1)); @@ -205,7 +205,7 @@ impl FromMeta for DataSegment { } impl FromMeta for RoutePath { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { let (origin, string) = (Origin::from_meta(meta)?, StringLit::from_meta(meta)?); let path_span = string.subspan(1..origin.0.path().len() + 1); let path = parse_segments::(origin.0.path(), path_span); diff --git a/core/codegen/src/lib.rs b/core/codegen/src/lib.rs index 722af00ac2..c00bdc149e 100644 --- a/core/codegen/src/lib.rs +++ b/core/codegen/src/lib.rs @@ -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)] + //! # Rocket - Code Generation //! //! This crate implements the code generation portions of Rocket. This includes @@ -58,10 +60,9 @@ //! ``` #[macro_use] extern crate quote; -extern crate devise; +use devise; extern crate proc_macro; -extern crate rocket_http as http; -extern crate indexmap; +use rocket_http as http; macro_rules! define { ($val:path as $v:ident) => (#[allow(non_snake_case)] let $v = quote!($val);); diff --git a/core/http/src/accept.rs b/core/http/src/accept.rs index b624d8453a..71fb7e4201 100644 --- a/core/http/src/accept.rs +++ b/core/http/src/accept.rs @@ -353,7 +353,7 @@ impl Accept { } impl fmt::Display for Accept { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for (i, media_type) in self.iter().enumerate() { if i >= 1 { write!(f, ", {}", media_type.0)?; diff --git a/core/http/src/content_type.rs b/core/http/src/content_type.rs index 50b1be3ae3..be8f881f3d 100644 --- a/core/http/src/content_type.rs +++ b/core/http/src/content_type.rs @@ -350,7 +350,7 @@ impl fmt::Display for ContentType { /// assert_eq!(ct, "application/json"); /// ``` #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) } } diff --git a/core/http/src/cookies.rs b/core/http/src/cookies.rs index 4393139b79..d2a76ed6a9 100644 --- a/core/http/src/cookies.rs +++ b/core/http/src/cookies.rs @@ -260,7 +260,7 @@ impl<'a> Cookies<'a> { /// WARNING: This is unstable! Do not use this method outside of Rocket! #[inline] #[doc(hidden)] - pub fn delta(&self) -> Delta { + pub fn delta(&self) -> Delta<'_> { match *self { Cookies::Jarred(ref jar, _) => jar.delta(), Cookies::Empty(ref jar) => jar.delta() @@ -401,7 +401,7 @@ impl<'a> Cookies<'a> { } impl<'a> fmt::Debug for Cookies<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Cookies::Jarred(ref jar, _) => write!(f, "{:?}", jar), Cookies::Empty(ref jar) => write!(f, "{:?}", jar) @@ -410,13 +410,13 @@ impl<'a> fmt::Debug for Cookies<'a> { } impl<'c> From> for Header<'static> { - fn from(cookie: Cookie) -> Header<'static> { + fn from(cookie: Cookie<'_>) -> Header<'static> { Header::new("Set-Cookie", cookie.encoded().to_string()) } } impl<'a, 'c> From<&'a Cookie<'c>> for Header<'static> { - fn from(cookie: &Cookie) -> Header<'static> { + fn from(cookie: &Cookie<'_>) -> Header<'static> { Header::new("Set-Cookie", cookie.encoded().to_string()) } } diff --git a/core/http/src/ext.rs b/core/http/src/ext.rs index a37797e90a..809cdcd7c9 100644 --- a/core/http/src/ext.rs +++ b/core/http/src/ext.rs @@ -104,7 +104,7 @@ use std::path::Path; // Outside of http, this is used by a test. #[doc(hidden)] pub trait Normalize { - fn normalized_str(&self) -> Cow; + fn normalized_str(&self) -> Cow<'_, str>; } impl> Normalize for T { @@ -114,7 +114,7 @@ impl> Normalize for T { } #[cfg(not(windows))] - fn normalized_str(&self) -> Cow { + fn normalized_str(&self) -> Cow<'_, str> { self.as_ref().to_string_lossy() } } diff --git a/core/http/src/header.rs b/core/http/src/header.rs index ada791f1d6..842995fa84 100644 --- a/core/http/src/header.rs +++ b/core/http/src/header.rs @@ -106,7 +106,7 @@ impl<'h> Header<'h> { impl<'h> fmt::Display for Header<'h> { #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}: {}", self.name, self.value) } } @@ -560,7 +560,7 @@ impl<'h> HeaderMap<'h> { /// } /// } /// ``` - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator> { self.headers.iter().flat_map(|(key, values)| { values.iter().map(move |val| { Header::new(key.as_str(), &**val) diff --git a/core/http/src/hyper.rs b/core/http/src/hyper.rs index a66108aae9..0d994a7663 100644 --- a/core/http/src/hyper.rs +++ b/core/http/src/hyper.rs @@ -4,7 +4,7 @@ //! These types will, with certainty, be removed with time, but they reside here //! while necessary. -extern crate hyper; +use hyper; #[doc(hidden)] pub use self::hyper::server::Request as Request; #[doc(hidden)] pub use self::hyper::server::Response as Response; diff --git a/core/http/src/lib.rs b/core/http/src/lib.rs index cc19d5e803..870ade9c48 100644 --- a/core/http/src/lib.rs +++ b/core/http/src/lib.rs @@ -4,6 +4,8 @@ #![feature(doc_cfg)] #![recursion_limit="512"] +#![deny(rust_2018_idioms)] + //! Types that map to concepts in HTTP. //! //! This module exports types that map to HTTP concepts or to the underlying @@ -13,13 +15,6 @@ //! [#17]: https://github.com/SergioBenitez/Rocket/issues/17 #[macro_use] extern crate pear; -extern crate percent_encoding; -extern crate smallvec; -extern crate cookie; -extern crate time; -extern crate indexmap; -extern crate state; -extern crate unicode_xid; pub mod hyper; pub mod uri; diff --git a/core/http/src/media_type.rs b/core/http/src/media_type.rs index 08fefed82d..eeae2dd760 100644 --- a/core/http/src/media_type.rs +++ b/core/http/src/media_type.rs @@ -533,7 +533,7 @@ impl Hash for MediaType { impl fmt::Display for MediaType { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Source::Known(src) = self.source { src.fmt(f) } else { diff --git a/core/http/src/method.rs b/core/http/src/method.rs index 5462fb2563..ce83d67a29 100644 --- a/core/http/src/method.rs +++ b/core/http/src/method.rs @@ -116,7 +116,7 @@ impl FromStr for Method { impl fmt::Display for Method { #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.as_str().fmt(f) } } diff --git a/core/http/src/parse/accept.rs b/core/http/src/parse/accept.rs index 3bf7186ed1..c27bc50239 100644 --- a/core/http/src/parse/accept.rs +++ b/core/http/src/parse/accept.rs @@ -29,7 +29,7 @@ fn accept<'a>(input: &mut Input<'a>) -> Result<'a, Accept> { Accept(series(false, ',', is_whitespace, weighted_media_type)?) } -pub fn parse_accept(input: &str) -> Result { +pub fn parse_accept(input: &str) -> Result<'_, Accept> { parse!(accept: &mut input.into()) } diff --git a/core/http/src/parse/checkers.rs b/core/http/src/parse/checkers.rs index 2658552995..ae9d21ed8e 100644 --- a/core/http/src/parse/checkers.rs +++ b/core/http/src/parse/checkers.rs @@ -6,7 +6,7 @@ pub fn is_whitespace(byte: char) -> bool { #[inline] pub fn is_valid_token(c: char) -> bool { match c { - '0'...'9' | 'A'...'Z' | '^'...'~' | '#'...'\'' + '0'..='9' | 'A'..='Z' | '^'..='~' | '#'..='\'' | '!' | '*' | '+' | '-' | '.' => true, _ => false } diff --git a/core/http/src/parse/indexed.rs b/core/http/src/parse/indexed.rs index b6da943d34..7a92fa4bd3 100644 --- a/core/http/src/parse/indexed.rs +++ b/core/http/src/parse/indexed.rs @@ -154,7 +154,7 @@ impl<'a, T: ?Sized + ToOwned + 'a> Indexed<'a, T> /// /// Panics if `self` is an indexed string and `string` is None. // pub fn to_source(&self, source: Option<&'a T>) -> &T { - pub fn from_cow_source<'s>(&'s self, source: &'s Option>) -> &'s T { + pub fn from_cow_source<'s>(&'s self, source: &'s Option>) -> &'s T { if self.is_indexed() && source.is_none() { panic!("Cannot convert indexed str to str without base string!") } @@ -196,7 +196,7 @@ impl<'a, T: ToOwned + ?Sized + 'a> Clone for Indexed<'a, T> { impl<'a, T: ?Sized + 'a> Debug for Indexed<'a, T> where T: ToOwned + Debug, T::Owned: Debug { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Indexed::Indexed(a, b) => fmt::Debug::fmt(&(a, b), f), Indexed::Concrete(ref cow) => fmt::Debug::fmt(cow, f), @@ -215,7 +215,7 @@ impl<'a, T: ?Sized + Length + ToOwned + 'a> Length for Indexed<'a, T> { } #[derive(Debug)] -pub struct IndexedInput<'a, T: ?Sized + 'a> { +pub struct IndexedInput<'a, T: ?Sized> { source: &'a T, current: &'a T } @@ -324,7 +324,7 @@ pub struct Context { } impl ::std::fmt::Display for Context { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { const LIMIT: usize = 7; write!(f, "[{}:]", self.offset)?; diff --git a/core/http/src/parse/media_type.rs b/core/http/src/parse/media_type.rs index ae451c1043..fd349ab6c1 100644 --- a/core/http/src/parse/media_type.rs +++ b/core/http/src/parse/media_type.rs @@ -54,7 +54,7 @@ pub fn media_type<'a>(input: &mut Input<'a>) -> Result<'a, MediaType> { } } -pub fn parse_media_type(input: &str) -> Result { +pub fn parse_media_type(input: &str) -> Result<'_, MediaType> { parse!(media_type: &mut input.into()) } diff --git a/core/http/src/parse/uri/error.rs b/core/http/src/parse/uri/error.rs index abe097ecec..74a2940ea3 100644 --- a/core/http/src/parse/uri/error.rs +++ b/core/http/src/parse/uri/error.rs @@ -58,7 +58,7 @@ impl<'a> Error<'a> { } impl fmt::Display for Or { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Or::A(left) => write!(f, "'{}'", left), Or::B(right) => write!(f, "non-ASCII byte {}", right), @@ -67,7 +67,7 @@ impl fmt::Display for Or { } impl<'a> fmt::Display for Error<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // This relies on specialization of the `Display` impl for `Expected`. write!(f, "{}", self.expected)?; diff --git a/core/http/src/parse/uri/mod.rs b/core/http/src/parse/uri/mod.rs index 4edd75d70b..33f0066143 100644 --- a/core/http/src/parse/uri/mod.rs +++ b/core/http/src/parse/uri/mod.rs @@ -14,31 +14,31 @@ pub use self::error::Error; type RawInput<'a> = IndexedInput<'a, [u8]>; #[inline] -pub fn from_str(string: &str) -> Result { +pub fn from_str(string: &str) -> Result, Error<'_>> { parse!(uri: &mut RawInput::from(string.as_bytes())) .map_err(|e| Error::from(string, e)) } #[inline] -pub fn origin_from_str(string: &str) -> Result { +pub fn origin_from_str(string: &str) -> Result, Error<'_>> { parse!(origin: &mut RawInput::from(string.as_bytes())) .map_err(|e| Error::from(string, e)) } #[inline] -pub fn route_origin_from_str(string: &str) -> Result { +pub fn route_origin_from_str(string: &str) -> Result, Error<'_>> { parse!(rocket_route_origin: &mut RawInput::from(string.as_bytes())) .map_err(|e| Error::from(string, e)) } #[inline] -pub fn authority_from_str(string: &str) -> Result { +pub fn authority_from_str(string: &str) -> Result, Error<'_>> { parse!(authority_only: &mut RawInput::from(string.as_bytes())) .map_err(|e| Error::from(string, e)) } #[inline] -pub fn absolute_from_str(string: &str) -> Result { +pub fn absolute_from_str(string: &str) -> Result, Error<'_>> { parse!(absolute_only: &mut RawInput::from(string.as_bytes())) .map_err(|e| Error::from(string, e)) } diff --git a/core/http/src/raw_str.rs b/core/http/src/raw_str.rs index d6d8539117..714ce4436d 100644 --- a/core/http/src/raw_str.rs +++ b/core/http/src/raw_str.rs @@ -103,7 +103,7 @@ impl RawStr { /// assert!(bad_raw_str.percent_decode().is_err()); /// ``` #[inline(always)] - pub fn percent_decode(&self) -> Result, Utf8Error> { + pub fn percent_decode(&self) -> Result, Utf8Error> { ::percent_encoding::percent_decode(self.as_bytes()).decode_utf8() } @@ -136,7 +136,7 @@ impl RawStr { /// assert_eq!(bad_raw_str.percent_decode_lossy(), "a=�"); /// ``` #[inline(always)] - pub fn percent_decode_lossy(&self) -> Cow { + pub fn percent_decode_lossy(&self) -> Cow<'_, str> { ::percent_encoding::percent_decode(self.as_bytes()).decode_utf8_lossy() } @@ -245,7 +245,7 @@ impl RawStr { /// let escaped = raw_str.html_escape(); /// assert_eq!(escaped, "大阪"); /// ``` - pub fn html_escape(&self) -> Cow { + pub fn html_escape(&self) -> Cow<'_, str> { let mut escaped = false; let mut allocated = Vec::new(); // this is allocation free for c in self.as_bytes() { @@ -426,7 +426,7 @@ impl DerefMut for RawStr { impl fmt::Display for RawStr { #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } diff --git a/core/http/src/route.rs b/core/http/src/route.rs index cfb0442d8a..5a47feb859 100644 --- a/core/http/src/route.rs +++ b/core/http/src/route.rs @@ -86,7 +86,7 @@ fn is_valid_ident(string: &str) -> bool { } impl<'a, P: UriPart> RouteSegment<'a, P> { - pub fn parse_one(segment: &'a str) -> Result { + pub fn parse_one(segment: &'a str) -> Result> { let (string, index) = (segment.into(), None); // Check if this is a dynamic param. If so, check its well-formedness. @@ -129,7 +129,7 @@ impl<'a, P: UriPart> RouteSegment<'a, P> { pub fn parse_many( string: &'a str, - ) -> impl Iterator> { + ) -> impl Iterator> { let mut last_multi_seg: Option<&str> = None; string.split(P::DELIMITER) .filter(|s| !s.is_empty()) @@ -151,13 +151,13 @@ impl<'a, P: UriPart> RouteSegment<'a, P> { } impl<'a> RouteSegment<'a, Path> { - pub fn parse(uri: &'a Origin) -> impl Iterator> { + pub fn parse(uri: &'a Origin<'_>) -> impl Iterator> { Self::parse_many(uri.path()) } } impl<'a> RouteSegment<'a, Query> { - pub fn parse(uri: &'a Origin) -> Option>> { + pub fn parse(uri: &'a Origin<'_>) -> Option>> { uri.query().map(|q| Self::parse_many(q)) } } diff --git a/core/http/src/status.rs b/core/http/src/status.rs index b1a1986224..6e32db4363 100644 --- a/core/http/src/status.rs +++ b/core/http/src/status.rs @@ -273,7 +273,7 @@ impl Status { impl fmt::Display for Status { #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{} {}", self.code, self.reason) } } diff --git a/core/http/src/tls.rs b/core/http/src/tls.rs index 63931ca3d0..f8737e5920 100644 --- a/core/http/src/tls.rs +++ b/core/http/src/tls.rs @@ -1,5 +1,5 @@ -extern crate rustls; -extern crate hyper_sync_rustls; +use rustls; +use hyper_sync_rustls; pub use self::hyper_sync_rustls::{util, WrappedStream, ServerSession, TlsServer}; pub use self::rustls::{Certificate, PrivateKey}; diff --git a/core/http/src/uncased.rs b/core/http/src/uncased.rs index b81a7b1302..819ea2a92f 100644 --- a/core/http/src/uncased.rs +++ b/core/http/src/uncased.rs @@ -156,7 +156,7 @@ impl Ord for UncasedStr { impl fmt::Display for UncasedStr { #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } @@ -299,7 +299,7 @@ impl<'a> Ord for Uncased<'a> { impl<'s> fmt::Display for Uncased<'s> { #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.string.fmt(f) } } diff --git a/core/http/src/uri/absolute.rs b/core/http/src/uri/absolute.rs index fffeba5b84..143367d3a1 100644 --- a/core/http/src/uri/absolute.rs +++ b/core/http/src/uri/absolute.rs @@ -158,7 +158,7 @@ impl<'a, 'b> PartialEq> for Absolute<'a> { } impl<'a> Display for Absolute<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.scheme())?; match self.authority { Some(ref authority) => write!(f, "://{}", authority)?, diff --git a/core/http/src/uri/authority.rs b/core/http/src/uri/authority.rs index 24c76acd02..2f9baad89b 100644 --- a/core/http/src/uri/authority.rs +++ b/core/http/src/uri/authority.rs @@ -181,7 +181,7 @@ impl<'a, 'b> PartialEq> for Authority<'a> { } impl<'a> Display for Authority<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(user_info) = self.user_info() { write!(f, "{}@", user_info)?; } diff --git a/core/http/src/uri/encoding.rs b/core/http/src/uri/encoding.rs index 7bc704f706..c08d96cf06 100644 --- a/core/http/src/uri/encoding.rs +++ b/core/http/src/uri/encoding.rs @@ -62,7 +62,7 @@ impl EncodeSet for DEFAULT_ENCODE_SET { } } -crate fn unsafe_percent_encode(string: &str) -> Cow { +crate fn unsafe_percent_encode(string: &str) -> Cow<'_, str> { match P::DELIMITER { '/' => percent_encode::>(string), '&' => percent_encode::>(string), @@ -70,6 +70,6 @@ crate fn unsafe_percent_encode(string: &str) -> Cow { } } -crate fn percent_encode(string: &str) -> Cow { +crate fn percent_encode(string: &str) -> Cow<'_, str> { utf8_percent_encode(string, S::default()).into() } diff --git a/core/http/src/uri/origin.rs b/core/http/src/uri/origin.rs index 566d783bda..eb1bb23de1 100644 --- a/core/http/src/uri/origin.rs +++ b/core/http/src/uri/origin.rs @@ -270,7 +270,7 @@ impl<'a> Origin<'a> { /// assert!(normalized.is_normalized()); /// assert_eq!(normalized, Origin::parse("/a/b/c/d").unwrap()); /// ``` - pub fn to_normalized(&self) -> Origin { + pub fn to_normalized(&self) -> Origin<'_> { if self.is_normalized() { Origin::new(self.path(), self.query()) } else { @@ -403,7 +403,7 @@ impl<'a> Origin<'a> { /// } /// ``` #[inline(always)] - pub fn segments(&self) -> Segments { + pub fn segments(&self) -> Segments<'_> { Segments(self.path()) } @@ -441,7 +441,7 @@ impl<'a> Origin<'a> { } impl<'a> Display for Origin<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.path())?; if let Some(q) = self.query() { write!(f, "?{}", q)?; @@ -482,7 +482,7 @@ mod tests { #[test] fn send_and_sync() { fn assert() {}; - assert::(); + assert::>(); } #[test] diff --git a/core/http/src/uri/uri.rs b/core/http/src/uri/uri.rs index a179b0fd6e..d4b8dba3a1 100644 --- a/core/http/src/uri/uri.rs +++ b/core/http/src/uri/uri.rs @@ -90,7 +90,7 @@ impl<'a> Uri<'a> { /// // Invalid URIs fail to parse. /// Uri::parse("foo bar").expect_err("invalid URI"); /// ``` - pub fn parse(string: &'a str) -> Result, Error> { + pub fn parse(string: &'a str) -> Result, Error<'_>> { crate::parse::uri::from_str(string) } @@ -172,7 +172,7 @@ impl<'a> Uri<'a> { /// let encoded = Uri::percent_encode("hello?a=hi"); /// assert_eq!(encoded, "hello%3Fa%3D%3Cb%3Ehi%3C%2Fb%3E"); /// ``` - pub fn percent_encode(string: &str) -> Cow { + pub fn percent_encode(string: &str) -> Cow<'_, str> { percent_encode::(string) } @@ -188,7 +188,7 @@ impl<'a> Uri<'a> { /// let decoded = Uri::percent_decode("/Hello%2C%20world%21".as_bytes()); /// assert_eq!(decoded.unwrap(), "/Hello, world!"); /// ``` - pub fn percent_decode(string: &[u8]) -> Result, Utf8Error> { + pub fn percent_decode(string: &[u8]) -> Result, Utf8Error> { let decoder = ::percent_encoding::percent_decode(string); decoder.decode_utf8() } @@ -206,13 +206,13 @@ impl<'a> Uri<'a> { /// let decoded = Uri::percent_decode_lossy("/Hello%2C%20world%21".as_bytes()); /// assert_eq!(decoded, "/Hello, world!"); /// ``` - pub fn percent_decode_lossy(string: &[u8]) -> Cow { + pub fn percent_decode_lossy(string: &[u8]) -> Cow<'_, str> { let decoder = ::percent_encoding::percent_decode(string); decoder.decode_utf8_lossy() } } -crate unsafe fn as_utf8_unchecked(input: Cow<[u8]>) -> Cow { +crate unsafe fn as_utf8_unchecked(input: Cow<'_, [u8]>) -> Cow<'_, str> { match input { Cow::Borrowed(bytes) => Cow::Borrowed(::std::str::from_utf8_unchecked(bytes)), Cow::Owned(bytes) => Cow::Owned(String::from_utf8_unchecked(bytes)) @@ -254,7 +254,7 @@ impl<'a> IntoOwned for Uri<'a> { } impl<'a> Display for Uri<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Uri::Origin(ref origin) => write!(f, "{}", origin), Uri::Authority(ref authority) => write!(f, "{}", authority), diff --git a/core/http/src/uri/uri_display.rs b/core/http/src/uri/uri_display.rs index dedbc4b6b8..ef600bcacd 100644 --- a/core/http/src/uri/uri_display.rs +++ b/core/http/src/uri/uri_display.rs @@ -291,13 +291,13 @@ use crate::uri::{Uri, UriPart, Path, Query, Formatter}; /// ``` pub trait UriDisplay { /// Formats `self` in a URI-safe manner using the given formatter. - fn fmt(&self, f: &mut Formatter

) -> fmt::Result; + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result; } -impl<'a, P: UriPart> fmt::Display for &'a UriDisplay

{ +impl<'a, P: UriPart> fmt::Display for &'a dyn UriDisplay

{ #[inline(always)] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - UriDisplay::fmt(*self, &mut >::new(f)) + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + UriDisplay::fmt(*self, &mut >::new(f)) } } @@ -306,14 +306,14 @@ impl<'a, P: UriPart> fmt::Display for &'a UriDisplay

{ /// Percent-encodes the raw string. impl UriDisplay

for str { #[inline(always)] - fn fmt(&self, f: &mut Formatter

) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result { f.write_raw(&Uri::percent_encode(self)) } } /// Percent-encodes each segment in the path and normalizes separators. impl UriDisplay for path::Path { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, Path>) -> fmt::Result { use std::path::Component; for component in self.components() { @@ -332,7 +332,7 @@ macro_rules! impl_with_display { /// This implementation is identical to the `Display` implementation. impl UriDisplay

for $T { #[inline(always)] - fn fmt(&self, f: &mut Formatter

) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result { use std::fmt::Write; write!(f, "{}", self) } @@ -355,7 +355,7 @@ impl_with_display! { /// Percent-encodes the raw string. Defers to `str`. impl UriDisplay

for RawStr { #[inline(always)] - fn fmt(&self, f: &mut Formatter

) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result { self.as_str().fmt(f) } } @@ -363,7 +363,7 @@ impl UriDisplay

for RawStr { /// Percent-encodes the raw string. Defers to `str`. impl UriDisplay

for String { #[inline(always)] - fn fmt(&self, f: &mut Formatter

) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result { self.as_str().fmt(f) } } @@ -371,7 +371,7 @@ impl UriDisplay

for String { /// Percent-encodes the raw string. Defers to `str`. impl<'a, P: UriPart> UriDisplay

for Cow<'a, str> { #[inline(always)] - fn fmt(&self, f: &mut Formatter

) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result { self.as_ref().fmt(f) } } @@ -379,7 +379,7 @@ impl<'a, P: UriPart> UriDisplay

for Cow<'a, str> { /// Percent-encodes each segment in the path and normalizes separators. impl UriDisplay for path::PathBuf { #[inline(always)] - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, Path>) -> fmt::Result { self.as_path().fmt(f) } } @@ -387,7 +387,7 @@ impl UriDisplay for path::PathBuf { /// Defers to the `UriDisplay

` implementation for `T`. impl<'a, P: UriPart, T: UriDisplay

+ ?Sized> UriDisplay

for &'a T { #[inline(always)] - fn fmt(&self, f: &mut Formatter

) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result { UriDisplay::fmt(*self, f) } } @@ -395,7 +395,7 @@ impl<'a, P: UriPart, T: UriDisplay

+ ?Sized> UriDisplay

for &'a T { /// Defers to the `UriDisplay

` implementation for `T`. impl<'a, P: UriPart, T: UriDisplay

+ ?Sized> UriDisplay

for &'a mut T { #[inline(always)] - fn fmt(&self, f: &mut Formatter

) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, P>) -> fmt::Result { UriDisplay::fmt(*self, f) } } @@ -403,7 +403,7 @@ impl<'a, P: UriPart, T: UriDisplay

+ ?Sized> UriDisplay

for &'a mut T { /// Defers to the `UriDisplay` implementation for `T`. impl> UriDisplay for Option { #[inline(always)] - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, Query>) -> fmt::Result { match self { Some(v) => v.fmt(f), None => Ok(()) @@ -414,7 +414,7 @@ impl> UriDisplay for Option { /// Defers to the `UriDisplay` implementation for `T`. impl, E> UriDisplay for Result { #[inline(always)] - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_, Query>) -> fmt::Result { match self { Ok(v) => v.fmt(f), Err(_) => Ok(()) diff --git a/core/lib/src/catcher.rs b/core/lib/src/catcher.rs index fdaf558b01..ba3ad7ba2f 100644 --- a/core/lib/src/catcher.rs +++ b/core/lib/src/catcher.rs @@ -98,7 +98,7 @@ impl Catcher { } #[inline(always)] - crate fn handle<'r>(&self, req: &'r Request) -> response::Result<'r> { + crate fn handle<'r>(&self, req: &'r Request<'_>) -> response::Result<'r> { (self.handler)(req) } @@ -116,7 +116,7 @@ impl<'a> From<&'a StaticCatchInfo> for Catcher { } impl fmt::Display for Catcher { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", Blue.paint(&self.code)) } } @@ -149,7 +149,7 @@ macro_rules! default_catchers { let mut map = HashMap::new(); $( - fn $fn_name<'r>(req: &'r Request) -> response::Result<'r> { + fn $fn_name<'r>(req: &'r Request<'_>) -> response::Result<'r> { status::Custom(Status::from_code($code).unwrap(), content::Html(error_page_template!($code, $name, $description)) ).respond_to(req) diff --git a/core/lib/src/codegen.rs b/core/lib/src/codegen.rs index 7b750593d0..276eea1a32 100644 --- a/core/lib/src/codegen.rs +++ b/core/lib/src/codegen.rs @@ -3,7 +3,7 @@ use crate::handler::{Outcome, ErrorHandler}; use crate::http::{Method, MediaType}; /// Type of a static handler, which users annotate with Rocket's attribute. -pub type StaticHandler = for<'r> fn(&'r Request, Data) -> Outcome<'r>; +pub type StaticHandler = for<'r> fn(&'r Request<'_>, Data) -> Outcome<'r>; /// Information generated by the `route` attribute during codegen. pub struct StaticRouteInfo { diff --git a/core/lib/src/config/config.rs b/core/lib/src/config/config.rs index d32cddfca1..d622939b07 100644 --- a/core/lib/src/config/config.rs +++ b/core/lib/src/config/config.rs @@ -917,7 +917,7 @@ impl Config { } impl fmt::Debug for Config { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut s = f.debug_struct("Config"); s.field("environment", &self.environment); s.field("address", &self.address); diff --git a/core/lib/src/config/custom_values.rs b/core/lib/src/config/custom_values.rs index 5d28ea86b4..662efdd969 100644 --- a/core/lib/src/config/custom_values.rs +++ b/core/lib/src/config/custom_values.rs @@ -31,7 +31,7 @@ impl SecretKey { } impl fmt::Display for SecretKey { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[cfg(feature = "private-cookies")] match *self { SecretKey::Generated(_) => write!(f, "generated"), @@ -180,8 +180,8 @@ impl Limits { } impl fmt::Display for Limits { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fn fmt_size(n: u64, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt_size(n: u64, f: &mut fmt::Formatter<'_>) -> fmt::Result { if (n & ((1 << 20) - 1)) == 0 { write!(f, "{}MiB", n >> 20) } else if (n & ((1 << 10) - 1)) == 0 { diff --git a/core/lib/src/config/environment.rs b/core/lib/src/config/environment.rs index b582d2587c..e32e09be36 100644 --- a/core/lib/src/config/environment.rs +++ b/core/lib/src/config/environment.rs @@ -150,7 +150,7 @@ impl FromStr for Environment { } impl fmt::Display for Environment { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Development => write!(f, "development"), Staging => write!(f, "staging"), diff --git a/core/lib/src/config/error.rs b/core/lib/src/config/error.rs index f26b3bbbaa..e7041c8261 100644 --- a/core/lib/src/config/error.rs +++ b/core/lib/src/config/error.rs @@ -131,7 +131,7 @@ impl ConfigError { } impl fmt::Display for ConfigError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { NotFound => write!(f, "config file was not found"), IoError => write!(f, "I/O error while reading the config file"), diff --git a/core/lib/src/config/toml_ext.rs b/core/lib/src/config/toml_ext.rs index 6683a311b9..453b4dd062 100644 --- a/core/lib/src/config/toml_ext.rs +++ b/core/lib/src/config/toml_ext.rs @@ -24,7 +24,7 @@ fn is_not_separator(byte: char) -> bool { #[inline(always)] fn is_ident_char(byte: char) -> bool { match byte { - '0'...'9' | 'A'...'Z' | 'a'...'z' | '_' | '-' => true, + '0'..='9' | 'A'..='Z' | 'a'..='z' | '_' | '-' => true, _ => false } } @@ -85,7 +85,7 @@ crate struct LoggedValue<'a>(pub &'a Value); impl<'a> fmt::Display for LoggedValue<'a> { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use crate::config::Value::*; match *self.0 { String(_) | Integer(_) | Float(_) | Boolean(_) | Datetime(_) | Array(_) => { diff --git a/core/lib/src/data/data.rs b/core/lib/src/data/data.rs index d8a167ae6c..32ebb18193 100644 --- a/core/lib/src/data/data.rs +++ b/core/lib/src/data/data.rs @@ -15,7 +15,7 @@ use crate::http::hyper::h1::HttpReader::*; use crate::http::hyper::net::{HttpStream, NetworkStream}; pub type HyperBodyReader<'a, 'b> = - self::HttpReader<&'a mut hyper::buffer::BufReader<&'b mut NetworkStream>>; + self::HttpReader<&'a mut hyper::buffer::BufReader<&'b mut dyn NetworkStream>>; // |---- from hyper ----| pub type BodyReader = HttpReader>, NetStream>>; @@ -91,10 +91,10 @@ impl Data { } // FIXME: This is absolutely terrible (downcasting!), thanks to Hyper. - crate fn from_hyp(mut body: HyperBodyReader) -> Result { + crate fn from_hyp(mut body: HyperBodyReader<'_, '_>) -> Result { #[inline(always)] #[cfg(feature = "tls")] - fn concrete_stream(stream: &mut NetworkStream) -> Option { + fn concrete_stream(stream: &mut dyn NetworkStream) -> Option { stream.downcast_ref::() .map(|s| NetStream::Https(s.clone())) .or_else(|| { @@ -105,7 +105,7 @@ impl Data { #[inline(always)] #[cfg(not(feature = "tls"))] - fn concrete_stream(stream: &mut NetworkStream) -> Option { + fn concrete_stream(stream: &mut dyn NetworkStream) -> Option { stream.downcast_ref::() .map(|s| NetStream::Http(s.clone())) } diff --git a/core/lib/src/data/from_data.rs b/core/lib/src/data/from_data.rs index 386f5584fe..e07755c1da 100644 --- a/core/lib/src/data/from_data.rs +++ b/core/lib/src/data/from_data.rs @@ -354,7 +354,7 @@ pub trait FromData<'a>: Sized { /// If transformation succeeds, an outcome of `Success` is returned. /// If the data is not appropriate given the type of `Self`, `Forward` is /// returned. On failure, `Failure` is returned. - fn transform(request: &Request, data: Data) -> Transform>; + fn transform(request: &Request<'_>, data: Data) -> Transform>; /// Validates, parses, and converts the incoming request body data into an /// instance of `Self`. @@ -383,7 +383,7 @@ pub trait FromData<'a>: Sized { /// # unimplemented!() /// # } /// ``` - fn from_data(request: &Request, outcome: Transformed<'a, Self>) -> Outcome; + fn from_data(request: &Request<'_>, outcome: Transformed<'a, Self>) -> Outcome; } /// The identity implementation of `FromData`. Always returns `Success`. @@ -393,12 +393,12 @@ impl<'f> FromData<'f> for Data { type Borrowed = Data; #[inline(always)] - fn transform(_: &Request, data: Data) -> Transform> { + fn transform(_: &Request<'_>, data: Data) -> Transform> { Transform::Owned(Success(data)) } #[inline(always)] - fn from_data(_: &Request, outcome: Transformed<'f, Self>) -> Outcome { + fn from_data(_: &Request<'_>, outcome: Transformed<'f, Self>) -> Outcome { Success(outcome.owned()?) } } @@ -502,7 +502,7 @@ pub trait FromDataSimple: Sized { /// If validation and parsing succeeds, an outcome of `Success` is returned. /// If the data is not appropriate given the type of `Self`, `Forward` is /// returned. If parsing fails, `Failure` is returned. - fn from_data(request: &Request, data: Data) -> Outcome; + fn from_data(request: &Request<'_>, data: Data) -> Outcome; } impl<'a, T: FromDataSimple> FromData<'a> for T { @@ -511,12 +511,12 @@ impl<'a, T: FromDataSimple> FromData<'a> for T { type Borrowed = Data; #[inline(always)] - fn transform(_: &Request, d: Data) -> Transform> { + fn transform(_: &Request<'_>, d: Data) -> Transform> { Transform::Owned(Success(d)) } #[inline(always)] - fn from_data(req: &Request, o: Transformed<'a, Self>) -> Outcome { + fn from_data(req: &Request<'_>, o: Transformed<'a, Self>) -> Outcome { T::from_data(req, o.owned()?) } } @@ -527,12 +527,12 @@ impl<'a, T: FromData<'a> + 'a> FromData<'a> for Result { type Borrowed = T::Borrowed; #[inline(always)] - fn transform(r: &Request, d: Data) -> Transform> { + fn transform(r: &Request<'_>, d: Data) -> Transform> { T::transform(r, d) } #[inline(always)] - fn from_data(r: &Request, o: Transformed<'a, Self>) -> Outcome { + fn from_data(r: &Request<'_>, o: Transformed<'a, Self>) -> Outcome { match T::from_data(r, o) { Success(val) => Success(Ok(val)), Forward(data) => Forward(data), @@ -547,12 +547,12 @@ impl<'a, T: FromData<'a> + 'a> FromData<'a> for Option { type Borrowed = T::Borrowed; #[inline(always)] - fn transform(r: &Request, d: Data) -> Transform> { + fn transform(r: &Request<'_>, d: Data) -> Transform> { T::transform(r, d) } #[inline(always)] - fn from_data(r: &Request, o: Transformed<'a, Self>) -> Outcome { + fn from_data(r: &Request<'_>, o: Transformed<'a, Self>) -> Outcome { match T::from_data(r, o) { Success(val) => Success(Some(val)), Failure(_) | Forward(_) => Success(None), @@ -568,7 +568,7 @@ impl FromDataSimple for String { type Error = io::Error; #[inline(always)] - fn from_data(_: &Request, data: Data) -> Outcome { + fn from_data(_: &Request<'_>, data: Data) -> Outcome { let mut string = String::new(); match data.open().read_to_string(&mut string) { Ok(_) => Success(string), @@ -582,7 +582,7 @@ impl FromDataSimple for Vec { type Error = io::Error; #[inline(always)] - fn from_data(_: &Request, data: Data) -> Outcome { + fn from_data(_: &Request<'_>, data: Data) -> Outcome { let mut bytes = Vec::new(); match data.open().read_to_end(&mut bytes) { Ok(_) => Success(bytes), diff --git a/core/lib/src/error.rs b/core/lib/src/error.rs index 4d05ff3b94..9f2e7cb2eb 100644 --- a/core/lib/src/error.rs +++ b/core/lib/src/error.rs @@ -27,7 +27,7 @@ pub enum LaunchErrorKind { /// A launch fairing reported an error. FailedFairings(Vec<&'static str>), /// An otherwise uncategorized error occurred during launch. - Unknown(Box<::std::error::Error + Send + Sync>) + Unknown(Box) } /// An error that occurs during launch. @@ -139,7 +139,7 @@ impl From for LaunchError { impl fmt::Display for LaunchErrorKind { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { LaunchErrorKind::Bind(ref e) => write!(f, "binding failed: {}", e), LaunchErrorKind::Io(ref e) => write!(f, "I/O error: {}", e), @@ -152,7 +152,7 @@ impl fmt::Display for LaunchErrorKind { impl fmt::Debug for LaunchError { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.mark_handled(); write!(f, "{:?}", self.kind()) } @@ -160,7 +160,7 @@ impl fmt::Debug for LaunchError { impl fmt::Display for LaunchError { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.mark_handled(); write!(f, "{}", self.kind()) } @@ -248,7 +248,7 @@ impl<'a> From> for RouteUriError { } impl fmt::Display for RouteUriError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { RouteUriError::Segment => { write!(f, "The URI contains malformed dynamic route path segments.") diff --git a/core/lib/src/fairing/ad_hoc.rs b/core/lib/src/fairing/ad_hoc.rs index 2be4b25c25..1952b6d4b5 100644 --- a/core/lib/src/fairing/ad_hoc.rs +++ b/core/lib/src/fairing/ad_hoc.rs @@ -46,10 +46,10 @@ enum AdHocKind { /// An ad-hoc **launch** fairing. Called just before Rocket launches. Launch(Mutex>>), /// An ad-hoc **request** fairing. Called when a request is received. - Request(Box), + Request(Box, &Data) + Send + Sync + 'static>), /// An ad-hoc **response** fairing. Called when a response is ready to be /// sent to a client. - Response(Box), + Response(Box, &mut Response<'_>) + Send + Sync + 'static>), } impl AdHoc { @@ -104,7 +104,7 @@ impl AdHoc { /// }); /// ``` pub fn on_request(name: &'static str, f: F) -> AdHoc - where F: Fn(&mut Request, &Data) + Send + Sync + 'static + where F: Fn(&mut Request<'_>, &Data) + Send + Sync + 'static { AdHoc { name, kind: AdHocKind::Request(Box::new(f)) } } @@ -124,7 +124,7 @@ impl AdHoc { /// }); /// ``` pub fn on_response(name: &'static str, f: F) -> AdHoc - where F: Fn(&Request, &mut Response) + Send + Sync + 'static + where F: Fn(&Request<'_>, &mut Response<'_>) + Send + Sync + 'static { AdHoc { name, kind: AdHocKind::Response(Box::new(f)) } } @@ -160,13 +160,13 @@ impl Fairing for AdHoc { } } - fn on_request(&self, request: &mut Request, data: &Data) { + fn on_request(&self, request: &mut Request<'_>, data: &Data) { if let AdHocKind::Request(ref callback) = self.kind { callback(request, data) } } - fn on_response(&self, request: &Request, response: &mut Response) { + fn on_response(&self, request: &Request<'_>, response: &mut Response<'_>) { if let AdHocKind::Response(ref callback) = self.kind { callback(request, response) } diff --git a/core/lib/src/fairing/fairings.rs b/core/lib/src/fairing/fairings.rs index 73c86ea135..a0425f1e2d 100644 --- a/core/lib/src/fairing/fairings.rs +++ b/core/lib/src/fairing/fairings.rs @@ -5,7 +5,7 @@ use yansi::Paint; #[derive(Default)] pub struct Fairings { - all_fairings: Vec>, + all_fairings: Vec>, attach_failures: Vec<&'static str>, // The vectors below hold indices into `all_fairings`. launch: Vec, @@ -19,7 +19,7 @@ impl Fairings { Fairings::default() } - pub fn attach(&mut self, fairing: Box, mut rocket: Rocket) -> Rocket { + pub fn attach(&mut self, fairing: Box, mut rocket: Rocket) -> Rocket { // Run the `on_attach` callback if this is an 'attach' fairing. let kind = fairing.info().kind; let name = fairing.info().name; @@ -32,7 +32,7 @@ impl Fairings { rocket } - fn add(&mut self, fairing: Box) { + fn add(&mut self, fairing: Box) { let kind = fairing.info().kind; if !kind.is_exactly(Kind::Attach) { let index = self.all_fairings.len(); @@ -58,14 +58,14 @@ impl Fairings { } #[inline(always)] - pub fn handle_request(&self, req: &mut Request, data: &Data) { + pub fn handle_request(&self, req: &mut Request<'_>, data: &Data) { for &i in &self.request { self.all_fairings[i].on_request(req, data); } } #[inline(always)] - pub fn handle_response(&self, request: &Request, response: &mut Response) { + pub fn handle_response(&self, request: &Request<'_>, response: &mut Response<'_>) { for &i in &self.response { self.all_fairings[i].on_response(request, response); } diff --git a/core/lib/src/fairing/mod.rs b/core/lib/src/fairing/mod.rs index 0dc20d4157..5ced986b2f 100644 --- a/core/lib/src/fairing/mod.rs +++ b/core/lib/src/fairing/mod.rs @@ -395,7 +395,7 @@ pub trait Fairing: Send + Sync + 'static { /// /// The default implementation of this method does nothing. #[allow(unused_variables)] - fn on_request(&self, request: &mut Request, data: &Data) {} + fn on_request(&self, request: &mut Request<'_>, data: &Data) {} /// The response callback. /// @@ -408,7 +408,7 @@ pub trait Fairing: Send + Sync + 'static { /// /// The default implementation of this method does nothing. #[allow(unused_variables)] - fn on_response(&self, request: &Request, response: &mut Response) {} + fn on_response(&self, request: &Request<'_>, response: &mut Response<'_>) {} } impl Fairing for ::std::sync::Arc { @@ -428,12 +428,12 @@ impl Fairing for ::std::sync::Arc { } #[inline] - fn on_request(&self, request: &mut Request, data: &Data) { + fn on_request(&self, request: &mut Request<'_>, data: &Data) { (self as &T).on_request(request, data) } #[inline] - fn on_response(&self, request: &Request, response: &mut Response) { + fn on_response(&self, request: &Request<'_>, response: &mut Response<'_>) { (self as &T).on_response(request, response) } } diff --git a/core/lib/src/handler.rs b/core/lib/src/handler.rs index 771207a371..66a4c1a8a2 100644 --- a/core/lib/src/handler.rs +++ b/core/lib/src/handler.rs @@ -142,7 +142,7 @@ pub trait Handler: Cloneable + Send + Sync + 'static { /// a response. Otherwise, if the return value is `Forward(Data)`, the next /// matching route is attempted. If there are no other matching routes, the /// `404` error catcher is invoked. - fn handle<'r>(&self, request: &'r Request, data: Data) -> Outcome<'r>; + fn handle<'r>(&self, request: &'r Request<'_>, data: Data) -> Outcome<'r>; } /// Unfortunate but necessary hack to be able to clone a `Box`. @@ -152,34 +152,34 @@ pub trait Handler: Cloneable + Send + Sync + 'static { /// `Handler` automatically implement `Cloneable`. pub trait Cloneable { /// Clones `self`. - fn clone_handler(&self) -> Box; + fn clone_handler(&self) -> Box; } impl Cloneable for T { #[inline(always)] - fn clone_handler(&self) -> Box { + fn clone_handler(&self) -> Box { Box::new(self.clone()) } } -impl Clone for Box { +impl Clone for Box { #[inline(always)] - fn clone(&self) -> Box { + fn clone(&self) -> Box { self.clone_handler() } } impl Handler for F - where for<'r> F: Fn(&'r Request, Data) -> Outcome<'r> + where for<'r> F: Fn(&'r Request<'_>, Data) -> Outcome<'r> { #[inline(always)] - fn handle<'r>(&self, req: &'r Request, data: Data) -> Outcome<'r> { + fn handle<'r>(&self, req: &'r Request<'_>, data: Data) -> Outcome<'r> { self(req, data) } } /// The type of an error handler. -pub type ErrorHandler = for<'r> fn(&'r Request) -> response::Result<'r>; +pub type ErrorHandler = for<'r> fn(&'r Request<'_>) -> response::Result<'r>; impl<'r> Outcome<'r> { /// Return the `Outcome` of response to `req` from `responder`. @@ -199,7 +199,7 @@ impl<'r> Outcome<'r> { /// } /// ``` #[inline] - pub fn from>(req: &Request, responder: T) -> Outcome<'r> { + pub fn from>(req: &Request<'_>, responder: T) -> Outcome<'r> { match responder.respond_to(req) { Ok(response) => outcome::Outcome::Success(response), Err(status) => outcome::Outcome::Failure(status) diff --git a/core/lib/src/lib.rs b/core/lib/src/lib.rs index 033895086a..8481e8318e 100644 --- a/core/lib/src/lib.rs +++ b/core/lib/src/lib.rs @@ -12,6 +12,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)] + //! # Rocket - Core API Documentation //! //! Hello, and welcome to the core Rocket API documentation! @@ -99,17 +101,8 @@ #[allow(unused_imports)] #[macro_use] extern crate rocket_codegen; #[doc(hidden)] pub use rocket_codegen::*; -extern crate rocket_http; #[macro_use] extern crate log; #[macro_use] extern crate pear; -extern crate yansi; -extern crate toml; -extern crate num_cpus; -extern crate state; -extern crate time; -extern crate memchr; -extern crate base64; -extern crate atty; #[cfg(test)] #[macro_use] extern crate lazy_static; diff --git a/core/lib/src/local/request.rs b/core/lib/src/local/request.rs index ee06133e78..e5e20828a6 100644 --- a/core/lib/src/local/request.rs +++ b/core/lib/src/local/request.rs @@ -119,7 +119,7 @@ impl<'c> LocalRequest<'c> { // See the comments on the structure for what's going on here. let mut request = Rc::new(request); - let ptr = Rc::get_mut(&mut request).unwrap() as *mut Request; + let ptr = Rc::get_mut(&mut request).unwrap() as *mut Request<'_>; LocalRequest { client, ptr, request, uri, data: vec![] } } @@ -236,7 +236,7 @@ impl<'c> LocalRequest<'c> { /// .cookie(Cookie::new("user_id", "12")); /// ``` #[inline] - pub fn cookie(self, cookie: Cookie) -> Self { + pub fn cookie(self, cookie: Cookie<'_>) -> Self { self.request.cookies().add_original(cookie.into_owned()); self } @@ -257,7 +257,7 @@ impl<'c> LocalRequest<'c> { /// let req = client.get("/").cookies(cookies); /// ``` #[inline] - pub fn cookies(self, cookies: Vec) -> Self { + pub fn cookies(self, cookies: Vec>) -> Self { for cookie in cookies { self.request.cookies().add_original(cookie.into_owned()); } @@ -435,7 +435,7 @@ impl<'c> LocalRequest<'c> { } impl<'c> fmt::Debug for LocalRequest<'c> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.request, f) } } @@ -469,7 +469,7 @@ impl<'c> DerefMut for LocalResponse<'c> { } impl<'c> fmt::Debug for LocalResponse<'c> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.response, f) } } diff --git a/core/lib/src/logger.rs b/core/lib/src/logger.rs index bd31d68155..4936dc92ea 100644 --- a/core/lib/src/logger.rs +++ b/core/lib/src/logger.rs @@ -52,7 +52,7 @@ impl FromStr for LoggingLevel { } impl fmt::Display for LoggingLevel { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let string = match *self { LoggingLevel::Critical => "critical", LoggingLevel::Normal => "normal", @@ -83,14 +83,14 @@ macro_rules! warn_ { ($($args:expr),+) => { log_!(warn: $($args),+); }; } impl log::Log for RocketLogger { #[inline(always)] - fn enabled(&self, record: &log::Metadata) -> bool { + fn enabled(&self, record: &log::Metadata<'_>) -> bool { match self.0.to_level_filter().to_level() { Some(max) => record.level() <= max || record.target().starts_with("launch"), None => false } } - fn log(&self, record: &log::Record) { + fn log(&self, record: &log::Record<'_>) { // Print nothing if this level isn't enabled and this isn't launch info. if !self.enabled(record.metadata()) { return; diff --git a/core/lib/src/outcome.rs b/core/lib/src/outcome.rs index e635ccaa26..cadb812f93 100644 --- a/core/lib/src/outcome.rs +++ b/core/lib/src/outcome.rs @@ -625,13 +625,13 @@ impl Try for Outcome { } impl fmt::Debug for Outcome { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Outcome::{}", self.formatting().1) } } impl fmt::Display for Outcome { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (color, string) = self.formatting(); write!(f, "{}", Paint::default(string).fg(color)) } diff --git a/core/lib/src/request/form/form.rs b/core/lib/src/request/form/form.rs index 94f4ec1517..ac60e41c3b 100644 --- a/core/lib/src/request/form/form.rs +++ b/core/lib/src/request/form/form.rs @@ -190,7 +190,7 @@ impl<'f, T: FromForm<'f>> FromData<'f> for Form { type Borrowed = str; fn transform( - request: &Request, + request: &Request<'_>, data: Data ) -> Transform> { use std::{cmp::min, io::Read}; @@ -214,7 +214,7 @@ impl<'f, T: FromForm<'f>> FromData<'f> for Form { Transform::Borrowed(outcome) } - fn from_data(_: &Request, o: Transformed<'f, Self>) -> Outcome { + fn from_data(_: &Request<'_>, o: Transformed<'f, Self>) -> Outcome { >::from_data(o.borrowed()?, true).map(Form) } } diff --git a/core/lib/src/request/form/lenient.rs b/core/lib/src/request/form/lenient.rs index d5dd73d120..4cae348f11 100644 --- a/core/lib/src/request/form/lenient.rs +++ b/core/lib/src/request/form/lenient.rs @@ -100,11 +100,11 @@ impl<'f, T: FromForm<'f>> FromData<'f> for LenientForm { type Owned = String; type Borrowed = str; - fn transform(r: &Request, d: Data) -> Transform> { + fn transform(r: &Request<'_>, d: Data) -> Transform> { >::transform(r, d) } - fn from_data(_: &Request, o: Transformed<'f, Self>) -> Outcome { + fn from_data(_: &Request<'_>, o: Transformed<'f, Self>) -> Outcome { >::from_data(o.borrowed()?, false).map(LenientForm) } } diff --git a/core/lib/src/request/request.rs b/core/lib/src/request/request.rs index f83009f786..f56f7b7c25 100644 --- a/core/lib/src/request/request.rs +++ b/core/lib/src/request/request.rs @@ -135,7 +135,7 @@ impl<'r> Request<'r> { /// # }); /// ``` #[inline(always)] - pub fn uri(&self) -> &Origin { + pub fn uri(&self) -> &Origin<'_> { &self.uri } @@ -287,7 +287,7 @@ impl<'r> Request<'r> { /// request.cookies().add(Cookie::new("ans", format!("life: {}", 38 + 4))); /// # }); /// ``` - pub fn cookies(&self) -> Cookies { + pub fn cookies(&self) -> Cookies<'_> { // FIXME: Can we do better? This is disappointing. match self.state.cookies.try_borrow_mut() { Ok(jar) => Cookies::new(jar, self.state.config.secret_key()), @@ -696,7 +696,7 @@ impl<'r> Request<'r> { #[doc(hidden)] impl<'r> Request<'r> { // Only used by doc-tests! Needs to be `pub` because doc-test are external. - pub fn example(method: Method, uri: &str, f: F) { + pub fn example)>(method: Method, uri: &str, f: F) { let rocket = Rocket::custom(Config::development()); let uri = Origin::parse(uri).expect("invalid URI in example"); let mut request = Request::new(&rocket, method, uri); @@ -732,7 +732,7 @@ impl<'r> Request<'r> { /// Get the segments beginning at the `n`th, 0-indexed, after the mount /// point for the currently matched route, if they exist. Used by codegen. #[inline] - pub fn raw_segments(&self, n: usize) -> Option { + pub fn raw_segments(&self, n: usize) -> Option> { self.routed_path_segment(n) .map(|(i, _)| Segments(&self.uri.path()[i..]) ) } @@ -759,7 +759,7 @@ impl<'r> Request<'r> { #[inline] pub fn raw_query_items( &self - ) -> Option + DoubleEndedIterator + Clone> { + ) -> Option> + DoubleEndedIterator + Clone> { let query = self.uri.query()?; self.state.query_items.as_ref().map(move |items| { items.iter().map(move |item| item.convert(query)) @@ -843,7 +843,7 @@ impl<'r> Request<'r> { } impl<'r> fmt::Debug for Request<'r> { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Request") .field("method", &self.method) .field("uri", &self.uri) @@ -856,7 +856,7 @@ impl<'r> fmt::Debug for Request<'r> { impl<'r> fmt::Display for Request<'r> { /// Pretty prints a Request. This is primarily used by Rocket's logging /// infrastructure. - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{} {}", Paint::green(self.method()), Paint::blue(&self.uri))?; // Print the requests media type when the route specifies a format. @@ -872,7 +872,7 @@ impl<'r> fmt::Display for Request<'r> { impl IndexedFormItem { #[inline(always)] - fn from(s: &str, i: FormItem) -> Self { + fn from(s: &str, i: FormItem<'_>) -> Self { let (r, k, v) = (indices(i.raw, s), indices(i.key, s), indices(i.value, s)); IndexedFormItem { raw: r, key: k, value: v } } diff --git a/core/lib/src/response/content.rs b/core/lib/src/response/content.rs index 44409be9d0..84cb60cb4c 100644 --- a/core/lib/src/response/content.rs +++ b/core/lib/src/response/content.rs @@ -48,7 +48,7 @@ pub struct Content(pub ContentType, pub R); /// delegates the remainder of the response to the wrapped responder. impl<'r, R: Responder<'r>> Responder<'r> for Content { #[inline(always)] - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { Response::build() .merge(self.1.respond_to(req)?) .header(self.0) @@ -72,7 +72,7 @@ macro_rules! ctrs { /// Sets the Content-Type of the response then delegates the /// remainder of the response to the wrapped responder. impl<'r, R: Responder<'r>> Responder<'r> for $name { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { Content(ContentType::$ct, self.0).respond_to(req) } } diff --git a/core/lib/src/response/flash.rs b/core/lib/src/response/flash.rs index bcdf2219fe..8bbc4c3960 100644 --- a/core/lib/src/response/flash.rs +++ b/core/lib/src/response/flash.rs @@ -194,7 +194,7 @@ impl<'r, R: Responder<'r>> Flash { /// response handling to the wrapped responder. As a result, the `Outcome` of /// the response is the `Outcome` of the wrapped `Responder`. impl<'r, R: Responder<'r>> Responder<'r> for Flash { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { trace_!("Flash: setting message: {}:{}", self.name, self.message); req.cookies().add(self.cookie()); self.inner.respond_to(req) diff --git a/core/lib/src/response/named_file.rs b/core/lib/src/response/named_file.rs index 9aa4994edf..ce6d2cd9db 100644 --- a/core/lib/src/response/named_file.rs +++ b/core/lib/src/response/named_file.rs @@ -79,7 +79,7 @@ impl NamedFile { /// you would like to stream a file with a different Content-Type than that /// implied by its extension, use a [`File`] directly. impl<'r> Responder<'r> for NamedFile { - fn respond_to(self, req: &Request) -> response::Result<'r> { + fn respond_to(self, req: &Request<'_>) -> response::Result<'r> { let mut response = self.1.respond_to(req)?; if let Some(ext) = self.0.extension() { if let Some(ct) = ContentType::from_extension(&ext.to_string_lossy()) { diff --git a/core/lib/src/response/redirect.rs b/core/lib/src/response/redirect.rs index 0d8318662c..0fdaa09a3b 100644 --- a/core/lib/src/response/redirect.rs +++ b/core/lib/src/response/redirect.rs @@ -148,7 +148,7 @@ impl Redirect { /// value used to create the `Responder` is an invalid URI, an error of /// `Status::InternalServerError` is returned. impl<'a> Responder<'a> for Redirect { - fn respond_to(self, _: &Request) -> Result, Status> { + fn respond_to(self, _: &Request<'_>) -> Result, Status> { if let Some(uri) = self.1 { Response::build() .status(self.0) diff --git a/core/lib/src/response/responder.rs b/core/lib/src/response/responder.rs index 6c8b85f49f..877a42799f 100644 --- a/core/lib/src/response/responder.rs +++ b/core/lib/src/response/responder.rs @@ -192,13 +192,13 @@ pub trait Responder<'r> { /// returned, the error catcher for the given status is retrieved and called /// to generate a final error response, which is then written out to the /// client. - fn respond_to(self, request: &Request) -> response::Result<'r>; + fn respond_to(self, request: &Request<'_>) -> response::Result<'r>; } /// Returns a response with Content-Type `text/plain` and a fixed-size body /// containing the string `self`. Always returns `Ok`. impl<'r> Responder<'r> for &'r str { - fn respond_to(self, _: &Request) -> response::Result<'r> { + fn respond_to(self, _: &Request<'_>) -> response::Result<'r> { Response::build() .header(ContentType::Plain) .sized_body(Cursor::new(self)) @@ -209,7 +209,7 @@ impl<'r> Responder<'r> for &'r str { /// Returns a response with Content-Type `text/plain` and a fixed-size body /// containing the string `self`. Always returns `Ok`. impl<'r> Responder<'r> for String { - fn respond_to(self, _: &Request) -> response::Result<'r> { + fn respond_to(self, _: &Request<'_>) -> response::Result<'r> { Response::build() .header(ContentType::Plain) .sized_body(Cursor::new(self)) @@ -220,7 +220,7 @@ impl<'r> Responder<'r> for String { /// Returns a response with Content-Type `application/octet-stream` and a /// fixed-size body containing the data in `self`. Always returns `Ok`. impl<'r> Responder<'r> for &'r [u8] { - fn respond_to(self, _: &Request) -> response::Result<'r> { + fn respond_to(self, _: &Request<'_>) -> response::Result<'r> { Response::build() .header(ContentType::Binary) .sized_body(Cursor::new(self)) @@ -231,7 +231,7 @@ impl<'r> Responder<'r> for &'r [u8] { /// Returns a response with Content-Type `application/octet-stream` and a /// fixed-size body containing the data in `self`. Always returns `Ok`. impl<'r> Responder<'r> for Vec { - fn respond_to(self, _: &Request) -> response::Result<'r> { + fn respond_to(self, _: &Request<'_>) -> response::Result<'r> { Response::build() .header(ContentType::Binary) .sized_body(Cursor::new(self)) @@ -241,7 +241,7 @@ impl<'r> Responder<'r> for Vec { /// Returns a response with a sized body for the file. Always returns `Ok`. impl<'r> Responder<'r> for File { - fn respond_to(self, _: &Request) -> response::Result<'r> { + fn respond_to(self, _: &Request<'_>) -> response::Result<'r> { let (metadata, file) = (self.metadata(), BufReader::new(self)); match metadata { Ok(md) => Response::build().raw_body(Body::Sized(file, md.len())).ok(), @@ -252,7 +252,7 @@ impl<'r> Responder<'r> for File { /// Returns an empty, default `Response`. Always returns `Ok`. impl<'r> Responder<'r> for () { - fn respond_to(self, _: &Request) -> response::Result<'r> { + fn respond_to(self, _: &Request<'_>) -> response::Result<'r> { Ok(Response::new()) } } @@ -260,7 +260,7 @@ impl<'r> Responder<'r> for () { /// If `self` is `Some`, responds with the wrapped `Responder`. Otherwise prints /// a warning message and returns an `Err` of `Status::NotFound`. impl<'r, R: Responder<'r>> Responder<'r> for Option { - fn respond_to(self, req: &Request) -> response::Result<'r> { + fn respond_to(self, req: &Request<'_>) -> response::Result<'r> { self.map_or_else(|| { warn_!("Response was `None`."); Err(Status::NotFound) @@ -272,7 +272,7 @@ impl<'r, R: Responder<'r>> Responder<'r> for Option { /// an error message with the `Err` value returns an `Err` of /// `Status::InternalServerError`. impl<'r, R: Responder<'r>, E: fmt::Debug> Responder<'r> for Result { - default fn respond_to(self, req: &Request) -> response::Result<'r> { + default fn respond_to(self, req: &Request<'_>) -> response::Result<'r> { self.map(|r| r.respond_to(req)).unwrap_or_else(|e| { error_!("Response was a non-`Responder` `Err`: {:?}.", e); Err(Status::InternalServerError) @@ -283,7 +283,7 @@ impl<'r, R: Responder<'r>, E: fmt::Debug> Responder<'r> for Result { /// Responds with the wrapped `Responder` in `self`, whether it is `Ok` or /// `Err`. impl<'r, R: Responder<'r>, E: Responder<'r> + fmt::Debug> Responder<'r> for Result { - fn respond_to(self, req: &Request) -> response::Result<'r> { + fn respond_to(self, req: &Request<'_>) -> response::Result<'r> { match self { Ok(responder) => responder.respond_to(req), Err(responder) => responder.respond_to(req), @@ -306,7 +306,7 @@ impl<'r, R: Responder<'r>, E: Responder<'r> + fmt::Debug> Responder<'r> for Resu /// status code emit an error message and forward to the `500` (internal server /// error) catcher. impl<'r> Responder<'r> for Status { - fn respond_to(self, _: &Request) -> response::Result<'r> { + fn respond_to(self, _: &Request<'_>) -> response::Result<'r> { match self.class() { StatusClass::ClientError | StatusClass::ServerError => Err(self), StatusClass::Success if self.code < 206 => { diff --git a/core/lib/src/response/response.rs b/core/lib/src/response/response.rs index ef13fbd59f..40f92b58c0 100644 --- a/core/lib/src/response/response.rs +++ b/core/lib/src/response/response.rs @@ -88,7 +88,7 @@ impl Body { } impl fmt::Debug for Body { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Body::Sized(_, n) => writeln!(f, "Sized Body [{} bytes]", n), Body::Chunked(_, n) => writeln!(f, "Chunked Body [{} bytes]", n), @@ -560,7 +560,7 @@ impl<'r> ResponseBuilder<'r> { pub struct Response<'r> { status: Option, headers: HeaderMap<'r>, - body: Option>>, + body: Option>>, } impl<'r> Response<'r> { @@ -707,7 +707,7 @@ impl<'r> Response<'r> { /// response.set_header(Cookie::new("hello", "world!")); /// assert_eq!(response.cookies(), vec![Cookie::new("hello", "world!")]); /// ``` - pub fn cookies(&self) -> Vec { + pub fn cookies(&self) -> Vec> { let mut cookies = vec![]; for header in self.headers().get("Set-Cookie") { if let Ok(cookie) = Cookie::parse_encoded(header) { @@ -889,7 +889,7 @@ impl<'r> Response<'r> { /// assert_eq!(response.body_string(), Some("Hello, world!".to_string())); /// ``` #[inline(always)] - pub fn body(&mut self) -> Option> { + pub fn body(&mut self) -> Option> { // Looks crazy, right? Needed so Rust infers lifetime correctly. Weird. match self.body.as_mut() { Some(body) => Some(match body.as_mut() { @@ -966,7 +966,7 @@ impl<'r> Response<'r> { /// assert!(response.body().is_none()); /// ``` #[inline(always)] - pub fn take_body(&mut self) -> Option>> { + pub fn take_body(&mut self) -> Option>> { self.body.take() } @@ -1177,7 +1177,7 @@ impl<'r> Response<'r> { } impl<'r> fmt::Debug for Response<'r> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "{}", self.status())?; for header in self.headers().iter() { @@ -1195,7 +1195,7 @@ use crate::request::Request; impl<'r> Responder<'r> for Response<'r> { /// This is the identity implementation. It simply returns `Ok(self)`. - fn respond_to(self, _: &Request) -> Result, Status> { + fn respond_to(self, _: &Request<'_>) -> Result, Status> { Ok(self) } } diff --git a/core/lib/src/response/status.rs b/core/lib/src/response/status.rs index 3d8386dee0..2753e7750d 100644 --- a/core/lib/src/response/status.rs +++ b/core/lib/src/response/status.rs @@ -41,7 +41,7 @@ pub struct Created(pub String, pub Option); /// information about the created resource. If no responder is provided, the /// response body will be empty. impl<'r, R: Responder<'r>> Responder<'r> for Created { - default fn respond_to(self, req: &Request) -> Result, Status> { + default fn respond_to(self, req: &Request<'_>) -> Result, Status> { let mut build = Response::build(); if let Some(responder) = self.1 { build.merge(responder.respond_to(req)?); @@ -56,7 +56,7 @@ impl<'r, R: Responder<'r>> Responder<'r> for Created { /// a `Responder` is provided that implements `Hash`. The `ETag` header is set /// to a hash value of the responder. impl<'r, R: Responder<'r> + Hash> Responder<'r> for Created { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { let mut hasher = DefaultHasher::default(); let mut build = Response::build(); if let Some(responder) = self.1 { @@ -101,7 +101,7 @@ pub struct Accepted(pub Option); /// Sets the status code of the response to 202 Accepted. If the responder is /// `Some`, it is used to finalize the response. impl<'r, R: Responder<'r>> Responder<'r> for Accepted { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { let mut build = Response::build(); if let Some(responder) = self.0 { build.merge(responder.respond_to(req)?); @@ -141,7 +141,7 @@ pub struct BadRequest(pub Option); /// Sets the status code of the response to 400 Bad Request. If the responder is /// `Some`, it is used to finalize the response. impl<'r, R: Responder<'r>> Responder<'r> for BadRequest { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { let mut build = Response::build(); if let Some(responder) = self.0 { build.merge(responder.respond_to(req)?); @@ -168,7 +168,7 @@ pub struct NotFound(pub R); /// Sets the status code of the response to 404 Not Found. impl<'r, R: Responder<'r>> Responder<'r> for NotFound { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { Response::build_from(self.0.respond_to(req)?) .status(Status::NotFound) .ok() @@ -192,7 +192,7 @@ pub struct Custom(pub Status, pub R); /// Sets the status code of the response and then delegates the remainder of the /// response to the wrapped responder. impl<'r, R: Responder<'r>> Responder<'r> for Custom { - fn respond_to(self, req: &Request) -> Result, Status> { + fn respond_to(self, req: &Request<'_>) -> Result, Status> { Response::build_from(self.1.respond_to(req)?) .status(self.0) .ok() diff --git a/core/lib/src/response/stream.rs b/core/lib/src/response/stream.rs index 032393e1b8..84e106cc57 100644 --- a/core/lib/src/response/stream.rs +++ b/core/lib/src/response/stream.rs @@ -35,7 +35,7 @@ impl Stream { } impl Debug for Stream { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Stream({:?})", self.0) } } @@ -69,7 +69,7 @@ impl From for Stream { /// response is abandoned, and the response ends abruptly. An error is printed /// to the console with an indication of what went wrong. impl<'r, T: Read + 'r> Responder<'r> for Stream { - fn respond_to(self, _: &Request) -> Result, Status> { + fn respond_to(self, _: &Request<'_>) -> Result, Status> { Response::build().chunked_body(self.0, self.1).ok() } } diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs index 2117953cfc..469ad30bef 100644 --- a/core/lib/src/rocket.rs +++ b/core/lib/src/rocket.rs @@ -115,7 +115,7 @@ macro_rules! serve { impl Rocket { #[inline] - fn issue_response(&self, response: Response, hyp_res: hyper::FreshResponse) { + fn issue_response(&self, response: Response<'_>, hyp_res: hyper::FreshResponse<'_>) { match self.write_response(response, hyp_res) { Ok(_) => info_!("{}", Paint::green("Response succeeded.")), Err(e) => error_!("Failed to write response: {:?}.", e), @@ -125,8 +125,8 @@ impl Rocket { #[inline] fn write_response( &self, - mut response: Response, - mut hyp_res: hyper::FreshResponse, + mut response: Response<'_>, + mut hyp_res: hyper::FreshResponse<'_>, ) -> io::Result<()> { *hyp_res.status_mut() = hyper::StatusCode::from_u16(response.status().code); @@ -175,7 +175,7 @@ impl Rocket { /// * Rewriting the method in the request if _method form field exists. /// /// Keep this in-sync with derive_form when preprocessing form fields. - fn preprocess_request(&self, req: &mut Request, data: &Data) { + fn preprocess_request(&self, req: &mut Request<'_>, data: &Data) { // Check if this is a form and if the form contains the special _method // field which we use to reinterpret the request's method. let data_len = data.peek().len(); @@ -313,7 +313,7 @@ impl Rocket { crate fn handle_error<'r>( &self, status: Status, - req: &'r Request + req: &'r Request<'_> ) -> Response<'r> { warn_!("Responding with {} catcher.", Paint::red(&status)); diff --git a/core/lib/src/router/collider.rs b/core/lib/src/router/collider.rs index d49d75cc03..f3b1aa68d8 100644 --- a/core/lib/src/router/collider.rs +++ b/core/lib/src/router/collider.rs @@ -38,7 +38,7 @@ impl Route { /// request query string, though in any position. /// - If no query in route, requests with/without queries match. #[doc(hidden)] - pub fn matches(&self, req: &Request) -> bool { + pub fn matches(&self, req: &Request<'_>) -> bool { self.method == req.method() && paths_match(self, req) && queries_match(self, req) @@ -64,7 +64,7 @@ fn paths_collide(route: &Route, other: &Route) -> bool { a_segments.len() == b_segments.len() } -fn paths_match(route: &Route, request: &Request) -> bool { +fn paths_match(route: &Route, request: &Request<'_>) -> bool { let route_segments = &route.metadata.path_segments; if route_segments.len() > request.state.path_segments.len() { return false; @@ -82,7 +82,7 @@ fn paths_match(route: &Route, request: &Request) -> bool { route_segments.len() == request.state.path_segments.len() } -fn queries_match(route: &Route, request: &Request) -> bool { +fn queries_match(route: &Route, request: &Request<'_>) -> bool { if route.metadata.fully_dynamic_query { return true; } @@ -126,7 +126,7 @@ fn formats_collide(route: &Route, other: &Route) -> bool { } } -fn formats_match(route: &Route, request: &Request) -> bool { +fn formats_match(route: &Route, request: &Request<'_>) -> bool { if !route.method.supports_payload() { route.format.as_ref() .and_then(|a| request.format().map(|b| (a, b))) diff --git a/core/lib/src/router/mod.rs b/core/lib/src/router/mod.rs index 4818a471f5..16328ae5e9 100644 --- a/core/lib/src/router/mod.rs +++ b/core/lib/src/router/mod.rs @@ -12,7 +12,7 @@ use crate::http::Method; type Selector = Method; // A handler to use when one is needed temporarily. -crate fn dummy_handler<'r>(r: &'r Request, _: crate::Data) -> crate::handler::Outcome<'r> { +crate fn dummy_handler<'r>(r: &'r Request<'_>, _: crate::Data) -> crate::handler::Outcome<'r> { crate::Outcome::from(r, ()) } @@ -35,7 +35,7 @@ impl Router { entries.insert(i, route); } - pub fn route<'b>(&'b self, req: &Request) -> Vec<&'b Route> { + pub fn route<'b>(&'b self, req: &Request<'_>) -> Vec<&'b Route> { // Note that routes are presorted by rank on each `add`. let matches = self.routes.get(&req.method()).map_or(vec![], |routes| { routes.iter() diff --git a/core/lib/src/router/route.rs b/core/lib/src/router/route.rs index 4122066c17..115abe6c58 100644 --- a/core/lib/src/router/route.rs +++ b/core/lib/src/router/route.rs @@ -19,7 +19,7 @@ pub struct Route { /// The method this route matches against. pub method: Method, /// The function that should be called when the route matches. - pub handler: Box, + pub handler: Box, /// The base mount point of this `Route`. pub base: Origin<'static>, /// The uri (in Rocket's route format) that should be matched against. This @@ -42,11 +42,11 @@ crate struct Metadata { impl Metadata { fn from(route: &Route) -> Result { - let path_segments = >::parse(&route.uri) + let path_segments = >::parse(&route.uri) .map(|res| res.map(|s| s.into_owned())) .collect::, _>>()?; - let (query_segments, fully_dynamic_query) = match >::parse(&route.uri) { + let (query_segments, fully_dynamic_query) = match >::parse(&route.uri) { Some(results) => { let segments = results.map(|res| res.map(|s| s.into_owned())) .collect::, _>>()?; @@ -264,7 +264,7 @@ impl Route { path: Origin<'a> ) -> Result<(), RouteUriError> { base.clear_query(); - for segment in >::parse(&base) { + for segment in >::parse(&base) { if segment?.kind != Kind::Static { return Err(RouteUriError::DynamicBase); } @@ -281,7 +281,7 @@ impl Route { } impl fmt::Display for Route { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{} {}", Paint::green(&self.method), Paint::blue(&self.uri))?; if self.rank > 1 { @@ -302,7 +302,7 @@ impl fmt::Display for Route { } impl fmt::Debug for Route { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Route") .field("name", &self.name) .field("method", &self.method)