about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNick Cameron <nrc@ncameron.org>2018-09-03 13:25:35 +1200
committerGitHub <noreply@github.com>2018-09-03 13:25:35 +1200
commit2291be7fa1ef8b38483ea1c76e465931d9d6647b (patch)
treef833877ef356e81ee9d5f6f2d765eee16fec3a60 /src
parenta67208f212657f94833792148e3e3e09fe0785ba (diff)
parent968affc3e0bd713d2e4c46f273eca8b988c469ae (diff)
Merge pull request #2992 from max-sixty/clippy2
Clippy 2/2
Diffstat (limited to 'src')
-rw-r--r--src/attr.rs2
-rw-r--r--src/bin/main.rs14
-rw-r--r--src/comment.rs6
-rw-r--r--src/config/options.rs4
-rw-r--r--src/expr.rs14
-rw-r--r--src/format-diff/main.rs2
-rw-r--r--src/formatting.rs10
-rw-r--r--src/imports.rs4
-rw-r--r--src/lists.rs2
-rw-r--r--src/macros.rs18
-rw-r--r--src/missed_spans.rs2
-rw-r--r--src/overflow.rs2
-rw-r--r--src/reorder.rs12
-rw-r--r--src/shape.rs2
-rw-r--r--src/test/mod.rs4
-rw-r--r--src/vertical.rs2
-rw-r--r--src/visitor.rs4
17 files changed, 52 insertions, 52 deletions
diff --git a/src/attr.rs b/src/attr.rs
index f4b84e51a30..fc29c69b498 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -48,7 +48,7 @@ fn is_derive(attr: &ast::Attribute) -> bool {
 }
 
 /// Returns the arguments of `#[derive(...)]`.
-fn get_derive_spans<'a>(attr: &ast::Attribute) -> Option<Vec<Span>> {
+fn get_derive_spans(attr: &ast::Attribute) -> Option<Vec<Span>> {
     attr.meta_item_list().map(|meta_item_list| {
         meta_item_list
             .iter()
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 760333955a0..a3d2819e1db 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -172,19 +172,19 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
     match determine_operation(&matches)? {
         Operation::Help(HelpOp::None) => {
             print_usage_to_stdout(opts, "");
-            return Ok(0);
+            Ok(0)
         }
         Operation::Help(HelpOp::Config) => {
             Config::print_docs(&mut stdout(), options.unstable_features);
-            return Ok(0);
+            Ok(0)
         }
         Operation::Help(HelpOp::FileLines) => {
             print_help_file_lines();
-            return Ok(0);
+            Ok(0)
         }
         Operation::Version => {
             print_version();
-            return Ok(0);
+            Ok(0)
         }
         Operation::ConfigOutputDefault { path } => {
             let toml = Config::default().all_options().to_toml().map_err(err_msg)?;
@@ -194,13 +194,13 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
             } else {
                 io::stdout().write_all(toml.as_bytes())?;
             }
-            return Ok(0);
+            Ok(0)
         }
         Operation::Stdin { input } => format_string(input, options),
         Operation::Format {
             files,
             minimal_config_path,
-        } => format(files, minimal_config_path, options),
+        } => format(files, minimal_config_path, &options),
     }
 }
 
@@ -236,7 +236,7 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32, failure:
 fn format(
     files: Vec<PathBuf>,
     minimal_config_path: Option<String>,
-    options: GetOptsOptions,
+    options: &GetOptsOptions,
 ) -> Result<i32, failure::Error> {
     options.verify_file_lines(&files);
     let (config, config_path) = load_config(None, Some(options.clone()))?;
diff --git a/src/comment.rs b/src/comment.rs
index e3c6201d3c4..de0fca11f71 100644
--- a/src/comment.rs
+++ b/src/comment.rs
@@ -47,7 +47,7 @@ fn custom_opener(s: &str) -> &str {
     s.lines().next().map_or("", |first_line| {
         first_line
             .find(' ')
-            .map_or(first_line, |space_index| &first_line[0..space_index + 1])
+            .map_or(first_line, |space_index| &first_line[0..=space_index])
     })
 }
 
@@ -1151,7 +1151,7 @@ pub fn recover_comment_removed(
             context.report.append(
                 context.source_map.span_to_filename(span).into(),
                 vec![FormattingError::from_span(
-                    &span,
+                    span,
                     &context.source_map,
                     ErrorKind::LostComment,
                 )],
@@ -1428,7 +1428,7 @@ mod test {
 
     #[test]
     fn test_remove_trailing_white_spaces() {
-        let s = format!("    r#\"\n        test\n    \"#");
+        let s = "    r#\"\n        test\n    \"#";
         assert_eq!(remove_trailing_white_spaces(&s), s);
     }
 
diff --git a/src/config/options.rs b/src/config/options.rs
index ac80116e0d0..e1aec1ddea9 100644
--- a/src/config/options.rs
+++ b/src/config/options.rs
@@ -279,7 +279,7 @@ configuration_option_enum! { Color:
 
 impl Color {
     /// Whether we should use a coloured terminal.
-    pub fn use_colored_tty(&self) -> bool {
+    pub fn use_colored_tty(self) -> bool {
         match self {
             Color::Always => true,
             Color::Never => false,
@@ -432,7 +432,7 @@ configuration_option_enum!{ Edition:
 }
 
 impl Edition {
-    pub(crate) fn to_libsyntax_pos_edition(&self) -> syntax_pos::edition::Edition {
+    pub(crate) fn to_libsyntax_pos_edition(self) -> syntax_pos::edition::Edition {
         match self {
             Edition::Edition2015 => syntax_pos::edition::Edition::Edition2015,
             Edition::Edition2018 => syntax_pos::edition::Edition::Edition2018,
diff --git a/src/expr.rs b/src/expr.rs
index 11d53eb7074..329081f5d70 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -100,7 +100,7 @@ pub fn format_expr(
                 )
             })
         }
-        ast::ExprKind::Unary(ref op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
+        ast::ExprKind::Unary(op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
         ast::ExprKind::Struct(ref path, ref fields, ref base) => rewrite_struct_lit(
             context,
             path,
@@ -1519,7 +1519,7 @@ fn rewrite_index(
     }
 }
 
-fn struct_lit_can_be_aligned(fields: &[ast::Field], base: &Option<&ast::Expr>) -> bool {
+fn struct_lit_can_be_aligned(fields: &[ast::Field], base: Option<&ast::Expr>) -> bool {
     if base.is_some() {
         return false;
     }
@@ -1555,7 +1555,7 @@ fn rewrite_struct_lit<'a>(
 
     let one_line_width = h_shape.map_or(0, |shape| shape.width);
     let body_lo = context.snippet_provider.span_after(span, "{");
-    let fields_str = if struct_lit_can_be_aligned(fields, &base)
+    let fields_str = if struct_lit_can_be_aligned(fields, base)
         && context.config.struct_field_align_threshold() > 0
     {
         rewrite_with_alignment(
@@ -1676,7 +1676,7 @@ pub fn rewrite_field(
     };
     let name = context.snippet(field.ident.span);
     if field.is_shorthand {
-        Some(attrs_str + &name)
+        Some(attrs_str + name)
     } else {
         let mut separator = String::from(struct_lit_field_separator(context.config));
         for _ in 0..prefix_max_width.saturating_sub(name.len()) {
@@ -1688,7 +1688,7 @@ pub fn rewrite_field(
 
         match expr {
             Some(ref e) if e.as_str() == name && context.config.use_field_init_shorthand() => {
-                Some(attrs_str + &name)
+                Some(attrs_str + name)
             }
             Some(e) => Some(format!("{}{}{}{}", attrs_str, name, separator, e)),
             None => {
@@ -1827,12 +1827,12 @@ pub fn rewrite_unary_suffix<R: Rewrite>(
 
 fn rewrite_unary_op(
     context: &RewriteContext,
-    op: &ast::UnOp,
+    op: ast::UnOp,
     expr: &ast::Expr,
     shape: Shape,
 ) -> Option<String> {
     // For some reason, an UnOp is not spanned like BinOp!
-    let operator_str = match *op {
+    let operator_str = match op {
         ast::UnOp::Deref => "*",
         ast::UnOp::Not => "!",
         ast::UnOp::Neg => "-",
diff --git a/src/format-diff/main.rs b/src/format-diff/main.rs
index 37ad4f35a1d..d509a4429b4 100644
--- a/src/format-diff/main.rs
+++ b/src/format-diff/main.rs
@@ -214,7 +214,7 @@ where
 
 #[test]
 fn scan_simple_git_diff() {
-    const DIFF: &'static str = include_str!("test/bindgen.diff");
+    const DIFF: &str = include_str!("test/bindgen.diff");
     let (files, ranges) = scan_diff(DIFF.as_bytes(), 1, r".*\.rs").expect("scan_diff failed?");
 
     assert!(
diff --git a/src/formatting.rs b/src/formatting.rs
index 3012837ba64..9386302c479 100644
--- a/src/formatting.rs
+++ b/src/formatting.rs
@@ -194,11 +194,11 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> {
     fn handle_formatted_file(
         &mut self,
         path: FileName,
-        mut result: String,
+        result: String,
         report: &mut FormatReport,
     ) -> Result<(), ErrorKind> {
         if let Some(ref mut out) = self.out {
-            match source_file::write_file(&mut result, &path, out, &self.config) {
+            match source_file::write_file(&result, &path, out, &self.config) {
                 Ok(b) if b => report.add_diff(),
                 Err(e) => {
                     // Create a new error with path_str to help users see which files failed
@@ -224,7 +224,7 @@ pub(crate) struct FormattingError {
 
 impl FormattingError {
     pub(crate) fn from_span(
-        span: &Span,
+        span: Span,
         source_map: &SourceMap,
         kind: ErrorKind,
     ) -> FormattingError {
@@ -234,13 +234,13 @@ impl FormattingError {
             kind,
             is_string: false,
             line_buffer: source_map
-                .span_to_lines(*span)
+                .span_to_lines(span)
                 .ok()
                 .and_then(|fl| {
                     fl.file
                         .get_line(fl.lines[0].line_index)
                         .map(|l| l.into_owned())
-                }).unwrap_or_else(|| String::new()),
+                }).unwrap_or_else(String::new),
         }
     }
 
diff --git a/src/imports.rs b/src/imports.rs
index db00c45b9d9..3ca063a58e7 100644
--- a/src/imports.rs
+++ b/src/imports.rs
@@ -179,7 +179,7 @@ pub fn merge_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
 fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
     for tree in trees.iter_mut() {
         if tree.share_prefix(&use_tree) {
-            tree.merge(use_tree);
+            tree.merge(&use_tree);
             return;
         }
     }
@@ -536,7 +536,7 @@ impl UseTree {
         }
     }
 
-    fn merge(&mut self, other: UseTree) {
+    fn merge(&mut self, other: &UseTree) {
         let mut new_path = vec![];
         for (a, b) in self
             .path
diff --git a/src/lists.rs b/src/lists.rs
index 8867c6f2283..f1b01ea8055 100644
--- a/src/lists.rs
+++ b/src/lists.rs
@@ -475,7 +475,7 @@ where
                     formatted_comment = rewrite_post_comment(&mut item_max_width)?;
                     comment_alignment = post_comment_alignment(item_max_width, inner_item.len());
                 }
-                for _ in 0..(comment_alignment + 1) {
+                for _ in 0..=comment_alignment {
                     result.push(' ');
                 }
                 // An additional space for the missing trailing separator.
diff --git a/src/macros.rs b/src/macros.rs
index e8e0f1b572e..6aae1b23f0c 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -524,12 +524,12 @@ enum MacroArgKind {
 
 fn delim_token_to_str(
     context: &RewriteContext,
-    delim_token: &DelimToken,
+    delim_token: DelimToken,
     shape: Shape,
     use_multiple_lines: bool,
     inner_is_empty: bool,
 ) -> (String, String) {
-    let (lhs, rhs) = match *delim_token {
+    let (lhs, rhs) = match delim_token {
         DelimToken::Paren => ("(", ")"),
         DelimToken::Bracket => ("[", "]"),
         DelimToken::Brace => {
@@ -612,7 +612,7 @@ impl MacroArgKind {
             MacroArgKind::MetaVariable(ty, ref name) => {
                 Some(format!("${}:{}", name, ty.name.as_str()))
             }
-            MacroArgKind::Repeat(ref delim_tok, ref args, ref another, ref tok) => {
+            MacroArgKind::Repeat(delim_tok, ref args, ref another, ref tok) => {
                 let (lhs, inner, rhs) = rewrite_delimited_inner(delim_tok, args)?;
                 let another = another
                     .as_ref()
@@ -622,7 +622,7 @@ impl MacroArgKind {
 
                 Some(format!("${}{}{}{}{}", lhs, inner, rhs, another, repeat_tok))
             }
-            MacroArgKind::Delimited(ref delim_tok, ref args) => {
+            MacroArgKind::Delimited(delim_tok, ref args) => {
                 rewrite_delimited_inner(delim_tok, args)
                     .map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs))
             }
@@ -755,8 +755,8 @@ impl MacroArgParser {
         let mut hi = span.hi();
 
         // Parse '*', '+' or '?.
-        for ref tok in iter {
-            self.set_last_tok(tok);
+        for tok in iter {
+            self.set_last_tok(&tok);
             if first {
                 first = false;
                 lo = tok.span().lo();
@@ -977,7 +977,7 @@ enum SpaceState {
 fn force_space_before(tok: &Token) -> bool {
     debug!("tok: force_space_before {:?}", tok);
 
-    match *tok {
+    match tok {
         Token::Eq
         | Token::Lt
         | Token::Le
@@ -1002,7 +1002,7 @@ fn force_space_before(tok: &Token) -> bool {
 }
 
 fn ident_like(tok: &Token) -> bool {
-    match *tok {
+    match tok {
         Token::Ident(..) | Token::Literal(..) | Token::Lifetime(_) => true,
         _ => false,
     }
@@ -1011,7 +1011,7 @@ fn ident_like(tok: &Token) -> bool {
 fn next_space(tok: &Token) -> SpaceState {
     debug!("next_space: {:?}", tok);
 
-    match *tok {
+    match tok {
         Token::Not
         | Token::BinOp(BinOpToken::And)
         | Token::Tilde
diff --git a/src/missed_spans.rs b/src/missed_spans.rs
index ef047b3144c..f2f2295a872 100644
--- a/src/missed_spans.rs
+++ b/src/missed_spans.rs
@@ -315,7 +315,7 @@ impl<'a> FmtVisitor<'a> {
                     self.push_str("\n");
                     status.last_wspace = None;
                 } else {
-                    self.push_str(&snippet[status.line_start..i + 1]);
+                    self.push_str(&snippet[status.line_start..=i]);
                 }
 
                 status.cur_line += 1;
diff --git a/src/overflow.rs b/src/overflow.rs
index 9a9c9831f40..674eb14b677 100644
--- a/src/overflow.rs
+++ b/src/overflow.rs
@@ -291,7 +291,7 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
             (true, DefinitiveListTactic::Horizontal, placeholder @ Some(..)) => {
                 list_items[self.items.len() - 1].item = placeholder;
             }
-            _ if self.items.len() >= 1 => {
+            _ if !self.items.is_empty() => {
                 list_items[self.items.len() - 1].item = self
                     .items
                     .last()
diff --git a/src/reorder.rs b/src/reorder.rs
index b6876738cfd..47aae3bfc2a 100644
--- a/src/reorder.rs
+++ b/src/reorder.rs
@@ -193,12 +193,12 @@ impl ReorderableItemKind {
         }
     }
 
-    fn is_same_item_kind(&self, item: &ast::Item) -> bool {
-        ReorderableItemKind::from(item) == *self
+    fn is_same_item_kind(self, item: &ast::Item) -> bool {
+        ReorderableItemKind::from(item) == self
     }
 
-    fn is_reorderable(&self, config: &Config) -> bool {
-        match *self {
+    fn is_reorderable(self, config: &Config) -> bool {
+        match self {
             ReorderableItemKind::ExternCrate => config.reorder_imports(),
             ReorderableItemKind::Mod => config.reorder_modules(),
             ReorderableItemKind::Use => config.reorder_imports(),
@@ -206,8 +206,8 @@ impl ReorderableItemKind {
         }
     }
 
-    fn in_group(&self) -> bool {
-        match *self {
+    fn in_group(self) -> bool {
+        match self {
             ReorderableItemKind::ExternCrate
             | ReorderableItemKind::Mod
             | ReorderableItemKind::Use => true,
diff --git a/src/shape.rs b/src/shape.rs
index 12a911a1931..5868f0b85fd 100644
--- a/src/shape.rs
+++ b/src/shape.rs
@@ -91,7 +91,7 @@ impl Indent {
         };
         let num_chars = num_tabs + num_spaces;
         if num_tabs == 0 && num_chars + offset <= INDENT_BUFFER_LEN {
-            Cow::from(&INDENT_BUFFER[offset..num_chars + 1])
+            Cow::from(&INDENT_BUFFER[offset..=num_chars])
         } else {
             let mut indent = String::with_capacity(num_chars + if offset == 0 { 1 } else { 0 });
             if offset == 0 {
diff --git a/src/test/mod.rs b/src/test/mod.rs
index 8b2358f1ada..17f8ffec9a1 100644
--- a/src/test/mod.rs
+++ b/src/test/mod.rs
@@ -102,7 +102,7 @@ fn verify_config_test_names() {
 // `print_diff` selects the approach not used.
 fn write_message(msg: &str) {
     let mut writer = OutputWriter::new(Color::Auto);
-    writer.writeln(&format!("{}", msg), None);
+    writer.writeln(msg, None);
 }
 
 // Integration tests. The files in the tests/source are formatted and compared
@@ -949,7 +949,7 @@ fn rustfmt() -> PathBuf {
         me.is_file() || me.with_extension("exe").is_file(),
         "no rustfmt bin, try running `cargo build` before testing"
     );
-    return me;
+    me
 }
 
 #[test]
diff --git a/src/vertical.rs b/src/vertical.rs
index e76f44ca39b..3f533920106 100644
--- a/src/vertical.rs
+++ b/src/vertical.rs
@@ -126,7 +126,7 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
     } else {
         ("", fields.len() - 1)
     };
-    let init = &fields[0..group_index + 1];
+    let init = &fields[0..=group_index];
     let rest = &fields[group_index + 1..];
     let init_last_pos = if rest.is_empty() {
         span.hi()
diff --git a/src/visitor.rs b/src/visitor.rs
index 7f557747778..e6ef7f23da0 100644
--- a/src/visitor.rs
+++ b/src/visitor.rs
@@ -621,7 +621,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
                 self.report.append(
                     file_name,
                     vec![FormattingError::from_span(
-                        &attr.span,
+                        attr.span,
                         &self.source_map,
                         ErrorKind::DeprecatedAttr,
                     )],
@@ -634,7 +634,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
                     self.report.append(
                         file_name,
                         vec![FormattingError::from_span(
-                            &attr.span,
+                            attr.span,
                             &self.source_map,
                             ErrorKind::BadAttr,
                         )],