diff --git a/src/comment.rs b/src/comment.rs index eb9e96f2509f..31b6f25bf086 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -328,7 +328,7 @@ fn rewrite_comment_inner( while let Some(line) = iter.next() { result.push_str(line); result.push_str(match iter.peek() { - Some(ref next_line) if next_line.is_empty() => comment_line_separator.trim_right(), + Some(next_line) if next_line.is_empty() => comment_line_separator.trim_right(), Some(..) => &comment_line_separator, None => "", }); diff --git a/src/lib.rs b/src/lib.rs index 817188925cdb..1dd122133746 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -165,7 +165,7 @@ pub fn warning_count(&self) -> usize { self.file_error_map .iter() .map(|(_, errors)| errors.len()) - .fold(0, |acc, x| acc + x) + .sum() } pub fn has_warnings(&self) -> bool { diff --git a/src/macros.rs b/src/macros.rs index 926c76dce7f0..b0080695449c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -351,7 +351,7 @@ pub fn rewrite_macro_def( // Undo our replacement of macro variables. // FIXME: this could be *much* more efficient. - for (old, new) in substs.iter() { + for (old, new) in &substs { if old_body.find(new).is_some() { debug!( "rewrite_macro_def: bailing matching variable: `{}` in `{}`", @@ -368,7 +368,7 @@ pub fn rewrite_macro_def( ident, args_str, new_body, - indent.to_string(&context.config), + indent.to_string(context.config), ); Some(result) @@ -467,13 +467,10 @@ fn format_macro_args(toks: ThinTokenStream) -> Option { insert_space = next_space(&t); } TokenTree::Delimited(_, d) => { - let formatted = format_macro_args(d.tts)?; - match insert_space { - SpaceState::Always => { - result.push(' '); - } - _ => {} + if let SpaceState::Always = insert_space { + result.push(' '); } + let formatted = format_macro_args(d.tts)?; match d.delim { DelimToken::Paren => { result.push_str(&format!("({})", formatted)); @@ -713,7 +710,7 @@ fn parse(&mut self) -> Option { fn parse_branch(&mut self) -> Option { let (args_paren_kind, args) = match self.toks.next()? { TokenTree::Token(..) => return None, - TokenTree::Delimited(_, ref d) => (d.delim, d.tts.clone().into()), + TokenTree::Delimited(_, ref d) => (d.delim, d.tts.clone()), }; match self.toks.next()? { TokenTree::Token(_, Token::FatArrow) => {} diff --git a/tests/system.rs b/tests/system.rs index 24a6b15e421a..06bfa1418d14 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -95,7 +95,7 @@ fn verify_config_test_names() { let config_name = path.file_name().unwrap().to_str().unwrap(); // Make sure that config name is used in the files in the directory. - verify_config_used(&path, &config_name); + verify_config_used(&path, config_name); } } } @@ -105,7 +105,7 @@ fn verify_config_test_names() { // println!) that is used by `rustfmt::rustfmt_diff::print_diff`. Writing // using only one or the other will cause the output order to differ when // `print_diff` selects the approach not used. -fn write_message(msg: String) { +fn write_message(msg: &str) { let mut writer = OutputWriter::new(Color::Auto); writer.writeln(&format!("{}", msg), None); } @@ -359,8 +359,8 @@ pub enum IdempotentCheckError { } pub fn idempotent_check(filename: &PathBuf) -> Result { - let sig_comments = read_significant_comments(&filename); - let config = read_config(&filename); + let sig_comments = read_significant_comments(filename); + let config = read_config(filename); let (error_summary, file_map, format_report) = format_file(filename, &config); if error_summary.has_parsing_errors() { return Err(IdempotentCheckError::Parse); @@ -660,7 +660,7 @@ fn code_block_valid(&self) -> bool { assert!(self.code_block.is_some() && self.code_block_start.is_some()); if self.config_name.is_none() { - write_message(format!( + write_message(&format!( "No configuration name for {}:{}", CONFIGURATIONS_FILE_NAME, self.code_block_start.unwrap() @@ -668,7 +668,7 @@ fn code_block_valid(&self) -> bool { return false; } if self.config_value.is_none() { - write_message(format!( + write_message(&format!( "No configuration value for {}:{}", CONFIGURATIONS_FILE_NAME, self.code_block_start.unwrap() @@ -680,7 +680,7 @@ fn code_block_valid(&self) -> bool { fn has_parsing_errors(&self, error_summary: Summary) -> bool { if error_summary.has_parsing_errors() { - write_message(format!( + write_message(&format!( "\u{261d}\u{1f3fd} Cannot format {}:{}", CONFIGURATIONS_FILE_NAME, self.code_block_start.unwrap() @@ -703,7 +703,7 @@ fn print_diff(&self, compare: Vec) { }); } - fn formatted_has_diff(&self, file_map: FileMap) -> bool { + fn formatted_has_diff(&self, file_map: &FileMap) -> bool { let &(ref _file_name, ref text) = file_map.first().unwrap(); let compare = make_diff(self.code_block.as_ref().unwrap(), text, DIFF_CONTEXT_SIZE); if !compare.is_empty() { @@ -729,7 +729,7 @@ fn formatted_is_idempotent(&self) -> bool { let (error_summary, file_map, _report) = format_input::(input, &config, None).unwrap(); - !self.has_parsing_errors(error_summary) && !self.formatted_has_diff(file_map) + !self.has_parsing_errors(error_summary) && !self.formatted_has_diff(&file_map) } // Extract a code block from the iterator. Behavior: @@ -746,7 +746,7 @@ fn extract>( prev: Option<&ConfigCodeBlock>, ) -> Option { let mut code_block = ConfigCodeBlock::new(); - code_block.config_name = prev.map_or(None, |cb| cb.config_name.clone()); + code_block.config_name = prev.and_then(|cb| cb.config_name.clone()); loop { match ConfigurationSection::get_section(file) {