Skip to content

Commit

Permalink
Placate clippy
Browse files Browse the repository at this point in the history
type: reform
  • Loading branch information
casey committed May 3, 2021
1 parent 61bbd3b commit 89c7300
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 121 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ jobs:
cargo clippy --version
- name: Build
run: cargo build --all --verbose
run: cargo build --all

- name: Test
run: cargo test --all --verbose
run: cargo test --all

- name: Clippy
run: cargo clippy --all
run: cargo clippy --all-targets --all-features

- name: Lint
if: matrix.os == 'macos-latest'
Expand All @@ -112,13 +112,11 @@ jobs:
git diff --no-ext-diff --exit-code
- name: Install `mdbook`
if: matrix.os != 'windows-latest'
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: latest

- name: Build Book
if: matrix.os != 'windows-latest'
run: |
cargo run --package gen -- --bin target/debug/imdl book --no-changelog
mdbook build book --dest-dir ../www/book
Expand Down
5 changes: 1 addition & 4 deletions bin/gen/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ impl Changelog {

#[throws]
pub(crate) fn render(&self, book: bool) -> String {
let mut lines: Vec<String> = Vec::new();

lines.push("Changelog".into());
lines.push("=========".into());
let mut lines: Vec<String> = vec!["Changelog".into(), "=========".into()];

for release in &self.releases {
lines.push("".into());
Expand Down
3 changes: 1 addition & 2 deletions bin/gen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ impl<R: Row> Table<R> {

impl<R: Row> Display for Table<R> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let mut rows = Vec::new();
rows.push(R::header().to_vec());
let mut rows = vec![R::header().to_vec()];

for row in &self.rows {
rows.push(row.entries());
Expand Down
1 change: 0 additions & 1 deletion book/src/changelog.md

This file was deleted.

2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test:
cargo test --all

clippy:
cargo clippy --all
cargo clippy --all-targets --all-features

fmt:
cargo +nightly fmt --all
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ error_on_unformatted = true
format_code_in_doc_comments = true
format_macro_bodies = true
format_strings = true
imports_granularity = "Crate"
max_width = 100
merge_imports = true
newline_style = "Unix"
normalize_comments = true
reorder_impl_items = true
Expand Down
4 changes: 3 additions & 1 deletion src/bench.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::unwrap_used)]

use crate::common::*;

use std::io::BufWriter;
Expand Down Expand Up @@ -39,7 +41,7 @@ impl Bench for HasherBench {

while written < TEMPFILE_BYTES {
rand::thread_rng().fill_bytes(&mut bytes);
writer.write(&bytes).unwrap();
writer.write_all(&bytes).unwrap();
written += bytes.len().into_u64();
}

Expand Down
2 changes: 1 addition & 1 deletion src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mod tests {
("1kib", KI),
("1KiB", KI),
("12kib", 12 * KI),
("1.5mib", 1 * MI + 512 * KI),
("1.5mib", MI + 512 * KI),
];

for (text, value) in CASES {
Expand Down
8 changes: 4 additions & 4 deletions src/file_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl FileError {
let metadata = match path.metadata() {
Ok(metadata) => metadata,
Err(error) => {
if error.kind() == io::ErrorKind::NotFound {
return Err(FileError::Missing);
return Err(if error.kind() == io::ErrorKind::NotFound {
FileError::Missing
} else {
return Err(FileError::Io(error));
}
FileError::Io(error)
})
}
};

Expand Down
6 changes: 1 addition & 5 deletions src/file_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ impl FilePath {

#[cfg(test)]
pub(crate) fn from_components(components: &[&str]) -> FilePath {
let components: Vec<String> = components
.iter()
.cloned()
.map(|component| component.to_owned())
.collect();
let components: Vec<String> = components.iter().cloned().map(ToOwned::to_owned).collect();
assert!(!components.is_empty());
FilePath { components }
}
Expand Down
6 changes: 3 additions & 3 deletions src/infohash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ impl From<Sha1Digest> for Infohash {
}
}

impl Into<Sha1Digest> for Infohash {
fn into(self) -> Sha1Digest {
self.inner
impl From<Infohash> for Sha1Digest {
fn from(infohash: Infohash) -> Sha1Digest {
infohash.inner
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::all, clippy::pedantic, clippy::restriction)]
#![allow(
clippy::blanket_clippy_restriction_lints,
clippy::create_dir,
clippy::else_if_without_else,
clippy::enum_glob_use,
clippy::float_arithmetic,
Expand All @@ -13,6 +14,7 @@
clippy::map_unwrap_or,
clippy::missing_docs_in_private_items,
clippy::missing_inline_in_public_items,
clippy::module_name_repetitions,
clippy::needless_lifetimes,
clippy::needless_pass_by_value,
clippy::non_ascii_literal,
Expand All @@ -24,6 +26,18 @@
clippy::wildcard_enum_match_arm,
clippy::wildcard_imports
)]
#![cfg_attr(
any(test),
allow(
clippy::blacklisted_name,
clippy::expect_fun_call,
clippy::expect_used,
clippy::panic,
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used
)
)]

#[cfg(test)]
#[macro_use]
Expand Down
12 changes: 6 additions & 6 deletions src/magnet_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl MagnetLink {
}

fn parse(text: &str) -> Result<Self, MagnetLinkParseError> {
let url = Url::parse(&text).context(magnet_link_parse_error::URL)?;
let url = Url::parse(&text).context(magnet_link_parse_error::Url)?;

if url.scheme() != "magnet" {
return Err(MagnetLinkParseError::Scheme {
Expand All @@ -105,7 +105,7 @@ impl MagnetLink {
}

let buf = hex::decode(infohash).context(magnet_link_parse_error::HexParse {
text: infohash.to_string(),
text: infohash.to_owned(),
})?;

link = Some(MagnetLink::with_infohash(
Expand Down Expand Up @@ -270,7 +270,7 @@ mod tests {

assert_matches!(e, Error::MagnetLinkParse {
text,
source: MagnetLinkParseError::URL { .. },
source: MagnetLinkParseError::Url { .. },
} if text == link);
}

Expand Down Expand Up @@ -307,7 +307,7 @@ mod tests {
text,
source: MagnetLinkParseError::HexParse {
text: ih,
source: _,
..
}} if text == link && infohash == ih);
}

Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
text,
source: MagnetLinkParseError::TrackerAddress {
text: addr,
source: _,
..
},
} if text == link && addr == bad_addr);
}
Expand All @@ -352,7 +352,7 @@ mod tests {
text,
source: MagnetLinkParseError::PeerAddress {
text: addr,
source: _,
..
}
} if text == link && addr == bad_addr
);
Expand Down
2 changes: 1 addition & 1 deletion src/magnet_link_parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ pub(crate) enum MagnetLinkParseError {
source: url::ParseError,
},
#[snafu(display("Failed to parse URL: {}", source))]
URL { source: url::ParseError },
Url { source: url::ParseError },
}
4 changes: 2 additions & 2 deletions src/md5_digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ impl Md5Digest {

let mut bytes: [u8; 16] = [0; 16];

for n in 0..16 {
for (n, byte) in bytes.iter_mut().enumerate() {
let i = n * 2;
bytes[n] = u8::from_str_radix(&hex[i..i + 2], 16).unwrap();
*byte = u8::from_str_radix(&hex[i..i + 2], 16).unwrap();
}

Self { bytes }
Expand Down
16 changes: 8 additions & 8 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ impl Shell {
}
}

impl Into<clap::Shell> for Shell {
fn into(self) -> clap::Shell {
match self {
Self::Bash => clap::Shell::Bash,
Self::Fish => clap::Shell::Fish,
Self::Zsh => clap::Shell::Zsh,
Self::Powershell => clap::Shell::PowerShell,
Self::Elvish => clap::Shell::Elvish,
impl From<Shell> for clap::Shell {
fn from(shell: Shell) -> Self {
match shell {
Shell::Bash => clap::Shell::Bash,
Shell::Fish => clap::Shell::Fish,
Shell::Zsh => clap::Shell::Zsh,
Shell::Powershell => clap::Shell::PowerShell,
Shell::Elvish => clap::Shell::Elvish,
}
}
}
Expand Down
Loading

0 comments on commit 89c7300

Please sign in to comment.