Skip to content

Commit b50ebd3

Browse files
committed
Auto merge of #3715 - jtgeibel:clippy-fixes, r=Turbo87
Address clippy findings This addresses warnings identified by clippy. Some of these warnings are currently generated on stable, but a missing environment variable caused those warnings to be logged but not to fail the build. The next to last commit fixes this. This final commit pins to 1.52.1 for linting, until a compiler ICE in 1.53.0 is addressed. I've just [reported] this ICE against the pre-release, but it may be too late to address in 1.53.0. r? `@Turbo87` [reported]: https://internals.rust-lang.org/t/1-53-0-prerelease-testing/14884/2?u=jtgeibel
2 parents d547935 + d5471df commit b50ebd3

29 files changed

+81
-76
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ jobs:
6868
name: Backend (linting)
6969
runs-on: ubuntu-20.04
7070

71+
env:
72+
CARGO_INCREMENTAL: 0
73+
RUSTFLAGS: "-D warnings"
74+
7175
steps:
7276
- uses: actions/checkout@v2
7377

@@ -98,8 +102,9 @@ jobs:
98102
- name: Install Rust
99103
run: |
100104
rustup set profile minimal
101-
rustup update stable
102-
rustup default stable
105+
# Pin to older version until a clippy regression is fixed
106+
rustup update 1.52.1
107+
rustup default 1.52.1
103108
104109
- run: rustup component add rustfmt
105110
- run: rustup component add clippy

src/admin/migrate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Error;
22

3-
static CATEGORIES_TOML: &'static str = include_str!("../boot/categories.toml");
3+
static CATEGORIES_TOML: &str = include_str!("../boot/categories.toml");
44
diesel_migrations::embed_migrations!("./migrations");
55

66
#[derive(clap::Clap, Debug, Copy, Clone)]

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl App {
141141
.connection_customizer(Box::new(replica_db_connection_config))
142142
.thread_pool(thread_pool);
143143

144-
Some(DieselPool::new(&url, replica_db_config).unwrap())
144+
Some(DieselPool::new(url, replica_db_config).unwrap())
145145
}
146146
} else {
147147
None

src/bin/crates-admin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum SubCommand {
2929
fn main() -> anyhow::Result<()> {
3030
let opts: Opts = Opts::parse();
3131

32-
Ok(match opts.command {
32+
match opts.command {
3333
SubCommand::DeleteCrate(opts) => delete_crate::run(opts),
3434
SubCommand::DeleteVersion(opts) => delete_version::run(opts),
3535
SubCommand::Populate(opts) => populate::run(opts),
@@ -38,5 +38,7 @@ fn main() -> anyhow::Result<()> {
3838
SubCommand::TransferCrates(opts) => transfer_crates::run(opts),
3939
SubCommand::VerifyToken(opts) => verify_token::run(opts).unwrap(),
4040
SubCommand::Migrate(opts) => migrate::run(opts)?,
41-
})
41+
}
42+
43+
Ok(())
4244
}

src/controllers/crate_owner_invitation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn list(req: &mut dyn RequestExt) -> EndpointResult {
6161
.cloned()
6262
.unwrap_or_else(|| String::from("(unknown crate name)"));
6363

64-
let expires_at = invitation.expires_at(&config);
64+
let expires_at = invitation.expires_at(config);
6565
EncodableCrateOwnerInvitation::from(invitation, inviter_name, crate_name, expires_at)
6666
})
6767
.collect();
@@ -101,11 +101,11 @@ pub fn handle_invite(req: &mut dyn RequestExt) -> EndpointResult {
101101
let conn = &*req.db_conn()?;
102102
let config = &req.app().config;
103103

104-
let invitation = CrateOwnerInvitation::find_by_id(user_id, crate_invite.crate_id, &conn)?;
104+
let invitation = CrateOwnerInvitation::find_by_id(user_id, crate_invite.crate_id, conn)?;
105105
if crate_invite.accepted {
106-
invitation.accept(&conn, config)?;
106+
invitation.accept(conn, config)?;
107107
} else {
108-
invitation.decline(&conn)?;
108+
invitation.decline(conn)?;
109109
}
110110

111111
#[derive(Serialize)]

src/controllers/krate/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn search(req: &mut dyn RequestExt) -> EndpointResult {
7373
query = query.filter(
7474
q.clone()
7575
.matches(crates::textsearchable_index_col)
76-
.or(Crate::loosly_matches_name(&q_string)),
76+
.or(Crate::loosly_matches_name(q_string)),
7777
);
7878

7979
query = query.select((

src/controllers/user/session.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ pub fn authorize(req: &mut dyn RequestExt) -> EndpointResult {
103103

104104
// Fetch the user info from GitHub using the access token we just got and create a user record
105105
let ghuser = req.app().github.current_user(token)?;
106-
let user = save_user_to_database(
107-
&ghuser,
108-
&token.secret(),
109-
&req.app().emails,
110-
&*req.db_conn()?,
111-
)?;
106+
let user = save_user_to_database(&ghuser, token.secret(), &req.app().emails, &*req.db_conn()?)?;
112107

113108
// Log in by setting a cookie and the middleware authentication
114109
req.session_mut()

src/controllers/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'a> UserAuthenticationExt for dyn RequestExt + 'a {
127127
};
128128
if still_locked {
129129
return Err(account_locked(
130-
&reason,
130+
reason,
131131
authenticated_user.user.account_lock_until,
132132
));
133133
}

src/controllers/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn version_and_crate(
1313
semver: &str,
1414
) -> AppResult<(Version, Crate)> {
1515
let krate: Crate = Crate::by_name(crate_name).first(conn)?;
16-
let version = krate.find_version(&conn, semver)?;
16+
let version = krate.find_version(conn, semver)?;
1717

1818
Ok((version, krate))
1919
}

src/downloads_counter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl DownloadsCounter {
7878
let mut stats = PersistStats::default();
7979
for shard in self.inner.shards() {
8080
let shard = std::mem::take(&mut *shard.write());
81-
stats = stats.merge(self.persist_shard(&conn, shard)?);
81+
stats = stats.merge(self.persist_shard(conn, shard)?);
8282
}
8383

8484
Ok(stats)
@@ -92,7 +92,7 @@ impl DownloadsCounter {
9292
let idx = self.shard_idx.fetch_add(1, Ordering::SeqCst) % shards.len();
9393
let shard = std::mem::take(&mut *shards[idx].write());
9494

95-
let mut stats = self.persist_shard(&conn, shard)?;
95+
let mut stats = self.persist_shard(conn, shard)?;
9696
stats.shard = Some(idx);
9797
Ok(stats)
9898
}

src/email.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ or go to https://{domain}/me/pending-invites to manage all of your crate ownersh
109109
login,
110110
password,
111111
} => {
112-
SmtpTransport::relay(&server)?
112+
SmtpTransport::relay(server)?
113113
.credentials(Credentials::new(login.clone(), password.clone()))
114114
.authentication(vec![Mechanism::Plain])
115115
.build()

src/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl Repository {
203203
let parent = self.repository.find_commit(head)?;
204204
let sig = self.repository.signature()?;
205205
self.repository
206-
.commit(Some("HEAD"), &sig, &sig, &msg, &tree, &[&parent])?;
206+
.commit(Some("HEAD"), &sig, &sig, msg, &tree, &[&parent])?;
207207

208208
self.push()
209209
}

src/metrics/log_encoder.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const CHUNKS_MAX_SIZE_BYTES: usize = 5000;
2727
#[derive(Debug, Clone, Copy)]
2828
pub struct LogEncoder(());
2929

30+
impl Default for LogEncoder {
31+
fn default() -> Self {
32+
Self::new()
33+
}
34+
}
35+
3036
impl LogEncoder {
3137
pub fn new() -> Self {
3238
Self(())
@@ -132,6 +138,7 @@ fn serialize_and_split_list<'a, S: Serialize + 'a>(
132138
let mut serializer = Serializer::new(EncoderWriter::new(&mut writer, base64::STANDARD));
133139

134140
let mut seq = serializer.serialize_seq(None)?;
141+
#[allow(clippy::while_let_on_iterator)]
135142
while let Some(next) = items.next() {
136143
seq.serialize_element(next)?;
137144
if written_count.get() >= max_size_hint {
@@ -363,7 +370,7 @@ mod tests {
363370
fn test_encoding() -> Result<(), Error> {
364371
let gauge = IntGauge::with_opts(Opts::new("sample_gauge", "sample_gauge help message"))?;
365372
let registry = Registry::new();
366-
registry.register(Box::new(gauge.clone()))?;
373+
registry.register(Box::new(gauge))?;
367374

368375
let mut output = Vec::new();
369376
LogEncoder::new().encode(&registry.gather(), &mut output)?;

src/models/krate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl Crate {
336336
let config = &app.config;
337337
match CrateOwnerInvitation::create(user.id, req_user.id, self.id, conn, config)? {
338338
NewCrateOwnerInvitationOutcome::InviteCreated { plaintext_token } => {
339-
if let Ok(Some(email)) = user.verified_email(&conn) {
339+
if let Ok(Some(email)) = user.verified_email(conn) {
340340
// Swallow any error. Whether or not the email is sent, the invitation
341341
// entry will be created in the database and the user will see the
342342
// invitation when they visit https://crates.io/me/pending-invites/.

src/models/version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ impl TopVersions {
7272
.collect();
7373

7474
let newest = pairs.iter().max().map(|(_, v)| v.clone());
75-
let highest = pairs.iter().map(|(_, v)| v).max().map(|v| v.clone());
75+
let highest = pairs.iter().map(|(_, v)| v).max().cloned();
7676
let highest_stable = pairs
7777
.iter()
7878
.map(|(_, v)| v)
7979
.filter(|v| v.pre.is_empty())
8080
.max()
81-
.map(|v| v.clone());
81+
.cloned();
8282

8383
Self {
8484
highest,

src/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub fn render_and_upload_readme(
276276
let rendered = readme_to_html(&text, &file_name, base_url.as_deref());
277277

278278
conn.transaction(|| {
279-
Version::record_readme_rendering(version_id, &conn)?;
279+
Version::record_readme_rendering(version_id, conn)?;
280280
let (crate_name, vers): (String, String) = versions::table
281281
.find(version_id)
282282
.inner_join(crates::table)

src/s3/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Bucket {
4646
content_type: &str,
4747
extra_headers: header::HeaderMap,
4848
) -> Result<Response, Error> {
49-
let path = path.strip_prefix("/").unwrap_or(path);
49+
let path = path.strip_prefix('/').unwrap_or(path);
5050
let date = Utc::now().to_rfc2822();
5151
let auth = self.auth("PUT", &date, path, "", content_type);
5252
let url = self.url(path);
@@ -66,7 +66,7 @@ impl Bucket {
6666
}
6767

6868
pub fn delete(&self, client: &Client, path: &str) -> Result<Response, Error> {
69-
let path = path.strip_prefix("/").unwrap_or(path);
69+
let path = path.strip_prefix('/').unwrap_or(path);
7070
let date = Utc::now().to_rfc2822();
7171
let auth = self.auth("DELETE", &date, path, "", "");
7272
let url = self.url(path);

src/tasks/update_downloads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use swirl::PerformError;
88

99
#[swirl::background_job]
1010
pub fn update_downloads(conn: &PgConnection) -> Result<(), PerformError> {
11-
update(&conn)?;
11+
update(conn)?;
1212
Ok(())
1313
}
1414

src/tests/category.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn update_crate() {
7575
assert_ok!(
7676
new_category("Category 2", "category-2", "Category 2 crates").create_or_update(conn)
7777
);
78-
let krate = CrateBuilder::new("foo_crate", user.id).expect_build(&conn);
78+
let krate = CrateBuilder::new("foo_crate", user.id).expect_build(conn);
7979

8080
// Updating with no categories has no effect
8181
Category::update_crate(conn, &krate, &[]).unwrap();
@@ -127,7 +127,7 @@ fn update_crate() {
127127

128128
// Add a category and its subcategory
129129
assert_ok!(new_category("cat1::bar", "cat1::bar", "bar crates").create_or_update(conn));
130-
Category::update_crate(&conn, &krate, &["cat1", "cat1::bar"]).unwrap();
130+
Category::update_crate(conn, &krate, &["cat1", "cat1::bar"]).unwrap();
131131

132132
assert_eq!(count(&anon, "cat1"), 1);
133133
assert_eq!(count(&anon, "cat1::bar"), 1);

src/tests/krate/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ fn publish_records_an_audit_action() {
640640

641641
let (app, anon, _, token) = TestApp::full().with_token();
642642

643-
app.db(|conn| assert!(VersionOwnerAction::all(&conn).unwrap().is_empty()));
643+
app.db(|conn| assert!(VersionOwnerAction::all(conn).unwrap().is_empty()));
644644

645645
// Upload a new crate, putting it in the git index
646646
let crate_to_publish = PublishBuilder::new("fyk");

src/tests/krate/yanking.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl crate::util::MockCookieUser {
4040
}
4141

4242
#[test]
43+
#[allow(unknown_lints, clippy::bool_assert_comparison)] // for claim::assert_some_eq! with bool
4344
fn yank_works_as_intended() {
4445
let (app, anon, cookie, token) = TestApp::full().with_token();
4546

src/tests/owners.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn modify_multiple_owners() {
215215
response.json(),
216216
json!({ "errors": [{ "detail": "cannot remove all individual owners of a crate. Team member don't have permission to modify owners, so at least one individual owner is required." }] })
217217
);
218-
assert_eq!(app.db(|conn| krate.owners(&conn).unwrap()).len(), 3);
218+
assert_eq!(app.db(|conn| krate.owners(conn).unwrap()).len(), 3);
219219

220220
// Deleting two owners at once is allowed.
221221
let response = token.remove_named_owners("owners_multiple", &["user2", "user3"]);
@@ -224,7 +224,7 @@ fn modify_multiple_owners() {
224224
response.json(),
225225
json!({ "msg": "owners successfully removed", "ok": true })
226226
);
227-
assert_eq!(app.db(|conn| krate.owners(&conn).unwrap()).len(), 1);
227+
assert_eq!(app.db(|conn| krate.owners(conn).unwrap()).len(), 1);
228228

229229
// Adding multiple users fails if one of them already is an owner.
230230
let response = token.add_named_owners("owners_multiple", &["user2", username]);
@@ -233,7 +233,7 @@ fn modify_multiple_owners() {
233233
response.json(),
234234
json!({ "errors": [{ "detail": "`foo` is already an owner" }] })
235235
);
236-
assert_eq!(app.db(|conn| krate.owners(&conn).unwrap()).len(), 1);
236+
assert_eq!(app.db(|conn| krate.owners(conn).unwrap()).len(), 1);
237237

238238
// Adding multiple users at once succeeds.
239239
let response = token.add_named_owners("owners_multiple", &["user2", "user3"]);
@@ -249,7 +249,7 @@ fn modify_multiple_owners() {
249249
user2.accept_ownership_invitation(&krate.name, krate.id);
250250
user3.accept_ownership_invitation(&krate.name, krate.id);
251251

252-
assert_eq!(app.db(|conn| krate.owners(&conn).unwrap()).len(), 3);
252+
assert_eq!(app.db(|conn| krate.owners(conn).unwrap()).len(), 3);
253253
}
254254

255255
#[test]
@@ -449,7 +449,7 @@ fn invitations_list() {
449449
InvitationListResponse {
450450
crate_owner_invitations: vec![EncodableCrateOwnerInvitation {
451451
crate_id: krate.id,
452-
crate_name: krate.name.clone(),
452+
crate_name: krate.name,
453453
invited_by_username: owner.gh_login.clone(),
454454
invitee_id: user.as_model().id,
455455
inviter_id: owner.id,
@@ -484,7 +484,7 @@ fn invitations_list_does_not_include_expired_invites() {
484484
InvitationListResponse {
485485
crate_owner_invitations: vec![EncodableCrateOwnerInvitation {
486486
crate_id: krate2.id,
487-
crate_name: krate2.name.clone(),
487+
crate_name: krate2.name,
488488
invited_by_username: owner.gh_login.clone(),
489489
invitee_id: user.as_model().id,
490490
inviter_id: owner.id,

src/tests/server_binary.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ impl ServerBin {
9292
env.remove("DB_MIN_SIZE");
9393
// Other configuration variables needed for the application to boot.
9494
env.insert("WEB_ALLOWED_ORIGINS".into(), "http://localhost:8888".into());
95-
env.insert(
96-
"SESSION_KEY".into(),
97-
std::iter::repeat('a').take(32).collect(),
98-
);
95+
env.insert("SESSION_KEY".into(), "a".repeat(32));
9996
env.insert("GH_CLIENT_ID".into(), String::new());
10097
env.insert("GH_CLIENT_SECRET".into(), String::new());
10198

src/tests/token.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ fn list_tokens_exclude_revoked() {
9797
// Check that we now have one less token being listed.
9898
let json: ListResponse = user.get(URL).good();
9999
assert_eq!(json.api_tokens.len(), tokens.len() - 1);
100-
assert!(json
100+
assert!(!json
101101
.api_tokens
102102
.iter()
103-
.find(|token| token.name == tokens[0].model.name)
104-
.is_none());
103+
.any(|token| token.name == tokens[0].model.name));
105104
}
106105

107106
#[test]
@@ -175,7 +174,7 @@ fn create_token_success() {
175174
app.db(|conn| assert_ok!(ApiToken::belonging_to(user.as_model()).load(conn)));
176175
assert_eq!(tokens.len(), 1);
177176
assert_eq!(tokens[0].name, "bar");
178-
assert_eq!(tokens[0].revoked, false);
177+
assert!(!tokens[0].revoked);
179178
assert_eq!(tokens[0].last_used_at, None);
180179
}
181180

0 commit comments

Comments
 (0)