diff --git a/core/codegen/src/decorators/catch.rs b/core/codegen/src/decorators/catch.rs index 1872417806..9f8ce0acb1 100644 --- a/core/codegen/src/decorators/catch.rs +++ b/core/codegen/src/decorators/catch.rs @@ -8,8 +8,8 @@ use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::tokenstream::TokenTree; use syntax::parse::token; -const ERR_PARAM: &'static str = "__err"; -const REQ_PARAM: &'static str = "__req"; +const ERR_PARAM: &str = "__err"; +const REQ_PARAM: &str = "__req"; trait CatchGenerateExt { fn generate_fn_arguments(&self, &ExtCtxt, Ident, Ident) -> Vec; diff --git a/core/codegen/src/decorators/derive_form.rs b/core/codegen/src/decorators/derive_form.rs index 7f65e7de3b..c7f6c0d44b 100644 --- a/core/codegen/src/decorators/derive_form.rs +++ b/core/codegen/src/decorators/derive_form.rs @@ -217,7 +217,7 @@ fn from_form_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct let (ident, name, span) = extract_field_ident_name(cx, field); let stripped_ty = strip_ty_lifetimes(field.ty.clone()); - if let Some(sp) = names.get(&name).map(|sp| *sp) { + if let Some(sp) = names.get(&name).cloned() { cx.struct_span_err(span, "field with duplicate name") .span_note(sp, "original was declared here") .emit(); diff --git a/core/codegen/src/lib.rs b/core/codegen/src/lib.rs index 56043910e9..3f0eb47138 100644 --- a/core/codegen/src/lib.rs +++ b/core/codegen/src/lib.rs @@ -238,19 +238,19 @@ use rustc_plugin::Registry; use syntax::ext::base::SyntaxExtension; use syntax::symbol::Symbol; -const DEBUG_ENV_VAR: &'static str = "ROCKET_CODEGEN_DEBUG"; +const DEBUG_ENV_VAR: &str = "ROCKET_CODEGEN_DEBUG"; -const PARAM_PREFIX: &'static str = "rocket_param_"; -const ROUTE_STRUCT_PREFIX: &'static str = "static_rocket_route_info_for_"; -const CATCH_STRUCT_PREFIX: &'static str = "static_rocket_catch_info_for_"; -const ROUTE_FN_PREFIX: &'static str = "rocket_route_fn_"; -const CATCH_FN_PREFIX: &'static str = "rocket_catch_fn_"; -const URI_INFO_MACRO_PREFIX: &'static str = "rocket_uri_for_"; +const PARAM_PREFIX: &str = "rocket_param_"; +const ROUTE_STRUCT_PREFIX: &str = "static_rocket_route_info_for_"; +const CATCH_STRUCT_PREFIX: &str = "static_rocket_catch_info_for_"; +const ROUTE_FN_PREFIX: &str = "rocket_route_fn_"; +const CATCH_FN_PREFIX: &str = "rocket_catch_fn_"; +const URI_INFO_MACRO_PREFIX: &str = "rocket_uri_for_"; -const ROUTE_ATTR: &'static str = "rocket_route"; -const ROUTE_INFO_ATTR: &'static str = "rocket_route_info"; +const ROUTE_ATTR: &str = "rocket_route"; +const ROUTE_INFO_ATTR: &str = "rocket_route_info"; -const CATCHER_ATTR: &'static str = "rocket_catcher"; +const CATCHER_ATTR: &str = "rocket_catcher"; macro_rules! register_decorators { ($registry:expr, $($name:expr => $func:ident),+) => ( diff --git a/core/codegen/src/macros/uri.rs b/core/codegen/src/macros/uri.rs index b2217bfa33..9702bcb261 100644 --- a/core/codegen/src/macros/uri.rs +++ b/core/codegen/src/macros/uri.rs @@ -28,7 +28,7 @@ pub fn uri( // so that errors from the `internal` call show up on the user's code. let expr = parser.mk_mac_expr(sp, ast::Mac_ { - path: path, + path, delim: MacDelimiter::Parenthesis, tts: args.to_vec().into_iter().collect::().into(), }, diff --git a/core/codegen/src/parser/catch.rs b/core/codegen/src/parser/catch.rs index ad5c2470d6..fd503f6169 100644 --- a/core/codegen/src/parser/catch.rs +++ b/core/codegen/src/parser/catch.rs @@ -34,7 +34,7 @@ impl CatchParams { ecx.span_fatal(sp, "malformed attribute"); }); - if meta_items.len() < 1 { + if meta_items.is_empty() { ecx.span_fatal(sp, "attribute requires the `code` parameter"); } else if meta_items.len() > 1 { ecx.span_fatal(sp, "attribute can only have one `code` parameter"); diff --git a/core/codegen/src/parser/route.rs b/core/codegen/src/parser/route.rs index 1987e53b15..4b7d2119d8 100644 --- a/core/codegen/src/parser/route.rs +++ b/core/codegen/src/parser/route.rs @@ -52,7 +52,7 @@ impl RouteParams { ecx.span_fatal(sp, "malformed attribute"); }); - if meta_items.len() < 1 { + if meta_items.is_empty() { ecx.span_fatal(sp, "attribute requires at least 1 parameter"); } @@ -64,7 +64,7 @@ impl RouteParams { None => (parse_method(ecx, &meta_items[0]), &meta_items[1..]) }; - if attr_params.len() < 1 { + if attr_params.is_empty() { ecx.struct_span_err(sp, "attribute requires at least a path") .help(r#"example: #[get("/my/path")] or #[get(path = "/hi")]"#) .emit(); @@ -119,12 +119,9 @@ impl RouteParams { } RouteParams { - method: method, - uri: uri, + method, uri, format, rank, data_param: data, query_param: query, - format: format, - rank: rank, annotated_fn: function, } } diff --git a/core/codegen/src/parser/uri.rs b/core/codegen/src/parser/uri.rs index 1c87d18363..c3a963e20f 100644 --- a/core/codegen/src/parser/uri.rs +++ b/core/codegen/src/parser/uri.rs @@ -47,7 +47,7 @@ fn valid_segments(ecx: &ExtCtxt, uri: &Uri, sp: Span) -> bool { } // Check if this is a dynamic param. If so, check it's well-formedness. - if segment.starts_with("<") && segment.ends_with(">") { + if segment.starts_with('<') && segment.ends_with('>') { let mut param = &segment[1..(segment.len() - 1)]; if segment.ends_with("..>") { segments_span = Some(span); @@ -69,8 +69,8 @@ fn valid_segments(ecx: &ExtCtxt, uri: &Uri, sp: Span) -> bool { } validated = false; - } else if segment.starts_with("<") { - if segment[1..].contains("<") || segment.contains(">") { + } else if segment.starts_with('<') { + if segment[1..].contains('<') || segment.contains('>') { ecx.struct_span_err(span, "malformed parameter") .help("parameters must be of the form ''") .emit(); @@ -82,7 +82,7 @@ fn valid_segments(ecx: &ExtCtxt, uri: &Uri, sp: Span) -> bool { validated = false; } else if Uri::percent_encode(segment) != segment { - if segment.contains("<") || segment.contains(">") { + if segment.contains('<') || segment.contains('>') { ecx.struct_span_err(span, "malformed parameter") .help("parameters must be of the form ''") .emit(); diff --git a/core/codegen/src/parser/uri_macro.rs b/core/codegen/src/parser/uri_macro.rs index 44658fa63a..2214f1ee4b 100644 --- a/core/codegen/src/parser/uri_macro.rs +++ b/core/codegen/src/parser/uri_macro.rs @@ -146,7 +146,7 @@ impl UriParams { // Ensure that both types of arguments were not used at once. let (mut homogeneous_args, mut prev_named) = (true, None); - for arg in arguments.iter() { + for arg in &arguments { match prev_named { Some(prev_named) => homogeneous_args = prev_named == arg.is_named(), None => prev_named = Some(arg.is_named()), @@ -237,7 +237,7 @@ impl InternalUriParams { } let (mut missing, mut exprs) = (vec![], vec![]); - for (name, expr) in params.into_iter() { + for (name, expr) in params { match expr { Some(expr) => exprs.push(expr), None => missing.push(name) diff --git a/core/codegen/src/utils/mod.rs b/core/codegen/src/utils/mod.rs index 7ba632a268..f9f7172850 100644 --- a/core/codegen/src/utils/mod.rs +++ b/core/codegen/src/utils/mod.rs @@ -41,7 +41,7 @@ macro_rules! debug { } pub fn span(t: T, span: Span) -> Spanned { - Spanned { node: t, span: span } + Spanned { node: t, span } } pub fn sep_by_tok(ecx: &ExtCtxt, things: &[T], token: Token) -> Vec diff --git a/core/codegen/src/utils/span_ext.rs b/core/codegen/src/utils/span_ext.rs index aeace35e3c..0dabe44d4d 100644 --- a/core/codegen/src/utils/span_ext.rs +++ b/core/codegen/src/utils/span_ext.rs @@ -43,6 +43,6 @@ impl SpanExt for Span { } fn wrap(self, node: T) -> Spanned { - Spanned { node: node, span: self } + Spanned { node, span: self } } } diff --git a/core/codegen_next/src/parser.rs b/core/codegen_next/src/parser.rs index dd2f037205..5f6144e62a 100644 --- a/core/codegen_next/src/parser.rs +++ b/core/codegen_next/src/parser.rs @@ -10,6 +10,7 @@ pub use proc_macro2::Delimiter; pub type Result = ::std::result::Result; +#[derive(Copy, Clone)] pub enum Seperator { Comma, Pipe, @@ -23,7 +24,7 @@ pub struct Parser { impl Parser { pub fn new(tokens: TokenStream) -> Parser { - let buffer = Box::new(TokenBuffer::new(tokens.into())); + let buffer = Box::new(TokenBuffer::new(tokens)); // Our `Parser` is self-referential. We cast a pointer to the heap // allocation as `&'static` to allow the storage of the reference // along-side the allocation. This is safe as long as `buffer` is never @@ -42,7 +43,7 @@ impl Parser { pub fn current_span(&self) -> Span { self.cursor.token_tree() .map(|_| self.cursor.span().unstable()) - .unwrap_or_else(|| Span::call_site()) + .unwrap_or_else(Span::call_site) } pub fn parse(&mut self) -> Result { diff --git a/core/http/src/content_type.rs b/core/http/src/content_type.rs index bf9035f640..7d0b725dbc 100644 --- a/core/http/src/content_type.rs +++ b/core/http/src/content_type.rs @@ -332,7 +332,7 @@ impl FromStr for ContentType { /// ``` #[inline(always)] fn from_str(raw: &str) -> Result { - MediaType::from_str(raw).map(|mt| ContentType(mt)) + MediaType::from_str(raw).map(ContentType) } } diff --git a/core/http/src/cookies.rs b/core/http/src/cookies.rs index b639731fa6..db7d36a415 100644 --- a/core/http/src/cookies.rs +++ b/core/http/src/cookies.rs @@ -353,7 +353,7 @@ impl<'a> Cookies<'a> { /// } /// } /// ``` - pub fn iter<'s>(&'s self) -> impl Iterator> { + pub fn iter(&self) -> impl Iterator> { match *self { Cookies::Jarred(ref jar, _) => jar.iter(), Cookies::Empty(ref jar) => jar.iter() diff --git a/core/http/src/ext.rs b/core/http/src/ext.rs index f586db79a4..94c7dadbe4 100644 --- a/core/http/src/ext.rs +++ b/core/http/src/ext.rs @@ -28,8 +28,8 @@ impl IntoCollection for Vec { } #[inline] - fn mapped U, A: Array>(self, mut f: F) -> SmallVec { - self.into_iter().map(|item| f(item)).collect() + fn mapped U, A: Array>(self, f: F) -> SmallVec { + self.into_iter().map(f).collect() } } @@ -42,8 +42,10 @@ macro_rules! impl_for_slice { } #[inline] - fn mapped U, A: Array>(self, mut f: F) -> SmallVec { - self.iter().cloned().map(|item| f(item)).collect() + fn mapped>(self, f: F) -> SmallVec + where F: FnMut(T) -> U + { + self.iter().cloned().map(f).collect() } } ) diff --git a/core/http/src/header.rs b/core/http/src/header.rs index 489919be24..d2a5e03e1b 100644 --- a/core/http/src/header.rs +++ b/core/http/src/header.rs @@ -267,7 +267,7 @@ impl<'h> HeaderMap<'h> { pub fn get_one<'a>(&'a self, name: &str) -> Option<&'a str> { self.headers.get(UncasedStr::new(name)) .and_then(|values| { - if values.len() >= 1 { Some(values[0].borrow()) } + if !values.is_empty() { Some(values[0].borrow()) } else { None } }) } @@ -561,7 +561,7 @@ impl<'h> HeaderMap<'h> { /// } /// } /// ``` - pub fn iter<'s>(&'s 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) @@ -611,10 +611,7 @@ impl<'h> HeaderMap<'h> { pub fn into_iter(self) -> impl Iterator> { self.headers.into_iter().flat_map(|(name, value)| { value.into_iter().map(move |value| { - Header { - name: name.clone(), - value: value - } + Header { name: name.clone(), value } }) }) } diff --git a/core/http/src/method.rs b/core/http/src/method.rs index 6571788e17..96670af0de 100644 --- a/core/http/src/method.rs +++ b/core/http/src/method.rs @@ -52,8 +52,8 @@ impl Method { /// assert_eq!(Method::Post.supports_payload(), true); /// ``` #[inline] - pub fn supports_payload(&self) -> bool { - match *self { + pub fn supports_payload(self) -> bool { + match self { Put | Post | Delete | Patch => true, Get | Head | Connect | Trace | Options => false, } @@ -70,8 +70,8 @@ impl Method { /// assert_eq!(Method::Get.as_str(), "GET"); /// ``` #[inline] - pub fn as_str(&self) -> &'static str { - match *self { + pub fn as_str(self) -> &'static str { + match self { Get => "GET", Put => "PUT", Post => "POST", diff --git a/core/http/src/raw_str.rs b/core/http/src/raw_str.rs index 365841774e..ae7c8d8a07 100644 --- a/core/http/src/raw_str.rs +++ b/core/http/src/raw_str.rs @@ -63,7 +63,7 @@ impl RawStr { /// let raw_str: &RawStr = "Hello, world!".into(); /// ``` #[inline(always)] - pub fn from_str<'a>(string: &'a str) -> &'a RawStr { + pub fn from_str(string: &str) -> &RawStr { string.into() } diff --git a/core/http/src/status.rs b/core/http/src/status.rs index e1897a0819..671d50c605 100644 --- a/core/http/src/status.rs +++ b/core/http/src/status.rs @@ -156,10 +156,7 @@ impl Status { /// ``` #[inline(always)] pub const fn new(code: u16, reason: &'static str) -> Status { - Status { - code: code, - reason: reason - } + Status { code, reason } } /// Returns the class of a given status. diff --git a/core/http/src/uri/uri.rs b/core/http/src/uri/uri.rs index 826a237a85..ad4b9b0026 100644 --- a/core/http/src/uri/uri.rs +++ b/core/http/src/uri/uri.rs @@ -39,13 +39,7 @@ impl<'a> Uri<'a> { (None, None) => ((0, end), None, None), }; - Uri { - uri: uri, - path: path, - query: query, - fragment: fragment, - segment_count: AtomicIsize::new(EMPTY), - } + Uri { uri, path, query, fragment, segment_count: AtomicIsize::new(EMPTY) } } /// Returns the number of segments in the URI. Empty segments, which are diff --git a/core/lib/src/config/mod.rs b/core/lib/src/config/mod.rs index 26558bee3d..e5a91a62bc 100644 --- a/core/lib/src/config/mod.rs +++ b/core/lib/src/config/mod.rs @@ -225,10 +225,10 @@ use self::environment::CONFIG_ENV; use self::toml_ext::parse_simple_toml_value; use http::uncased::uncased_eq; -const CONFIG_FILENAME: &'static str = "Rocket.toml"; -const GLOBAL_ENV_NAME: &'static str = "global"; -const ENV_VAR_PREFIX: &'static str = "ROCKET_"; -const PREHANDLED_VARS: [&'static str; 2] = ["ROCKET_CODEGEN_DEBUG", CONFIG_ENV]; +const CONFIG_FILENAME: &str = "Rocket.toml"; +const GLOBAL_ENV_NAME: &str = "global"; +const ENV_VAR_PREFIX: &str = "ROCKET_"; +const PREHANDLED_VARS: [&str; 2] = ["ROCKET_CODEGEN_DEBUG", CONFIG_ENV]; /// Wraps `std::result` with the error type of /// [ConfigError](enum.ConfigError.html). diff --git a/core/lib/src/local/request.rs b/core/lib/src/local/request.rs index cdde310d6c..d1233116ee 100644 --- a/core/lib/src/local/request.rs +++ b/core/lib/src/local/request.rs @@ -221,7 +221,7 @@ impl<'c> LocalRequest<'c> { /// .cookie(Cookie::new("user_id", "12")); /// ``` #[inline] - pub fn cookie<'a>(self, cookie: Cookie<'a>) -> Self { + pub fn cookie(self, cookie: Cookie) -> Self { self.request.cookies().add_original(cookie.into_owned()); self } @@ -242,7 +242,7 @@ impl<'c> LocalRequest<'c> { /// let req = client.get("/").cookies(cookies); /// ``` #[inline] - pub fn cookies<'a>(self, cookies: Vec>) -> Self { + pub fn cookies(self, cookies: Vec) -> Self { for cookie in cookies { self.request.cookies().add_original(cookie.into_owned()); } @@ -336,11 +336,7 @@ impl<'c> LocalRequest<'c> { let req = self.long_lived_request(); let response = self.client.rocket().dispatch(req, Data::local(self.data)); self.client.update_cookies(&response); - - LocalResponse { - _request: self.request, - response: response - } + LocalResponse { _request: self.request, response } } /// Dispatches the request, returning the response. @@ -400,11 +396,7 @@ impl<'c> LocalRequest<'c> { let req = self.long_lived_request(); let response = self.client.rocket().dispatch(req, Data::local(data)); self.client.update_cookies(&response); - - LocalResponse { - _request: self.request.clone(), - response: response - } + LocalResponse { _request: self.request.clone(), response } } } diff --git a/core/lib/src/logger.rs b/core/lib/src/logger.rs index ef7fac9737..b297d94117 100644 --- a/core/lib/src/logger.rs +++ b/core/lib/src/logger.rs @@ -23,8 +23,8 @@ pub enum LoggingLevel { impl LoggingLevel { #[inline(always)] - fn to_level_filter(&self) -> log::LevelFilter { - match *self { + fn to_level_filter(self) -> log::LevelFilter { + match self { LoggingLevel::Critical => log::LevelFilter::Warn, LoggingLevel::Normal => log::LevelFilter::Info, LoggingLevel::Debug => log::LevelFilter::Trace, diff --git a/core/lib/src/request/param.rs b/core/lib/src/request/param.rs index 865c81a7c0..5f15cb7ff5 100644 --- a/core/lib/src/request/param.rs +++ b/core/lib/src/request/param.rs @@ -332,7 +332,7 @@ impl<'a> FromSegments<'a> for PathBuf { let mut buf = PathBuf::new(); for segment in segments { let decoded = Uri::percent_decode(segment.as_bytes()) - .map_err(|e| SegmentError::Utf8(e))?; + .map_err(SegmentError::Utf8)?; if decoded == ".." { buf.pop(); diff --git a/core/lib/src/request/request.rs b/core/lib/src/request/request.rs index fbb907e82a..d93fb044a6 100644 --- a/core/lib/src/request/request.rs +++ b/core/lib/src/request/request.rs @@ -702,7 +702,7 @@ impl<'r> Request<'r> { Err(_) => continue }; - for cookie_str in raw_str.split(";").map(|s| s.trim()) { + for cookie_str in raw_str.split(';').map(|s| s.trim()) { if let Some(cookie) = Cookies::parse_cookie(cookie_str) { cookie_jar.add_original(cookie); } diff --git a/core/lib/src/response/flash.rs b/core/lib/src/response/flash.rs index 23f8a066f7..5e342f9ac5 100644 --- a/core/lib/src/response/flash.rs +++ b/core/lib/src/response/flash.rs @@ -9,7 +9,7 @@ use http::{Status, Cookie}; use std::sync::atomic::{AtomicBool, Ordering}; // The name of the actual flash cookie. -const FLASH_COOKIE_NAME: &'static str = "_flash"; +const FLASH_COOKIE_NAME: &str = "_flash"; /// Sets a "flash" cookie that will be removed when it is accessed. The /// analogous request type is