diff --git a/.cargo/config.toml b/.cargo/config.toml index bb7b3a4b..35196651 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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", +] diff --git a/.vscode/settings.json b/.vscode/settings.json index 9966a630..3bf0969e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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", + ], +} \ No newline at end of file diff --git a/src/app.rs b/src/app.rs index 5bc096b2..fce0cfe5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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; } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index a2a9bd81..4dfc5af3 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -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); diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index c06784e4..95a77812 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -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); } @@ -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) } } @@ -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); } @@ -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); } @@ -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) } } diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index 3ecc0a50..2c69169b 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -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); } @@ -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) } } @@ -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); } @@ -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); } @@ -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) } } diff --git a/src/models/info_hash.rs b/src/models/info_hash.rs index 342d0fc3..1908b674 100644 --- a/src/models/info_hash.rs +++ b/src/models/info_hash.rs @@ -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()) @@ -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") } diff --git a/src/services/torrent.rs b/src/services/torrent.rs index 77e358c4..e8e6cef9 100644 --- a/src/services/torrent.rs +++ b/src/services/torrent.rs @@ -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. @@ -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); } diff --git a/src/services/user.rs b/src/services/user.rs index f8a25b93..b144241e 100644 --- a/src/services/user.rs +++ b/src/services/user.rs @@ -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() { @@ -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); } } diff --git a/src/tracker/statistics_importer.rs b/src/tracker/statistics_importer.rs index f2ae0dce..a3f1f6b8 100644 --- a/src/tracker/statistics_importer.rs +++ b/src/tracker/statistics_importer.rs @@ -69,13 +69,14 @@ impl StatisticsImporter { /// found. pub async fn import_torrent_statistics(&self, torrent_id: i64, info_hash: &str) -> Result { 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) } }