Skip to content

Commit

Permalink
Fix various clippy warnings in core and codegen.
Browse files Browse the repository at this point in the history
  • Loading branch information
sstangl authored and SergioBenitez committed Jul 25, 2018
1 parent 1d1d525 commit a7cc554
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 80 deletions.
4 changes: 2 additions & 2 deletions core/codegen/src/decorators/catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenTree>;
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/decorators/derive_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions core/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),+) => (
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/macros/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TokenStream>().into(),
},
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/parser/catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 3 additions & 6 deletions core/codegen/src/parser/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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();
Expand Down Expand Up @@ -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,
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/codegen/src/parser/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 '<param>'")
.emit();
Expand All @@ -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 '<param>'")
.emit();
Expand Down
4 changes: 2 additions & 2 deletions core/codegen/src/parser/uri_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ macro_rules! debug {
}

pub fn span<T>(t: T, span: Span) -> Spanned<T> {
Spanned { node: t, span: span }
Spanned { node: t, span }
}

pub fn sep_by_tok<T>(ecx: &ExtCtxt, things: &[T], token: Token) -> Vec<TokenTree>
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/utils/span_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ impl SpanExt for Span {
}

fn wrap<T>(self, node: T) -> Spanned<T> {
Spanned { node: node, span: self }
Spanned { node, span: self }
}
}
5 changes: 3 additions & 2 deletions core/codegen_next/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use proc_macro2::Delimiter;

pub type Result<T> = ::std::result::Result<T, Diagnostic>;

#[derive(Copy, Clone)]
pub enum Seperator {
Comma,
Pipe,
Expand All @@ -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
Expand All @@ -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<T: Synom>(&mut self) -> Result<T> {
Expand Down
2 changes: 1 addition & 1 deletion core/http/src/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl FromStr for ContentType {
/// ```
#[inline(always)]
fn from_str(raw: &str) -> Result<ContentType, String> {
MediaType::from_str(raw).map(|mt| ContentType(mt))
MediaType::from_str(raw).map(ContentType)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/http/src/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl<'a> Cookies<'a> {
/// }
/// }
/// ```
pub fn iter<'s>(&'s self) -> impl Iterator<Item=&'s Cookie<'static>> {
pub fn iter(&self) -> impl Iterator<Item=&Cookie<'static>> {
match *self {
Cookies::Jarred(ref jar, _) => jar.iter(),
Cookies::Empty(ref jar) => jar.iter()
Expand Down
10 changes: 6 additions & 4 deletions core/http/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl<T> IntoCollection<T> for Vec<T> {
}

#[inline]
fn mapped<U, F: FnMut(T) -> U, A: Array<Item=U>>(self, mut f: F) -> SmallVec<A> {
self.into_iter().map(|item| f(item)).collect()
fn mapped<U, F: FnMut(T) -> U, A: Array<Item=U>>(self, f: F) -> SmallVec<A> {
self.into_iter().map(f).collect()
}
}

Expand All @@ -42,8 +42,10 @@ macro_rules! impl_for_slice {
}

#[inline]
fn mapped<U, F: FnMut(T) -> U, A: Array<Item=U>>(self, mut f: F) -> SmallVec<A> {
self.iter().cloned().map(|item| f(item)).collect()
fn mapped<U, F, A: Array<Item=U>>(self, f: F) -> SmallVec<A>
where F: FnMut(T) -> U
{
self.iter().cloned().map(f).collect()
}
}
)
Expand Down
9 changes: 3 additions & 6 deletions core/http/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})
}
Expand Down Expand Up @@ -561,7 +561,7 @@ impl<'h> HeaderMap<'h> {
/// }
/// }
/// ```
pub fn iter<'s>(&'s self) -> impl Iterator<Item=Header<'s>> {
pub fn iter(&self) -> impl Iterator<Item=Header> {
self.headers.iter().flat_map(|(key, values)| {
values.iter().map(move |val| {
Header::new(key.as_str(), &**val)
Expand Down Expand Up @@ -611,10 +611,7 @@ impl<'h> HeaderMap<'h> {
pub fn into_iter(self) -> impl Iterator<Item=Header<'h>> {
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 }
})
})
}
Expand Down
8 changes: 4 additions & 4 deletions core/http/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion core/http/src/raw_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
5 changes: 1 addition & 4 deletions core/http/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions core/http/src/uri/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions core/lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
16 changes: 4 additions & 12 deletions core/lib/src/local/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -242,7 +242,7 @@ impl<'c> LocalRequest<'c> {
/// let req = client.get("/").cookies(cookies);
/// ```
#[inline]
pub fn cookies<'a>(self, cookies: Vec<Cookie<'a>>) -> Self {
pub fn cookies(self, cookies: Vec<Cookie>) -> Self {
for cookie in cookies {
self.request.cookies().add_original(cookie.into_owned());
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/lib/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/request/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit a7cc554

Please sign in to comment.