Skip to content

Commit 3eca1ab

Browse files
authored
Remove redundant closures (#1655)
* fix: clippy::redundant_closure_for_method_calls * fixup! fix: clippy::redundant_closure_for_method_calls * use Into::into * use Instant::elapsed * cargo fmt * enable clippy lint * add lints to all packages
1 parent 34f9cd2 commit 3eca1ab

File tree

22 files changed

+52
-24
lines changed

22 files changed

+52
-24
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,9 @@ assets = [
209209
["contrib/librespot.service", "lib/systemd/system/", "644"],
210210
["contrib/librespot.user.service", "lib/systemd/user/", "644"],
211211
]
212+
213+
[workspace.lints]
214+
clippy.redundant_closure_for_method_calls = "warn"
215+
216+
[lints]
217+
workspace = true

audio/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ log = "0.4"
3131
tempfile = "3"
3232
thiserror = "2"
3333
tokio = { version = "1", features = ["macros", "sync"] }
34+
35+
[lints]
36+
workspace = true

audio/src/fetch/receive.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ async fn receive_data(
9999
}
100100

101101
let body = response.into_body();
102-
let data = match body.collect().await.map(|b| b.to_bytes()) {
102+
let data = match body
103+
.collect()
104+
.await
105+
.map(http_body_util::Collected::to_bytes)
106+
{
103107
Ok(bytes) => bytes,
104108
Err(e) => break Err(e.into()),
105109
};

connect/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ thiserror = "2"
3131
tokio = { version = "1", features = ["macros", "sync"] }
3232
tokio-stream = { version = "0.1", default-features = false }
3333
uuid = { version = "1.18", default-features = false, features = ["v4"] }
34+
35+
[lints]
36+
workspace = true

connect/src/context_resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl ContextResolver {
142142
let last_try = self
143143
.unavailable_contexts
144144
.get(&resolve)
145-
.map(|i| i.duration_since(Instant::now()));
145+
.map(Instant::elapsed);
146146

147147
let last_try = if matches!(last_try, Some(last_try) if last_try > RETRY_UNAVAILABLE) {
148148
let _ = self.unavailable_contexts.remove(&resolve);

core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ vergen-gitcl = { version = "1.0", default-features = false, features = [
118118

119119
[dev-dependencies]
120120
tokio = { version = "1", features = ["macros"] }
121+
122+
[lints]
123+
workspace = true

core/src/http_client.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,7 @@ impl HttpClient {
240240
let domain = match req.uri().host() {
241241
Some(host) => {
242242
// strip the prefix from *.domain.tld (assume rate limit is per domain, not subdomain)
243-
let mut parts = host
244-
.split('.')
245-
.map(|s| s.to_string())
246-
.collect::<Vec<String>>();
243+
let mut parts = host.split('.').map(Into::into).collect::<Vec<String>>();
247244
let n = parts.len().saturating_sub(2);
248245
parts.drain(n..).collect()
249246
}

core/src/spclient.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl SpClient {
422422
let mut headers = headers.unwrap_or_default();
423423
headers.insert(ACCEPT, HeaderValue::from_static("application/json"));
424424

425-
self.request(method, endpoint, Some(headers), body.map(|s| s.as_bytes()))
425+
self.request(method, endpoint, Some(headers), body.map(str::as_bytes))
426426
.await
427427
}
428428

@@ -749,7 +749,7 @@ impl SpClient {
749749

750750
let previous_track_str = previous_tracks
751751
.iter()
752-
.map(|track| track.to_base62())
752+
.map(SpotifyId::to_base62)
753753
.collect::<Vec<_>>()
754754
.join(",");
755755
// better than checking `previous_tracks.len() > 0` because the `filter_map` could still return 0 items
@@ -952,7 +952,7 @@ impl SpClient {
952952
&Method::POST,
953953
&endpoint,
954954
None,
955-
body.as_deref().map(|s| s.as_bytes()),
955+
body.as_deref().map(str::as_bytes),
956956
&NO_METRICS_AND_SALT,
957957
)
958958
.await

discovery/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ zbus = { version = "5", default-features = false, features = [
6060
futures = "0.3"
6161
hex = "0.4"
6262
tokio = { version = "1", features = ["macros", "rt"] }
63+
64+
[lints]
65+
workspace = true

metadata/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ serde = { version = "1.0", features = ["derive"] }
2929
serde_json = "1.0"
3030
thiserror = "2"
3131
uuid = { version = "1", default-features = false }
32+
33+
[lints]
34+
workspace = true

0 commit comments

Comments
 (0)