Skip to content

Commit 9de7aa7

Browse files
committed
dev: tighten lint for build and clippy
1 parent cf4fb22 commit 9de7aa7

File tree

10 files changed

+71
-34
lines changed

10 files changed

+71
-34
lines changed

.cargo/config.toml

+20
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@ cov = "llvm-cov"
33
cov-html = "llvm-cov --html"
44
cov-lcov = "llvm-cov --lcov --output-path=./.coverage/lcov.info"
55
time = "build --timings --all-targets"
6+
7+
[build]
8+
rustflags = [
9+
"-D",
10+
"warnings",
11+
"-D",
12+
"future-incompatible",
13+
"-D",
14+
"let-underscore",
15+
"-D",
16+
"nonstandard-style",
17+
"-D",
18+
"rust-2018-compatibility",
19+
"-D",
20+
"rust-2018-idioms",
21+
"-D",
22+
"rust-2021-compatibility",
23+
"-D",
24+
"unused",
25+
]

.vscode/settings.json

+19-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22
"[rust]": {
33
"editor.formatOnSave": true
44
},
5-
"rust-analyzer.checkOnSave.command": "clippy",
6-
"rust-analyzer.checkOnSave.allTargets": true,
7-
"rust-analyzer.checkOnSave.extraArgs": ["--", "-W", "clippy::pedantic"]
8-
}
5+
"rust-analyzer.checkOnSave": true,
6+
"rust-analyzer.check.command": "clippy",
7+
"rust-analyzer.check.allTargets": true,
8+
"rust-analyzer.check.extraArgs": [
9+
"--",
10+
"-D",
11+
"clippy::correctness",
12+
"-D",
13+
"clippy::suspicious",
14+
"-W",
15+
"clippy::complexity",
16+
"-W",
17+
"clippy::perf",
18+
"-W",
19+
"clippy::style",
20+
"-W",
21+
"clippy::pedantic",
22+
],
23+
}

src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running
162162
loop {
163163
interval.tick().await;
164164
if let Some(tracker) = weak_tracker_statistics_importer.upgrade() {
165-
let _ = tracker.import_all_torrents_statistics().await;
165+
drop(tracker.import_all_torrents_statistics().await);
166166
} else {
167167
break;
168168
}

src/cache/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl BytesCache {
121121
}
122122

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

126126
let bytes_cache_entry = BytesCacheEntry::new(bytes);
127127

src/databases/mysql.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Database for Mysql {
7373

7474
// rollback transaction on error
7575
if let Err(e) = insert_user_auth_result {
76-
let _ = tx.rollback().await;
76+
drop(tx.rollback().await);
7777
return Err(e);
7878
}
7979

@@ -100,11 +100,11 @@ impl Database for Mysql {
100100
// commit or rollback transaction and return user_id on success
101101
match insert_user_profile_result {
102102
Ok(_) => {
103-
let _ = tx.commit().await;
103+
drop(tx.commit().await);
104104
Ok(i64::overflowing_add_unsigned(0, user_id).0)
105105
}
106106
Err(e) => {
107-
let _ = tx.rollback().await;
107+
drop(tx.rollback().await);
108108
Err(e)
109109
}
110110
}
@@ -497,7 +497,7 @@ impl Database for Mysql {
497497

498498
// rollback transaction on error
499499
if let Err(e) = insert_torrent_files_result {
500-
let _ = tx.rollback().await;
500+
drop(tx.rollback().await);
501501
return Err(e);
502502
}
503503

@@ -531,7 +531,7 @@ impl Database for Mysql {
531531

532532
// rollback transaction on error
533533
if let Err(e) = insert_torrent_announce_urls_result {
534-
let _ = tx.rollback().await;
534+
drop(tx.rollback().await);
535535
return Err(e);
536536
}
537537

@@ -558,11 +558,11 @@ impl Database for Mysql {
558558
// commit or rollback transaction and return user_id on success
559559
match insert_torrent_info_result {
560560
Ok(_) => {
561-
let _ = tx.commit().await;
561+
drop(tx.commit().await);
562562
Ok(torrent_id)
563563
}
564564
Err(e) => {
565-
let _ = tx.rollback().await;
565+
drop(tx.rollback().await);
566566
Err(e)
567567
}
568568
}

src/databases/sqlite.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Database for Sqlite {
7474

7575
// rollback transaction on error
7676
if let Err(e) = insert_user_auth_result {
77-
let _ = tx.rollback().await;
77+
drop(tx.rollback().await);
7878
return Err(e);
7979
}
8080

@@ -101,11 +101,11 @@ impl Database for Sqlite {
101101
// commit or rollback transaction and return user_id on success
102102
match insert_user_profile_result {
103103
Ok(_) => {
104-
let _ = tx.commit().await;
104+
drop(tx.commit().await);
105105
Ok(user_id)
106106
}
107107
Err(e) => {
108-
let _ = tx.rollback().await;
108+
drop(tx.rollback().await);
109109
Err(e)
110110
}
111111
}
@@ -487,7 +487,7 @@ impl Database for Sqlite {
487487

488488
// rollback transaction on error
489489
if let Err(e) = insert_torrent_files_result {
490-
let _ = tx.rollback().await;
490+
drop(tx.rollback().await);
491491
return Err(e);
492492
}
493493

@@ -521,7 +521,7 @@ impl Database for Sqlite {
521521

522522
// rollback transaction on error
523523
if let Err(e) = insert_torrent_announce_urls_result {
524-
let _ = tx.rollback().await;
524+
drop(tx.rollback().await);
525525
return Err(e);
526526
}
527527

@@ -548,11 +548,11 @@ impl Database for Sqlite {
548548
// commit or rollback transaction and return user_id on success
549549
match insert_torrent_info_result {
550550
Ok(_) => {
551-
let _ = tx.commit().await;
551+
drop(tx.commit().await);
552552
Ok(torrent_id)
553553
}
554554
Err(e) => {
555-
let _ = tx.rollback().await;
555+
drop(tx.rollback().await);
556556
Err(e)
557557
}
558558
}

src/models/info_hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl InfoHash {
167167
}
168168

169169
impl std::fmt::Display for InfoHash {
170-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
171171
let mut chars = [0u8; 40];
172172
binascii::bin2hex(&self.0, &mut chars).expect("failed to hexlify");
173173
write!(f, "{}", std::str::from_utf8(&chars).unwrap())
@@ -271,7 +271,7 @@ struct InfoHashVisitor;
271271
impl<'v> serde::de::Visitor<'v> for InfoHashVisitor {
272272
type Value = InfoHash;
273273

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

src/services/torrent.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ impl Index {
118118

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

121-
let _ = self
122-
.tracker_statistics_importer
123-
.import_torrent_statistics(torrent_id, &torrent_request.torrent.info_hash())
124-
.await;
121+
drop(
122+
self.tracker_statistics_importer
123+
.import_torrent_statistics(torrent_id, &torrent_request.torrent.info_hash())
124+
.await,
125+
);
125126

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

src/services/user.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl RegistrationService {
126126

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

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

143143
if mail_res.is_err() {
144-
let _ = self.user_repository.delete(&user_id).await;
144+
drop(self.user_repository.delete(&user_id).await);
145145
return Err(ServiceError::FailedToSendVerificationEmail);
146146
}
147147
}

src/tracker/statistics_importer.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ impl StatisticsImporter {
6969
/// found.
7070
pub async fn import_torrent_statistics(&self, torrent_id: i64, info_hash: &str) -> Result<TorrentInfo, ServiceError> {
7171
if let Ok(torrent_info) = self.tracker_service.get_torrent_info(info_hash).await {
72-
let _ = self
73-
.database
74-
.update_tracker_info(torrent_id, &self.tracker_url, torrent_info.seeders, torrent_info.leechers)
75-
.await;
72+
drop(
73+
self.database
74+
.update_tracker_info(torrent_id, &self.tracker_url, torrent_info.seeders, torrent_info.leechers)
75+
.await,
76+
);
7677
Ok(torrent_info)
7778
} else {
78-
let _ = self.database.update_tracker_info(torrent_id, &self.tracker_url, 0, 0).await;
79+
drop(self.database.update_tracker_info(torrent_id, &self.tracker_url, 0, 0).await);
7980
Err(ServiceError::TorrentNotFound)
8081
}
8182
}

0 commit comments

Comments
 (0)