Fix clippy warnings

This commit is contained in:
sharkdp 2018-05-10 12:50:40 +02:00 committed by David Peter
parent 25cee002f9
commit e2ac6de783
3 changed files with 12 additions and 21 deletions

View File

@ -57,10 +57,7 @@ impl HighlightingAssets {
)
})?;
let mut syntax_set: SyntaxSet = from_reader(syntax_set_file).map_err(|_| {
io::Error::new(
io::ErrorKind::Other,
format!("Could not parse cached syntax set"),
)
io::Error::new(io::ErrorKind::Other, "Could not parse cached syntax set")
})?;
syntax_set.link_syntaxes();
@ -70,12 +67,8 @@ impl HighlightingAssets {
theme_set_path.to_string_lossy()
)
})?;
let theme_set: ThemeSet = from_reader(theme_set_file).map_err(|_| {
io::Error::new(
io::ErrorKind::Other,
format!("Could not parse cached theme set"),
)
})?;
let theme_set: ThemeSet = from_reader(theme_set_file)
.map_err(|_| io::Error::new(io::ErrorKind::Other, "Could not parse cached theme set"))?;
Ok(HighlightingAssets {
syntax_set,
@ -134,12 +127,10 @@ impl HighlightingAssets {
}
pub fn default_theme(&self) -> Result<&Theme> {
Ok(self.theme_set.themes.get("Default").ok_or_else(|| {
io::Error::new(
io::ErrorKind::Other,
format!("Could not find 'Default' theme"),
)
})?)
Ok(self.theme_set
.themes
.get("Default")
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Could not find 'Default' theme"))?)
}
}

View File

@ -22,7 +22,7 @@ mod diff;
mod printer;
mod terminal;
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::env;
use std::fs::{self, File};
use std::io::{self, BufRead, BufReader, Write};
@ -257,7 +257,7 @@ fn print_file(
break;
}
Ok(_) => {
if !line_buffer.ends_with("\n") {
if !line_buffer.ends_with('\n') {
line_buffer.push('\n');
}
&line_buffer
@ -459,14 +459,14 @@ fn run() -> Result<()> {
let longest = languages
.iter()
.filter(|s| !s.hidden && s.file_extensions.len() > 0)
.filter(|s| !s.hidden && !s.file_extensions.is_empty())
.map(|s| s.name.len())
.max()
.unwrap_or(32); // Fallback width if they have no language definitions.
let separator = " ";
for lang in languages {
if lang.hidden || lang.file_extensions.len() == 0 {
if lang.hidden || lang.file_extensions.is_empty() {
continue;
}
print!("{:width$}{}", lang.name, separator, width = longest);

View File

@ -92,7 +92,7 @@ impl<'a> Printer<'a> {
decorations
.into_iter()
.filter_map(|dec| if grid_requested {
Some(dec.unwrap_or(" ".to_owned()))
Some(dec.unwrap_or_else(|| " ".to_owned()))
} else {
dec
})