From d6c652e33c37cfc996bfd1442960edf1df3a0a9d Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Fri, 4 Sep 2015 23:39:33 +0200 Subject: [PATCH] code improvements suggested by clippy --- src/comment.rs | 4 ++-- src/lib.rs | 4 ++-- src/lists.rs | 6 +++--- src/modules.rs | 2 +- src/types.rs | 8 ++++---- src/visitor.rs | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index e6e083d84bc..0db2aefe013 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -81,7 +81,7 @@ pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usiz s } -fn left_trim_comment_line<'a>(line: &'a str) -> &'a str { +fn left_trim_comment_line(line: &str) -> &str { if line.starts_with("/* ") || line.starts_with("// ") { &line[3..] } else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") { @@ -289,7 +289,7 @@ impl Iterator for CharClasses where T: Iterator, T::Item: RichChar { return Some((CodeCharKind::Comment, item)); } }; - return Some((CodeCharKind::Normal, item)); + Some((CodeCharKind::Normal, item)) } } diff --git a/src/lib.rs b/src/lib.rs index 83c0c5ae1b7..8214012a908 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,7 +198,7 @@ struct FormatReport { impl fmt::Display for FormatReport { // Prints all the formatting errors. fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - for (file, errors) in self.file_error_map.iter() { + for (file, errors) in &self.file_error_map { for error in errors { try!(write!(fmt, "{} {}:{}: {} {}\n", @@ -292,7 +292,7 @@ fn fmt_lines(file_map: &mut FileMap, config: &Config) -> FormatReport { truncate_todo.push((f.to_owned(), text.len - newline_count + 1)) } - for &(l, _, _) in trims.iter() { + for &(l, _, _) in &trims { errors.push(FormattingError { line: l, kind: ErrorKind::TrailingWhitespace diff --git a/src/lists.rs b/src/lists.rs index 6938e4eb4d4..cc51e1286b9 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -414,8 +414,8 @@ fn total_item_width(item: &ListItem) -> usize { } fn comment_len(comment: &Option) -> usize { - match comment { - &Some(ref s) => { + match *comment { + Some(ref s) => { let text_len = s.trim().len(); if text_len > 0 { // We'll put " /*" before and " */" after inline comments. @@ -424,6 +424,6 @@ fn comment_len(comment: &Option) -> usize { text_len } } - &None => 0, + None => 0, } } diff --git a/src/modules.rs b/src/modules.rs index 681bb1c8ade..b50c9e26895 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -36,7 +36,7 @@ fn list_submodules<'a>(module: &'a ast::Mod, codemap: &codemap::CodeMap, result: &mut HashMap) { debug!("list_submodules: search_dir: {:?}", search_dir); - for item in module.items.iter() { + for item in &module.items { if let ast::ItemMod(ref sub_mod) = item.node { if !utils::contains_skip(&item.attrs) { let is_internal = codemap.span_to_filename(item.span) == diff --git a/src/types.rs b/src/types.rs index c04d694a68e..0c0d9e54424 100644 --- a/src/types.rs +++ b/src/types.rs @@ -265,8 +265,8 @@ impl Rewrite for ast::WherePredicate { fn rewrite(&self, context: &RewriteContext, width: usize, offset: usize) -> Option { // TODO dead spans? // TODO assumes we'll always fit on one line... - Some(match self { - &ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bound_lifetimes, + Some(match *self { + ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bound_lifetimes, ref bounded_ty, ref bounds, ..}) => { @@ -299,7 +299,7 @@ impl Rewrite for ast::WherePredicate { format!("{}: {}", type_str, bounds_str) } } - &ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, + ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, ref bounds, ..}) => { format!("{}: {}", @@ -307,7 +307,7 @@ impl Rewrite for ast::WherePredicate { bounds.iter().map(pprust::lifetime_to_string) .collect::>().join(" + ")) } - &ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { + ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { let ty_str = pprust::ty_to_string(ty); // 3 = " = ".len() let used_width = 3 + ty_str.len(); diff --git a/src/visitor.rs b/src/visitor.rs index 0b29086daf6..c2e4013e182 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -49,10 +49,10 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> { fn visit_stmt(&mut self, stmt: &'v ast::Stmt) { match stmt.node { ast::Stmt_::StmtDecl(ref decl, _) => { - return match decl.node { + match decl.node { ast::Decl_::DeclLocal(ref local) => self.visit_let(local, stmt.span), ast::Decl_::DeclItem(..) => visit::walk_stmt(self, stmt), - }; + } } ast::Stmt_::StmtExpr(ref ex, _) | ast::Stmt_::StmtSemi(ref ex, _) => { self.format_missing_with_indent(stmt.span.lo);