Cargo clippy

This commit is contained in:
Seiichi Uchida 2018-01-26 14:53:28 +09:00
parent f925c581fe
commit dfc67a5df7
4 changed files with 18 additions and 21 deletions

View File

@ -328,7 +328,7 @@ fn rewrite_comment_inner(
while let Some(line) = iter.next() { while let Some(line) = iter.next() {
result.push_str(line); result.push_str(line);
result.push_str(match iter.peek() { 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, Some(..) => &comment_line_separator,
None => "", None => "",
}); });

View File

@ -165,7 +165,7 @@ impl FormatReport {
self.file_error_map self.file_error_map
.iter() .iter()
.map(|(_, errors)| errors.len()) .map(|(_, errors)| errors.len())
.fold(0, |acc, x| acc + x) .sum()
} }
pub fn has_warnings(&self) -> bool { pub fn has_warnings(&self) -> bool {

View File

@ -351,7 +351,7 @@ pub fn rewrite_macro_def(
// Undo our replacement of macro variables. // Undo our replacement of macro variables.
// FIXME: this could be *much* more efficient. // 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() { if old_body.find(new).is_some() {
debug!( debug!(
"rewrite_macro_def: bailing matching variable: `{}` in `{}`", "rewrite_macro_def: bailing matching variable: `{}` in `{}`",
@ -368,7 +368,7 @@ pub fn rewrite_macro_def(
ident, ident,
args_str, args_str,
new_body, new_body,
indent.to_string(&context.config), indent.to_string(context.config),
); );
Some(result) Some(result)
@ -467,13 +467,10 @@ fn format_macro_args(toks: ThinTokenStream) -> Option<String> {
insert_space = next_space(&t); insert_space = next_space(&t);
} }
TokenTree::Delimited(_, d) => { TokenTree::Delimited(_, d) => {
let formatted = format_macro_args(d.tts)?; if let SpaceState::Always = insert_space {
match insert_space { result.push(' ');
SpaceState::Always => {
result.push(' ');
}
_ => {}
} }
let formatted = format_macro_args(d.tts)?;
match d.delim { match d.delim {
DelimToken::Paren => { DelimToken::Paren => {
result.push_str(&format!("({})", formatted)); result.push_str(&format!("({})", formatted));
@ -713,7 +710,7 @@ impl MacroParser {
fn parse_branch(&mut self) -> Option<MacroBranch> { fn parse_branch(&mut self) -> Option<MacroBranch> {
let (args_paren_kind, args) = match self.toks.next()? { let (args_paren_kind, args) = match self.toks.next()? {
TokenTree::Token(..) => return None, 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()? { match self.toks.next()? {
TokenTree::Token(_, Token::FatArrow) => {} TokenTree::Token(_, Token::FatArrow) => {}

View File

@ -95,7 +95,7 @@ fn verify_config_test_names() {
let config_name = path.file_name().unwrap().to_str().unwrap(); let config_name = path.file_name().unwrap().to_str().unwrap();
// Make sure that config name is used in the files in the directory. // 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 // 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 // using only one or the other will cause the output order to differ when
// `print_diff` selects the approach not used. // `print_diff` selects the approach not used.
fn write_message(msg: String) { fn write_message(msg: &str) {
let mut writer = OutputWriter::new(Color::Auto); let mut writer = OutputWriter::new(Color::Auto);
writer.writeln(&format!("{}", msg), None); writer.writeln(&format!("{}", msg), None);
} }
@ -359,8 +359,8 @@ pub enum IdempotentCheckError {
} }
pub fn idempotent_check(filename: &PathBuf) -> Result<FormatReport, IdempotentCheckError> { pub fn idempotent_check(filename: &PathBuf) -> Result<FormatReport, IdempotentCheckError> {
let sig_comments = read_significant_comments(&filename); let sig_comments = read_significant_comments(filename);
let config = read_config(&filename); let config = read_config(filename);
let (error_summary, file_map, format_report) = format_file(filename, &config); let (error_summary, file_map, format_report) = format_file(filename, &config);
if error_summary.has_parsing_errors() { if error_summary.has_parsing_errors() {
return Err(IdempotentCheckError::Parse); return Err(IdempotentCheckError::Parse);
@ -660,7 +660,7 @@ impl ConfigCodeBlock {
assert!(self.code_block.is_some() && self.code_block_start.is_some()); assert!(self.code_block.is_some() && self.code_block_start.is_some());
if self.config_name.is_none() { if self.config_name.is_none() {
write_message(format!( write_message(&format!(
"No configuration name for {}:{}", "No configuration name for {}:{}",
CONFIGURATIONS_FILE_NAME, CONFIGURATIONS_FILE_NAME,
self.code_block_start.unwrap() self.code_block_start.unwrap()
@ -668,7 +668,7 @@ impl ConfigCodeBlock {
return false; return false;
} }
if self.config_value.is_none() { if self.config_value.is_none() {
write_message(format!( write_message(&format!(
"No configuration value for {}:{}", "No configuration value for {}:{}",
CONFIGURATIONS_FILE_NAME, CONFIGURATIONS_FILE_NAME,
self.code_block_start.unwrap() self.code_block_start.unwrap()
@ -680,7 +680,7 @@ impl ConfigCodeBlock {
fn has_parsing_errors(&self, error_summary: Summary) -> bool { fn has_parsing_errors(&self, error_summary: Summary) -> bool {
if error_summary.has_parsing_errors() { if error_summary.has_parsing_errors() {
write_message(format!( write_message(&format!(
"\u{261d}\u{1f3fd} Cannot format {}:{}", "\u{261d}\u{1f3fd} Cannot format {}:{}",
CONFIGURATIONS_FILE_NAME, CONFIGURATIONS_FILE_NAME,
self.code_block_start.unwrap() self.code_block_start.unwrap()
@ -703,7 +703,7 @@ impl ConfigCodeBlock {
}); });
} }
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 &(ref _file_name, ref text) = file_map.first().unwrap();
let compare = make_diff(self.code_block.as_ref().unwrap(), text, DIFF_CONTEXT_SIZE); let compare = make_diff(self.code_block.as_ref().unwrap(), text, DIFF_CONTEXT_SIZE);
if !compare.is_empty() { if !compare.is_empty() {
@ -729,7 +729,7 @@ impl ConfigCodeBlock {
let (error_summary, file_map, _report) = let (error_summary, file_map, _report) =
format_input::<io::Stdout>(input, &config, None).unwrap(); format_input::<io::Stdout>(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: // Extract a code block from the iterator. Behavior:
@ -746,7 +746,7 @@ impl ConfigCodeBlock {
prev: Option<&ConfigCodeBlock>, prev: Option<&ConfigCodeBlock>,
) -> Option<ConfigCodeBlock> { ) -> Option<ConfigCodeBlock> {
let mut code_block = ConfigCodeBlock::new(); 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 { loop {
match ConfigurationSection::get_section(file) { match ConfigurationSection::get_section(file) {