Make clippy happy

pull/25/head
Wilfred Hughes 2021-03-06 13:46:18 +07:00
parent ca4fe593cb
commit f59e9d0f78
3 changed files with 10 additions and 15 deletions

@ -195,7 +195,7 @@ pub fn added(differences: &[Change]) -> Vec<Change> {
differences
.iter()
.filter(|c| c.kind == ChangeKind::Add)
.map(|c| *c)
.copied()
.collect()
}
@ -203,7 +203,7 @@ pub fn removed(differences: &[Change]) -> Vec<Change> {
differences
.iter()
.filter(|c| c.kind == ChangeKind::Remove)
.map(|c| *c)
.copied()
.collect()
}

@ -21,7 +21,7 @@ pub struct LineNumber {
impl LineNumber {
pub fn from(number: usize) -> LineNumber {
LineNumber { number: number }
LineNumber { number }
}
}
@ -59,9 +59,7 @@ impl NewlinePositions {
positions.push(0);
positions.extend(&newlines);
NewlinePositions {
positions: positions,
}
NewlinePositions { positions }
}
pub fn from_offset(self: &NewlinePositions, offset: usize) -> LinePosition {
@ -326,7 +324,7 @@ pub fn enforce_length(s: &str, line_length: usize) -> String {
if line.len() > line_length {
// Truncate.
result.push_str(&line[0..line_length]);
result.push_str("\n");
result.push('\n');
} else {
// Pad with spaces.
result.push_str(&format!("{:width$}\n", line, width = line_length));

@ -1,5 +1,3 @@
use term_size;
mod diffs;
mod language;
mod lines;
@ -13,14 +11,13 @@ use clap::{App, Arg};
use colored::*;
use std::collections::HashMap;
use std::fs;
use std::iter::FromIterator;
fn term_width() -> Option<usize> {
term_size::dimensions().map(|(w, _)| w)
}
fn index_map(lines: &[MatchedLine]) -> HashMap<usize, MatchedLine> {
HashMap::from_iter(lines.iter().map(|ml| (ml.line.number, *ml)))
lines.into_iter().map(|ml| (ml.line.number, *ml)).collect()
}
/// Vertically concat the desired lines of `left` and `right`, lining
@ -67,7 +64,7 @@ fn filter_concat(
result.push_str(left_str_lines[left_i]);
result.push_str(spacer);
result.push_str(right_str_lines[right_i]);
result.push_str("\n");
result.push('\n');
left_i += 1;
right_i += 1;
@ -83,7 +80,7 @@ fn filter_concat(
// There's no matching line of code on the other
// side, so just print this side.
result.push_str(left_str_lines[left_i]);
result.push_str("\n");
result.push('\n');
left_i += 1;
}
@ -98,7 +95,7 @@ fn filter_concat(
result.push_str(&" ".repeat(max_left_length));
result.push_str(spacer);
result.push_str(right_str_lines[right_i]);
result.push_str("\n");
result.push('\n');
right_i += 1;
}
@ -119,7 +116,7 @@ fn filter_concat(
fn read_or_die(path: &str) -> String {
match fs::read_to_string(path) {
Ok(src) => src.to_owned(),
Ok(src) => src,
Err(e) => {
match e.kind() {
std::io::ErrorKind::NotFound => {