Skip to content

Commit e2f20c7

Browse files
committed
Auto merge of #1705 - jtgeibel:clippy/redundant_closure, r=carols10cents
Fix new instances caught by `clippy::redundant_closure` The lint is more sensitive starting in 1.34 (currently in beta). This addresses the new warnings so that CI isn't affected after the release next week. There is one case that recommends using `failure::error::Error::compat` however we do not currently include `failure` in our TOML file. Rather than add it just for this case, I've allowed the lint for this expression.
2 parents 6bdd95c + 7dff61f commit e2f20c7

File tree

12 files changed

+20
-16
lines changed

12 files changed

+20
-16
lines changed

src/background_jobs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::panic::AssertUnwindSafe;
2-
use std::sync::{Mutex, MutexGuard};
2+
use std::sync::{Mutex, MutexGuard, PoisonError};
33

44
use crate::db::{DieselPool, DieselPooledConn};
55
use crate::git::Repository;
@@ -49,7 +49,7 @@ impl Environment {
4949
}
5050

5151
pub fn lock_index(&self) -> CargoResult<MutexGuard<'_, Repository>> {
52-
let repo = self.index.lock().unwrap_or_else(|e| e.into_inner());
52+
let repo = self.index.lock().unwrap_or_else(PoisonError::into_inner);
5353
repo.reset_head()?;
5454
Ok(repo)
5555
}

src/controllers/krate/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ pub fn show(req: &mut dyn Request) -> CargoResult<Response> {
153153
.into_iter()
154154
.map(|(v, pb)| v.encodable(&krate.name, pb))
155155
.collect(),
156-
keywords: kws.into_iter().map(|k| k.encodable()).collect(),
157-
categories: cats.into_iter().map(|k| k.encodable()).collect(),
156+
keywords: kws.into_iter().map(Keyword::encodable).collect(),
157+
categories: cats.into_iter().map(Category::encodable).collect(),
158158
}))
159159
}
160160

src/controllers/krate/publish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn parse_new_headers(req: &mut dyn Request) -> CargoResult<(EncodableCrateUpload
245245

246246
// Make sure required fields are provided
247247
fn empty(s: Option<&String>) -> bool {
248-
s.map_or(true, |s| s.is_empty())
248+
s.map_or(true, String::is_empty)
249249
}
250250
let mut missing = Vec::new();
251251

@@ -255,7 +255,7 @@ fn parse_new_headers(req: &mut dyn Request) -> CargoResult<(EncodableCrateUpload
255255
if empty(new.license.as_ref()) && empty(new.license_file.as_ref()) {
256256
missing.push("license");
257257
}
258-
if new.authors.iter().all(|s| s.is_empty()) {
258+
if new.authors.iter().all(String::is_empty) {
259259
missing.push("authors");
260260
}
261261
if !missing.is_empty() {

src/email.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fn build_email(
4242
.map(|s| s.smtp_login.as_str())
4343
.unwrap_or("test@localhost");
4444

45+
#[allow(clippy::redundant_closure)]
4546
let email = Email::builder()
4647
.to(recipient)
4748
.from(sender)

src/middleware/log_connection_pool_status.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::app::App;
66
use conduit::Request;
77
use std::sync::{
88
atomic::{AtomicUsize, Ordering},
9-
Arc, Mutex,
9+
Arc, Mutex, PoisonError,
1010
};
1111
use std::time::{Duration, Instant};
1212

@@ -29,7 +29,10 @@ impl LogConnectionPoolStatus {
2929

3030
impl Middleware for LogConnectionPoolStatus {
3131
fn before(&self, _: &mut dyn Request) -> Result<(), Box<dyn Error + Send>> {
32-
let mut last_log_time = self.last_log_time.lock().unwrap_or_else(|e| e.into_inner());
32+
let mut last_log_time = self
33+
.last_log_time
34+
.lock()
35+
.unwrap_or_else(PoisonError::into_inner);
3336
let in_flight_requests = self.in_flight_requests.fetch_add(1, Ordering::SeqCst);
3437
if last_log_time.elapsed() >= Duration::from_secs(60) {
3538
*last_log_time = Instant::now();

src/models/category.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Category {
8787
.iter()
8888
.cloned()
8989
.filter(|s| !categories.iter().any(|c| c.slug == *s))
90-
.map(|s| s.to_string())
90+
.map(ToString::to_string)
9191
.collect();
9292
let crate_categories = categories
9393
.iter()

src/models/dependency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn add_dependencies(
113113
git::Dependency {
114114
name,
115115
req: dep.version_req.to_string(),
116-
features: dep.features.iter().map(|s| s.to_string()).collect(),
116+
features: dep.features.iter().map(|s| s.0.to_string()).collect(),
117117
optional: dep.optional,
118118
default_features: dep.default_features,
119119
target: dep.target.clone(),

src/models/krate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl Crate {
332332
};
333333
let keyword_ids = keywords.map(|kws| kws.iter().map(|kw| kw.keyword.clone()).collect());
334334
let category_ids = categories.map(|cats| cats.iter().map(|cat| cat.slug.clone()).collect());
335-
let badges = badges.map(|bs| bs.into_iter().map(|b| b.encodable()).collect());
335+
let badges = badges.map(|bs| bs.into_iter().map(Badge::encodable).collect());
336336
let documentation = Crate::remove_blocked_documentation_urls(documentation);
337337

338338
EncodableCrate {

src/models/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Version {
7070
authors: format!("/api/v1/crates/{}/{}/authors", crate_name, num),
7171
},
7272
crate_size,
73-
published_by: published_by.map(|pb| pb.encodable_public()),
73+
published_by: published_by.map(User::encodable_public),
7474
}
7575
}
7676

src/render.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> MarkdownRenderer<'a> {
102102
.cloned()
103103
.collect();
104104

105-
let sanitizer_base_url = base_url.map(|s| s.to_string());
105+
let sanitizer_base_url = base_url.map(ToString::to_string);
106106

107107
// Constrain the type of the closures given to the HTML sanitizer.
108108
fn constrain_closure<F>(f: F) -> F
@@ -124,7 +124,7 @@ impl<'a> MarkdownRenderer<'a> {
124124
fn is_media_url(url: &str) -> bool {
125125
Path::new(url)
126126
.extension()
127-
.and_then(|e| e.to_str())
127+
.and_then(std::ffi::OsStr::to_str)
128128
.map_or(false, |e| match e {
129129
"png" | "svg" | "jpg" | "jpeg" | "gif" | "mp4" | "webm" | "ogg" => true,
130130
_ => false,

src/tests/record.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl GhUser {
358358
})
359359
.basic_auth(self.login, Some(password));
360360

361-
let mut response = t!(req.send().and_then(|r| r.error_for_status()));
361+
let mut response = t!(req.send().and_then(reqwest::Response::error_for_status));
362362

363363
#[derive(Deserialize)]
364364
struct Response {

src/util/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub trait CargoError: Send + fmt::Display + fmt::Debug + 'static {
3333
}],
3434
}))
3535
} else {
36-
self.cause().and_then(|cause| cause.response())
36+
self.cause().and_then(CargoError::response)
3737
}
3838
}
3939
fn human(&self) -> bool {

0 commit comments

Comments
 (0)