Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten Linter (Check and Clippy) #353

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ cov = "llvm-cov"
cov-lcov = "llvm-cov --lcov --output-path=./.coverage/lcov.info"
cov-html = "llvm-cov --html"
time = "build --timings --all-targets"

[build]
rustflags = [
"-D",
"warnings",
"-D",
"future-incompatible",
"-D",
"let-underscore",
"-D",
"nonstandard-style",
"-D",
"rust-2018-compatibility",
"-D",
"rust-2018-idioms",
"-D",
"rust-2021-compatibility",
"-D",
"unused",
]
21 changes: 18 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
"[rust]": {
"editor.formatOnSave": true
},
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.checkOnSave.allTargets": true,
"rust-analyzer.checkOnSave.extraArgs": ["--","-W","clippy::pedantic"],
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.allTargets": true,
"rust-analyzer.check.extraArgs": [
"--",
"-D",
"clippy::correctness",
"-D",
"clippy::suspicious",
"-W",
"clippy::complexity",
"-W",
"clippy::perf",
"-W",
"clippy::style",
"-W",
"clippy::pedantic",
],
}
2 changes: 1 addition & 1 deletion packages/located-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod tests {
fn error_should_include_location() {
let e = TestError::Test;

let b: LocatedError<TestError> = Located(e).into();
let b: LocatedError<'_, TestError> = Located(e).into();
let l = get_caller_location();

assert_eq!(b.location.file(), l.file());
Expand Down
2 changes: 1 addition & 1 deletion src/servers/apis/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ApiServer<Running> {
.send(0)
.map_err(|_| Error::Error("Task killer channel was closed.".to_string()))?;

let _: Result<(), tokio::task::JoinError> = self.state.task.await;
drop(self.state.task.await);

Ok(ApiServer {
cfg: self.cfg,
Expand Down
4 changes: 4 additions & 0 deletions src/servers/apis/v1/context/auth_key/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl From<AuthKey> for auth::ExpiringKey {
}
}

#[allow(deprecated)]
impl From<auth::ExpiringKey> for AuthKey {
fn from(auth_key: auth::ExpiringKey) -> Self {
AuthKey {
Expand Down Expand Up @@ -63,6 +64,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn it_should_be_convertible_into_an_auth_key() {
let auth_key_resource = AuthKey {
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
Expand All @@ -80,6 +82,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn it_should_be_convertible_from_an_auth_key() {
let auth_key = auth::ExpiringKey {
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".parse::<Key>().unwrap(), // cspell:disable-line
Expand All @@ -97,6 +100,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn it_should_be_convertible_into_json() {
assert_eq!(
serde_json::to_string(&AuthKey {
Expand Down
6 changes: 3 additions & 3 deletions src/servers/http/v1/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl From<Vec<(&str, &str)>> for Query {
}

impl std::fmt::Display for Query {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let query = self
.params
.iter_all()
Expand Down Expand Up @@ -185,7 +185,7 @@ impl FromStr for NameValuePair {
}

impl std::fmt::Display for NameValuePair {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}={}", self.name, self.value)
}
}
Expand All @@ -208,7 +208,7 @@ impl FieldValuePairSet {
}

impl std::fmt::Display for FieldValuePairSet {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let query = self
.pairs
.iter()
Expand Down
34 changes: 14 additions & 20 deletions src/servers/http/v1/requests/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl FromStr for Event {
}

impl fmt::Display for Event {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Event::Started => write!(f, "started"),
Event::Stopped => write!(f, "stopped"),
Expand Down Expand Up @@ -194,7 +194,7 @@ pub enum Compact {
}

impl fmt::Display for Compact {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Compact::Accepted => write!(f, "1"),
Compact::NotAccepted => write!(f, "0"),
Expand Down Expand Up @@ -264,12 +264,10 @@ fn extract_info_hash(query: &Query) -> Result<InfoHash, ParseAnnounceQueryError>
})?,
)
}
None => {
return Err(ParseAnnounceQueryError::MissingParam {
location: Location::caller(),
param_name: INFO_HASH.to_owned(),
})
}
None => Err(ParseAnnounceQueryError::MissingParam {
location: Location::caller(),
param_name: INFO_HASH.to_owned(),
}),
}
}

Expand All @@ -282,12 +280,10 @@ fn extract_peer_id(query: &Query) -> Result<peer::Id, ParseAnnounceQueryError> {
source: Located(err).into(),
})?,
),
None => {
return Err(ParseAnnounceQueryError::MissingParam {
location: Location::caller(),
param_name: PEER_ID.to_owned(),
})
}
None => Err(ParseAnnounceQueryError::MissingParam {
location: Location::caller(),
param_name: PEER_ID.to_owned(),
}),
}
}

Expand All @@ -298,12 +294,10 @@ fn extract_port(query: &Query) -> Result<u16, ParseAnnounceQueryError> {
param_value: raw_param.clone(),
location: Location::caller(),
})?),
None => {
return Err(ParseAnnounceQueryError::MissingParam {
location: Location::caller(),
param_name: PORT.to_owned(),
})
}
None => Err(ParseAnnounceQueryError::MissingParam {
location: Location::caller(),
param_name: PORT.to_owned(),
}),
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/servers/http/v1/requests/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ fn extract_info_hashes(query: &Query) -> Result<Vec<InfoHash>, ParseScrapeQueryE

Ok(info_hashes)
}
None => {
return Err(ParseScrapeQueryError::MissingParam {
location: Location::caller(),
param_name: INFO_HASH.to_owned(),
})
}
None => Err(ParseScrapeQueryError::MissingParam {
location: Location::caller(),
param_name: INFO_HASH.to_owned(),
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/servers/http/v1/responses/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub struct Peer {

impl Peer {
#[must_use]
pub fn ben_map(&self) -> BencodeMut {
pub fn ben_map(&self) -> BencodeMut<'_> {
ben_map! {
"peer id" => ben_bytes!(self.peer_id.clone().to_vec()),
"ip" => ben_bytes!(self.ip.to_string()),
Expand Down
2 changes: 2 additions & 0 deletions src/servers/udp/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub async fn handle_connect(remote_addr: SocketAddr, request: &ConnectRequest, t
/// # Errors
///
/// Will return `Error` if unable to `authenticate_request`.
#[allow(deprecated)]
pub async fn authenticate(info_hash: &InfoHash, tracker: &Tracker) -> Result<(), Error> {
tracker
.authenticate_request(info_hash, &None)
Expand Down Expand Up @@ -225,6 +226,7 @@ pub async fn handle_scrape(remote_addr: SocketAddr, request: &ScrapeRequest, tra
let info_hash = file.0;
let swarm_metadata = file.1;

#[allow(deprecated)]
let scrape_entry = if tracker.authenticate_request(info_hash, &None).await.is_ok() {
#[allow(clippy::cast_possible_truncation)]
TorrentScrapeStatistics {
Expand Down
2 changes: 1 addition & 1 deletion src/servers/udp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl UdpServer<Running> {
pub async fn stop(self) -> Result<UdpServer<Stopped>, Error> {
self.state.stop_job_sender.send(1).map_err(|e| Error::Error(e.to_string()))?;

let _: Result<(), tokio::task::JoinError> = self.state.job.await;
drop(self.state.job.await);

let stopped_api_server: UdpServer<Stopped> = UdpServer {
cfg: self.cfg,
Expand Down
6 changes: 3 additions & 3 deletions src/shared/bit_torrent/info_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl InfoHash {
}

impl std::fmt::Display for InfoHash {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut chars = [0u8; 40];
binascii::bin2hex(&self.0, &mut chars).expect("failed to hexlify");
write!(f, "{}", std::str::from_utf8(&chars).unwrap())
Expand Down Expand Up @@ -195,7 +195,7 @@ impl Ord for InfoHash {

impl std::cmp::PartialOrd<InfoHash> for InfoHash {
fn partial_cmp(&self, other: &InfoHash) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -271,7 +271,7 @@ struct InfoHashVisitor;
impl<'v> serde::de::Visitor<'v> for InfoHashVisitor {
type Value = InfoHash;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "a 40 character long hash")
}

Expand Down
5 changes: 1 addition & 4 deletions src/shared/clock/time_extent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ pub type DefaultTimeExtentMaker = StoppedTimeExtentMaker;

#[cfg(test)]
mod test {
use crate::shared::clock::time_extent::{
checked_duration_from_nanos, Base, DefaultTimeExtentMaker, Extent, Make, Multiplier, Product, TimeExtent, MAX, ZERO,
};
use crate::shared::clock::{Current, DurationSinceUnixEpoch, StoppedTime};
use crate::shared::clock::time_extent::TimeExtent;

const TIME_EXTENT_VAL: TimeExtent = TimeExtent::from_sec(2, &239_812_388_723);

Expand Down
13 changes: 7 additions & 6 deletions src/tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,11 @@ impl Tracker {

// todo: move this action to a separate worker
if self.config.persistent_torrent_completed_stat && stats_updated {
let _: Result<(), databases::error::Error> = self
.database
.save_persistent_torrent(info_hash, torrent_entry.completed)
.await;
drop(
self.database
.save_persistent_torrent(info_hash, torrent_entry.completed)
.await,
);
}

let (seeders, completed, leechers) = torrent_entry.get_stats();
Expand Down Expand Up @@ -966,10 +967,10 @@ impl Tracker {
return Ok(());
}

return Err(Error::TorrentNotWhitelisted {
Err(Error::TorrentNotWhitelisted {
info_hash: *info_hash,
location: Location::caller(),
});
})
}

/// It adds a torrent to the whitelist.
Expand Down
8 changes: 4 additions & 4 deletions tests/servers/http/requests/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Query {
}

impl fmt::Display for Query {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.build())
}
}
Expand Down Expand Up @@ -57,7 +57,7 @@ pub enum Event {
}

impl fmt::Display for Event {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
//Event::Started => write!(f, "started"),
//Event::Stopped => write!(f, "stopped"),
Expand All @@ -74,7 +74,7 @@ pub enum Compact {
}

impl fmt::Display for Compact {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Compact::Accepted => write!(f, "1"),
Compact::NotAccepted => write!(f, "0"),
Expand Down Expand Up @@ -163,7 +163,7 @@ pub struct QueryParams {
}

impl std::fmt::Display for QueryParams {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut params = vec![];

if let Some(info_hash) = &self.info_hash {
Expand Down
4 changes: 2 additions & 2 deletions tests/servers/http/requests/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Query {
}

impl fmt::Display for Query {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.build())
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ impl QueryParams {
}

impl std::fmt::Display for QueryParams {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let query = self
.info_hash
.iter()
Expand Down
2 changes: 0 additions & 2 deletions tests/servers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate rand;

mod api;
mod http;
mod udp;