Skip to content

Commit dfc67a5

Browse files
committed
Cargo clippy
1 parent f925c58 commit dfc67a5

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

src/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ fn rewrite_comment_inner(
328328
while let Some(line) = iter.next() {
329329
result.push_str(line);
330330
result.push_str(match iter.peek() {
331-
Some(ref next_line) if next_line.is_empty() => comment_line_separator.trim_right(),
331+
Some(next_line) if next_line.is_empty() => comment_line_separator.trim_right(),
332332
Some(..) => &comment_line_separator,
333333
None => "",
334334
});

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl FormatReport {
165165
self.file_error_map
166166
.iter()
167167
.map(|(_, errors)| errors.len())
168-
.fold(0, |acc, x| acc + x)
168+
.sum()
169169
}
170170

171171
pub fn has_warnings(&self) -> bool {

src/macros.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub fn rewrite_macro_def(
351351

352352
// Undo our replacement of macro variables.
353353
// FIXME: this could be *much* more efficient.
354-
for (old, new) in substs.iter() {
354+
for (old, new) in &substs {
355355
if old_body.find(new).is_some() {
356356
debug!(
357357
"rewrite_macro_def: bailing matching variable: `{}` in `{}`",
@@ -368,7 +368,7 @@ pub fn rewrite_macro_def(
368368
ident,
369369
args_str,
370370
new_body,
371-
indent.to_string(&context.config),
371+
indent.to_string(context.config),
372372
);
373373

374374
Some(result)
@@ -467,13 +467,10 @@ fn format_macro_args(toks: ThinTokenStream) -> Option<String> {
467467
insert_space = next_space(&t);
468468
}
469469
TokenTree::Delimited(_, d) => {
470-
let formatted = format_macro_args(d.tts)?;
471-
match insert_space {
472-
SpaceState::Always => {
473-
result.push(' ');
474-
}
475-
_ => {}
470+
if let SpaceState::Always = insert_space {
471+
result.push(' ');
476472
}
473+
let formatted = format_macro_args(d.tts)?;
477474
match d.delim {
478475
DelimToken::Paren => {
479476
result.push_str(&format!("({})", formatted));
@@ -713,7 +710,7 @@ impl MacroParser {
713710
fn parse_branch(&mut self) -> Option<MacroBranch> {
714711
let (args_paren_kind, args) = match self.toks.next()? {
715712
TokenTree::Token(..) => return None,
716-
TokenTree::Delimited(_, ref d) => (d.delim, d.tts.clone().into()),
713+
TokenTree::Delimited(_, ref d) => (d.delim, d.tts.clone()),
717714
};
718715
match self.toks.next()? {
719716
TokenTree::Token(_, Token::FatArrow) => {}

tests/system.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn verify_config_test_names() {
9595
let config_name = path.file_name().unwrap().to_str().unwrap();
9696

9797
// Make sure that config name is used in the files in the directory.
98-
verify_config_used(&path, &config_name);
98+
verify_config_used(&path, config_name);
9999
}
100100
}
101101
}
@@ -105,7 +105,7 @@ fn verify_config_test_names() {
105105
// println!) that is used by `rustfmt::rustfmt_diff::print_diff`. Writing
106106
// using only one or the other will cause the output order to differ when
107107
// `print_diff` selects the approach not used.
108-
fn write_message(msg: String) {
108+
fn write_message(msg: &str) {
109109
let mut writer = OutputWriter::new(Color::Auto);
110110
writer.writeln(&format!("{}", msg), None);
111111
}
@@ -359,8 +359,8 @@ pub enum IdempotentCheckError {
359359
}
360360

361361
pub fn idempotent_check(filename: &PathBuf) -> Result<FormatReport, IdempotentCheckError> {
362-
let sig_comments = read_significant_comments(&filename);
363-
let config = read_config(&filename);
362+
let sig_comments = read_significant_comments(filename);
363+
let config = read_config(filename);
364364
let (error_summary, file_map, format_report) = format_file(filename, &config);
365365
if error_summary.has_parsing_errors() {
366366
return Err(IdempotentCheckError::Parse);
@@ -660,15 +660,15 @@ impl ConfigCodeBlock {
660660
assert!(self.code_block.is_some() && self.code_block_start.is_some());
661661

662662
if self.config_name.is_none() {
663-
write_message(format!(
663+
write_message(&format!(
664664
"No configuration name for {}:{}",
665665
CONFIGURATIONS_FILE_NAME,
666666
self.code_block_start.unwrap()
667667
));
668668
return false;
669669
}
670670
if self.config_value.is_none() {
671-
write_message(format!(
671+
write_message(&format!(
672672
"No configuration value for {}:{}",
673673
CONFIGURATIONS_FILE_NAME,
674674
self.code_block_start.unwrap()
@@ -680,7 +680,7 @@ impl ConfigCodeBlock {
680680

681681
fn has_parsing_errors(&self, error_summary: Summary) -> bool {
682682
if error_summary.has_parsing_errors() {
683-
write_message(format!(
683+
write_message(&format!(
684684
"\u{261d}\u{1f3fd} Cannot format {}:{}",
685685
CONFIGURATIONS_FILE_NAME,
686686
self.code_block_start.unwrap()
@@ -703,7 +703,7 @@ impl ConfigCodeBlock {
703703
});
704704
}
705705

706-
fn formatted_has_diff(&self, file_map: FileMap) -> bool {
706+
fn formatted_has_diff(&self, file_map: &FileMap) -> bool {
707707
let &(ref _file_name, ref text) = file_map.first().unwrap();
708708
let compare = make_diff(self.code_block.as_ref().unwrap(), text, DIFF_CONTEXT_SIZE);
709709
if !compare.is_empty() {
@@ -729,7 +729,7 @@ impl ConfigCodeBlock {
729729
let (error_summary, file_map, _report) =
730730
format_input::<io::Stdout>(input, &config, None).unwrap();
731731

732-
!self.has_parsing_errors(error_summary) && !self.formatted_has_diff(file_map)
732+
!self.has_parsing_errors(error_summary) && !self.formatted_has_diff(&file_map)
733733
}
734734

735735
// Extract a code block from the iterator. Behavior:
@@ -746,7 +746,7 @@ impl ConfigCodeBlock {
746746
prev: Option<&ConfigCodeBlock>,
747747
) -> Option<ConfigCodeBlock> {
748748
let mut code_block = ConfigCodeBlock::new();
749-
code_block.config_name = prev.map_or(None, |cb| cb.config_name.clone());
749+
code_block.config_name = prev.and_then(|cb| cb.config_name.clone());
750750

751751
loop {
752752
match ConfigurationSection::get_section(file) {

0 commit comments

Comments
 (0)