Skip to content

Commit

Permalink
dev: tighten lint for build and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Aug 2, 2023
1 parent cf4fb22 commit 9de7aa7
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 34 deletions.
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-html = "llvm-cov --html"
cov-lcov = "llvm-cov --lcov --output-path=./.coverage/lcov.info"
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",
]
23 changes: 19 additions & 4 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 src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running
loop {
interval.tick().await;
if let Some(tracker) = weak_tracker_statistics_importer.upgrade() {
let _ = tracker.import_all_torrents_statistics().await;
drop(tracker.import_all_torrents_statistics().await);
} else {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl BytesCache {
}

// Remove the old entry so that a new entry will be added as last in the queue.
let _ = self.bytes_table.shift_remove(&key);
drop(self.bytes_table.shift_remove(&key));

let bytes_cache_entry = BytesCacheEntry::new(bytes);

Expand Down
14 changes: 7 additions & 7 deletions src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Database for Mysql {

// rollback transaction on error
if let Err(e) = insert_user_auth_result {
let _ = tx.rollback().await;
drop(tx.rollback().await);
return Err(e);
}

Expand All @@ -100,11 +100,11 @@ impl Database for Mysql {
// commit or rollback transaction and return user_id on success
match insert_user_profile_result {
Ok(_) => {
let _ = tx.commit().await;
drop(tx.commit().await);
Ok(i64::overflowing_add_unsigned(0, user_id).0)
}
Err(e) => {
let _ = tx.rollback().await;
drop(tx.rollback().await);
Err(e)
}
}
Expand Down Expand Up @@ -497,7 +497,7 @@ impl Database for Mysql {

// rollback transaction on error
if let Err(e) = insert_torrent_files_result {
let _ = tx.rollback().await;
drop(tx.rollback().await);
return Err(e);
}

Expand Down Expand Up @@ -531,7 +531,7 @@ impl Database for Mysql {

// rollback transaction on error
if let Err(e) = insert_torrent_announce_urls_result {
let _ = tx.rollback().await;
drop(tx.rollback().await);
return Err(e);
}

Expand All @@ -558,11 +558,11 @@ impl Database for Mysql {
// commit or rollback transaction and return user_id on success
match insert_torrent_info_result {
Ok(_) => {
let _ = tx.commit().await;
drop(tx.commit().await);
Ok(torrent_id)
}
Err(e) => {
let _ = tx.rollback().await;
drop(tx.rollback().await);
Err(e)
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Database for Sqlite {

// rollback transaction on error
if let Err(e) = insert_user_auth_result {
let _ = tx.rollback().await;
drop(tx.rollback().await);
return Err(e);
}

Expand All @@ -101,11 +101,11 @@ impl Database for Sqlite {
// commit or rollback transaction and return user_id on success
match insert_user_profile_result {
Ok(_) => {
let _ = tx.commit().await;
drop(tx.commit().await);
Ok(user_id)
}
Err(e) => {
let _ = tx.rollback().await;
drop(tx.rollback().await);
Err(e)
}
}
Expand Down Expand Up @@ -487,7 +487,7 @@ impl Database for Sqlite {

// rollback transaction on error
if let Err(e) = insert_torrent_files_result {
let _ = tx.rollback().await;
drop(tx.rollback().await);
return Err(e);
}

Expand Down Expand Up @@ -521,7 +521,7 @@ impl Database for Sqlite {

// rollback transaction on error
if let Err(e) = insert_torrent_announce_urls_result {
let _ = tx.rollback().await;
drop(tx.rollback().await);
return Err(e);
}

Expand All @@ -548,11 +548,11 @@ impl Database for Sqlite {
// commit or rollback transaction and return user_id on success
match insert_torrent_info_result {
Ok(_) => {
let _ = tx.commit().await;
drop(tx.commit().await);
Ok(torrent_id)
}
Err(e) => {
let _ = tx.rollback().await;
drop(tx.rollback().await);
Err(e)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/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 @@ -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
11 changes: 6 additions & 5 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ impl Index {

let torrent_id = self.torrent_repository.add(&torrent_request, user_id, category).await?;

let _ = self
.tracker_statistics_importer
.import_torrent_statistics(torrent_id, &torrent_request.torrent.info_hash())
.await;
drop(
self.tracker_statistics_importer
.import_torrent_statistics(torrent_id, &torrent_request.torrent.info_hash())
.await,
);

// We always whitelist the torrent on the tracker because even if the tracker mode is `public`
// it could be changed to `private` later on.
Expand All @@ -131,7 +132,7 @@ impl Index {
.await
{
// If the torrent can't be whitelisted somehow, remove the torrent from database
let _ = self.torrent_repository.delete(&torrent_id).await;
drop(self.torrent_repository.delete(&torrent_id).await);
return Err(e);
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl RegistrationService {

// If this is the first created account, give administrator rights
if user_id == 1 {
let _ = self.user_repository.grant_admin_role(&user_id).await;
drop(self.user_repository.grant_admin_role(&user_id).await);
}

if settings.mail.email_verification_enabled && opt_email.is_some() {
Expand All @@ -141,7 +141,7 @@ impl RegistrationService {
.await;

if mail_res.is_err() {
let _ = self.user_repository.delete(&user_id).await;
drop(self.user_repository.delete(&user_id).await);
return Err(ServiceError::FailedToSendVerificationEmail);
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/tracker/statistics_importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ impl StatisticsImporter {
/// found.
pub async fn import_torrent_statistics(&self, torrent_id: i64, info_hash: &str) -> Result<TorrentInfo, ServiceError> {
if let Ok(torrent_info) = self.tracker_service.get_torrent_info(info_hash).await {
let _ = self
.database
.update_tracker_info(torrent_id, &self.tracker_url, torrent_info.seeders, torrent_info.leechers)
.await;
drop(
self.database
.update_tracker_info(torrent_id, &self.tracker_url, torrent_info.seeders, torrent_info.leechers)
.await,
);
Ok(torrent_info)
} else {
let _ = self.database.update_tracker_info(torrent_id, &self.tracker_url, 0, 0).await;
drop(self.database.update_tracker_info(torrent_id, &self.tracker_url, 0, 0).await);
Err(ServiceError::TorrentNotFound)
}
}
Expand Down

0 comments on commit 9de7aa7

Please sign in to comment.