Skip to content

Commit b9c5cdc

Browse files
authored
Fix warnings (#537)
1 parent 28e621b commit b9c5cdc

File tree

11 files changed

+13
-154
lines changed

11 files changed

+13
-154
lines changed

.github/workflows/build.yaml

+4-15
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ defaults:
1414
run:
1515
shell: bash
1616

17-
env:
18-
# Cache issues can sometimes be fixed by incrementing this value.
19-
CACHE_KEY: 6
20-
2117
jobs:
2218
all:
2319
name: All
@@ -54,15 +50,6 @@ jobs:
5450
brew install gnu-tar
5551
echo /usr/local/opt/gnu-tar/libexec/gnubin > $GITHUB_PATH
5652
57-
- name: Cache
58-
uses: actions/cache@v2
59-
with:
60-
path: |
61-
~/.cargo/registry
62-
~/.cargo/git
63-
target
64-
key: cargo-${{ env.CACHE_KEY }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
65-
6653
- name: Install Rust Toolchain Components
6754
uses: actions-rs/toolchain@v1
6855
with:
@@ -71,6 +58,8 @@ jobs:
7158
target: ${{ matrix.target }}
7259
toolchain: stable
7360

61+
- uses: Swatinem/rust-cache@v2
62+
7463
- name: Info
7564
run: |
7665
rustup --version
@@ -104,9 +93,9 @@ jobs:
10493
10594
- name: Install `mdbook`
10695
if: matrix.os != 'windows-latest'
107-
uses: peaceiris/actions-mdbook@v1
96+
uses: peaceiris/actions-mdbook@v2
10897
with:
109-
mdbook-version: latest
98+
mdbook-version: 0.4.40
11099

111100
- name: Build Book
112101
if: matrix.os != 'windows-latest'

bin/gen/src/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ pub(crate) use std::{
66
fs::{self, File},
77
io,
88
ops::Deref,
9-
path::{Path, PathBuf, StripPrefixError},
9+
path::{Path, PathBuf},
1010
process::{self, Command, ExitStatus, Stdio},
1111
str,
1212
};
1313

1414
pub(crate) use ansi_term::Style;
1515
pub(crate) use askama::Template;
1616
pub(crate) use fehler::{throw, throws};
17-
pub(crate) use git2::{Oid, Repository};
17+
pub(crate) use git2::Repository;
1818
pub(crate) use libc::EXIT_FAILURE;
1919
pub(crate) use log::info;
2020
pub(crate) use regex::Regex;

bin/gen/src/error.rs

-27
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ pub(crate) enum Error {
1717
command: String,
1818
exit_status: ExitStatus,
1919
},
20-
#[snafu(display(
21-
"Failed to deserialize commit metadata: {}\n{}\n{}",
22-
source,
23-
hash,
24-
message
25-
))]
26-
CommitMetadataDeserialize {
27-
hash: Oid,
28-
message: String,
29-
source: serde_yaml::Error,
30-
},
31-
#[snafu(display("Commit missing metadata:\n{}\n{}", hash, message))]
32-
CommitMetadataMissing { hash: Oid, message: String },
33-
#[snafu(display("Commit has `{}` parents: {}", hash, parents))]
34-
CommitParents { hash: Oid, parents: usize },
35-
#[snafu(display("Commit has no summery: {}", hash))]
36-
CommitSummery { hash: Oid },
3720
#[snafu(display("Failed to deserialize config from `{}`: {}", path.display(), source))]
3821
ConfigDeserialize {
3922
path: PathBuf,
@@ -53,12 +36,6 @@ pub(crate) enum Error {
5336
#[snafu(display("I/O error at `{}`: {}", path.display(), source))]
5437
Filesystem { path: PathBuf, source: io::Error },
5538
#[snafu(display("I/O error copying `{}` to `{}`: {}", src.display(), dst.display(), source))]
56-
FilesystemCopy {
57-
src: PathBuf,
58-
dst: PathBuf,
59-
source: io::Error,
60-
},
61-
#[snafu(display("I/O error copying `{}` to `{}`: {}", src.display(), dst.display(), source))]
6239
FilesystemRecursiveCopy {
6340
src: PathBuf,
6441
dst: PathBuf,
@@ -77,10 +54,6 @@ pub(crate) enum Error {
7754
Tempdir { source: io::Error },
7855
#[snafu(display("Failed to render template: {}", source))]
7956
TemplateRender { source: askama::Error },
80-
#[snafu(display("Failed to get workdir for repo at `{}`", repo.display()))]
81-
Workdir { repo: PathBuf },
82-
#[snafu(display("Failed to strip path prefix: {}", source))]
83-
StripPrefix { source: StripPrefixError },
8457
}
8558

8659
impl From<regex::Error> for Error {

src/common.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub(crate) use std::{
1616
num::{ParseFloatError, ParseIntError, TryFromIntError},
1717
ops::{AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
1818
path::{self, Path, PathBuf},
19-
process::ExitStatus,
2019
str::{self, FromStr},
2120
string::FromUtf8Error,
2221
sync::{mpsc::channel, Once},

src/error.rs

-8
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ pub(crate) enum Error {
1414
ByteSuffix { text: String, suffix: String },
1515
#[snafu(display("{}", source))]
1616
Clap { source: clap::Error },
17-
#[snafu(display("Failed to invoke command `{}`: {}", command, source))]
18-
CommandInvoke { command: String, source: io::Error },
19-
#[snafu(display("Command `{}` returned bad exit status: {}", command, status))]
20-
CommandStatus { command: String, status: ExitStatus },
2117
#[snafu(display("Failed to get current directory: {}", source))]
2218
CurrentDirectoryGet { source: io::Error },
2319
#[snafu(display("Filename was not valid unicode: `{}`", filename.display()))]
2420
FilenameDecode { filename: PathBuf },
2521
#[snafu(display("Path had no file name: `{}`", path.display()))]
2622
FilenameExtract { path: PathBuf },
27-
#[snafu(display("Unknown file ordering: `{}`", text))]
28-
FileOrderUnknown { text: String },
2923
#[snafu(display("I/O error at `{}`: {}", path.display(), source))]
3024
Filesystem { source: io::Error, path: PathBuf },
3125
#[snafu(display("Error searching for files: {}", source))]
@@ -44,8 +38,6 @@ pub(crate) enum Error {
4438
message,
4539
))]
4640
Internal { message: String },
47-
#[snafu(display("Unknown lint: {}", text))]
48-
LintUnknown { text: String },
4941
#[snafu(display("Failed to parse magnet link `{}`: {}", text, source))]
5042
MagnetLinkParse {
5143
text: String,

src/peer/client.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ impl Client {
9191
if let State::WantInfo(_) = self.state {
9292
if handshake.metadata_size.is_none() {
9393
return Err(Error::PeerUtMetadataMetadataSizeNotKnown);
94-
} else if handshake
94+
} else if !handshake
9595
.message_ids
96-
.get(extended::UtMetadata::NAME)
97-
.is_none()
96+
.contains_key(extended::UtMetadata::NAME)
9897
{
9998
return Err(Error::PeerUtMetadataNotSupported);
10099
}

src/platform.rs

+3-58
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,10 @@ use crate::common::*;
33
pub(crate) struct Platform;
44

55
#[cfg(target_os = "windows")]
6-
impl PlatformInterface for Platform {
7-
fn hidden(path: &Path) -> Result<bool, Error> {
8-
use std::os::windows::fs::MetadataExt;
9-
10-
const HIDDEN_MASK_WIN: u32 = 0x0000_0002;
11-
12-
let metadata = path.metadata().context(error::Filesystem { path })?;
13-
Ok((metadata.file_attributes() & HIDDEN_MASK_WIN) != 0)
14-
}
15-
}
6+
impl PlatformInterface for Platform {}
167

178
#[cfg(target_os = "macos")]
18-
impl PlatformInterface for Platform {
19-
fn hidden(path: &Path) -> Result<bool, Error> {
20-
use std::os::macos::fs::MetadataExt;
21-
22-
const HIDDEN_MASK_MAC: u32 = 0x0000_8000;
23-
24-
let metadata = path.metadata().context(error::Filesystem { path })?;
25-
26-
Ok(metadata.st_flags() & HIDDEN_MASK_MAC != 0)
27-
}
28-
}
9+
impl PlatformInterface for Platform {}
2910

3011
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
31-
impl PlatformInterface for Platform {
32-
fn hidden(_path: &Path) -> Result<bool, Error> {
33-
Ok(false)
34-
}
35-
}
36-
37-
#[cfg(tests)]
38-
mod tests {
39-
use super::*;
40-
41-
#[test]
42-
fn hidden() {
43-
let tmp = tempdir().unwrap();
44-
45-
let file = tmp.path().join("file");
46-
47-
assert!(!Platform::hidden(&file));
48-
49-
if cfg!(target_os = "windows") {
50-
Command::new("attrib")
51-
.arg("+h")
52-
.arg(&file)
53-
.status()
54-
.unwrap();
55-
} else if cfg!(target_os = "macos") {
56-
Command::new("chflags")
57-
.arg("hidden")
58-
.arg(&file)
59-
.status()
60-
.unwrap();
61-
} else {
62-
return;
63-
}
64-
65-
assert!(Platform::hidden(&file));
66-
}
67-
}
12+
impl PlatformInterface for Platform {}

src/platform_interface.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ pub(crate) trait PlatformInterface {
1212
fn open_target(target: &OsStr) -> Result<(), Error> {
1313
open::that(target).context(error::OpenerInvoke)
1414
}
15-
16-
fn hidden(path: &Path) -> Result<bool, Error>;
1715
}

src/reckoner.rs

-30
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ pub(crate) trait Reckoner<K> {
44
fn increment_ref(&mut self, k: &K)
55
where
66
K: Clone;
7-
8-
fn increment(&mut self, k: K);
9-
10-
fn increment_multiple<I>(&mut self, i: I)
11-
where
12-
I: IntoIterator<Item = K>,
13-
{
14-
for k in i {
15-
self.increment(k);
16-
}
17-
}
187
}
198

209
impl<K: Ord> Reckoner<K> for BTreeMap<K, u64> {
@@ -28,10 +17,6 @@ impl<K: Ord> Reckoner<K> for BTreeMap<K, u64> {
2817
self.insert(k.clone(), 1);
2918
}
3019
}
31-
32-
fn increment(&mut self, k: K) {
33-
*self.entry(k).or_insert(0) += 1;
34-
}
3520
}
3621

3722
impl<K: Hash + Eq> Reckoner<K> for HashMap<K, u64> {
@@ -45,10 +30,6 @@ impl<K: Hash + Eq> Reckoner<K> for HashMap<K, u64> {
4530
self.insert(k.clone(), 1);
4631
}
4732
}
48-
49-
fn increment(&mut self, k: K) {
50-
*self.entry(k).or_insert(0) += 1;
51-
}
5233
}
5334

5435
impl<K: Ord> Reckoner<K> for Vec<(K, u64)> {
@@ -65,15 +46,4 @@ impl<K: Ord> Reckoner<K> for Vec<(K, u64)> {
6546
}
6647
}
6748
}
68-
69-
fn increment(&mut self, k: K) {
70-
match self.binary_search_by_key(&&k, |(key, _count)| key) {
71-
Ok(i) => {
72-
self[i].1 *= 1;
73-
}
74-
Err(i) => {
75-
self.insert(i, (k, 1));
76-
}
77-
}
78-
}
7949
}

src/subcommand/torrent/verify.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ impl Verify {
7878

7979
let content = self
8080
.content
81-
.as_ref()
82-
.cloned()
81+
.clone()
8382
.or_else(|| {
8483
self
8584
.base_directory

src/torrent_summary.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,7 @@ impl TorrentSummary {
209209
content_size: self.metainfo.content_size().count(),
210210
private: self.metainfo.info.private.unwrap_or_default(),
211211
tracker: self.metainfo.announce.clone(),
212-
announce_list: self
213-
.metainfo
214-
.announce_list
215-
.as_ref()
216-
.map(Clone::clone)
217-
.unwrap_or_default(),
212+
announce_list: self.metainfo.announce_list.clone().unwrap_or_default(),
218213
update_url: self
219214
.metainfo
220215
.info

0 commit comments

Comments
 (0)