Skip to content

Prepare for clippy and rustfmt in rust-2018 #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ matrix:
- rustup component add clippy-preview
script:
- cargo fmt -- --check
# TODO: Once clippy:: lint syntax is stable, remove everything after the -- below
- cargo clippy --all-targets -- -A renamed_and_removed_lints
- cargo clippy --all-targets --all-features --all
- cargo build
- cargo test
- npm install
Expand Down
3 changes: 2 additions & 1 deletion src/bin/delete-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ fn main() {
conn.transaction::<_, diesel::result::Error, _>(|| {
delete(&conn);
Ok(())
}).unwrap()
})
.unwrap()
}

fn delete(conn: &PgConnection) {
Expand Down
3 changes: 2 additions & 1 deletion src/bin/delete-version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ fn main() {
conn.transaction::<_, diesel::result::Error, _>(|| {
delete(&conn);
Ok(())
}).unwrap()
})
.unwrap()
}

fn delete(conn: &PgConnection) {
Expand Down
3 changes: 2 additions & 1 deletion src/bin/on_call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ impl Event {
.json(&FullEvent {
service_key,
event: self,
}).send()?;
})
.send()?;

match response.status() {
s if s.is_success() => Ok(()),
Expand Down
3 changes: 2 additions & 1 deletion src/bin/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ fn update(conn: &PgConnection) -> QueryResult<()> {
version_downloads::version_id.eq(id),
version_downloads::downloads.eq(dls),
version_downloads::date.eq(date(now - day.days())),
)).execute(conn)?;
))
.execute(conn)?;
}
}
Ok(())
Expand Down
15 changes: 10 additions & 5 deletions src/bin/render-readmes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ fn main() {
readme_renderings::rendered_at
.lt(older_than)
.or(readme_renderings::version_id.is_null()),
).select(versions::id)
)
.select(versions::id)
.into_boxed();

if let Some(crate_name) = args.flag_crate {
Expand Down Expand Up @@ -150,7 +151,8 @@ fn main() {
&readme_path,
readme.into_bytes(),
"text/html",
).unwrap_or_else(|_| {
)
.unwrap_or_else(|_| {
panic!(
"[{}-{}] Couldn't upload file to S3",
krate_name, version.num
Expand Down Expand Up @@ -227,7 +229,8 @@ fn get_readme(config: &Config, version: &Version, krate_name: &str) -> Option<St
.as_ref()
.map_or("README.md", |e| &**e),
manifest.package.repository.as_ref().map(|e| &**e),
).unwrap_or_else(|_| panic!("[{}-{}] Couldn't render README", krate_name, version.num))
)
.unwrap_or_else(|_| panic!("[{}-{}] Couldn't render README", krate_name, version.num))
};
return Some(rendered);

Expand Down Expand Up @@ -261,14 +264,16 @@ fn find_file_by_path<R: Read>(
};
filepath == path
}
}).unwrap_or_else(|| {
})
.unwrap_or_else(|| {
panic!(
"[{}-{}] couldn't open file: {}",
krate_name,
version.num,
path.display()
)
}).unwrap_or_else(|_| {
})
.unwrap_or_else(|_| {
panic!(
"[{}-{}] file is not present: {}",
krate_name,
Expand Down
3 changes: 2 additions & 1 deletion src/bin/transfer-crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ fn main() {
conn.transaction::<_, diesel::result::Error, _>(|| {
transfer(&conn);
Ok(())
}).unwrap()
})
.unwrap()
}

fn transfer(conn: &PgConnection) {
Expand Down
27 changes: 18 additions & 9 deletions src/bin/update-downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ fn collect(conn: &PgConnection, rows: &[VersionDownload]) -> QueryResult<()> {
crate_downloads::crate_id.eq(crate_id),
crate_downloads::downloads.eq(amt),
crate_downloads::date.eq(download.date),
)).on_conflict(crate_downloads::table.primary_key())
))
.on_conflict(crate_downloads::table.primary_key())
.do_update()
.set(crate_downloads::downloads.eq(crate_downloads::downloads + amt))
.execute(conn)?;
Expand Down Expand Up @@ -136,7 +137,8 @@ mod test {
let krate = NewCrate {
name: "foo",
..Default::default()
}.create_or_update(&conn, None, user_id)
}
.create_or_update(&conn, None, user_id)
.unwrap();
let version = NewVersion::new(
krate.id,
Expand All @@ -145,7 +147,8 @@ mod test {
None,
None,
0,
).unwrap();
)
.unwrap();
let version = version.save(&conn, &[]).unwrap();
(krate, version)
}
Expand Down Expand Up @@ -176,7 +179,8 @@ mod test {
version_downloads::version_id.eq(version.id),
version_downloads::date.eq(date(now - 1.day())),
version_downloads::processed.eq(true),
)).execute(&conn)
))
.execute(&conn)
.unwrap();

::update(&conn).unwrap();
Expand Down Expand Up @@ -213,7 +217,8 @@ mod test {
version_downloads::counted.eq(2),
version_downloads::date.eq(date(now - 2.days())),
version_downloads::processed.eq(false),
)).execute(&conn)
))
.execute(&conn)
.unwrap();
::update(&conn).unwrap();
let processed = version_downloads::table
Expand All @@ -236,7 +241,8 @@ mod test {
version_downloads::counted.eq(2),
version_downloads::date.eq(date(now)),
version_downloads::processed.eq(false),
)).execute(&conn)
))
.execute(&conn)
.unwrap();
::update(&conn).unwrap();
let processed = version_downloads::table
Expand Down Expand Up @@ -269,13 +275,15 @@ mod test {
version_downloads::counted.eq(1),
version_downloads::date.eq(date(now)),
version_downloads::processed.eq(false),
)).execute(&conn)
))
.execute(&conn)
.unwrap();
insert_into(version_downloads::table)
.values((
version_downloads::version_id.eq(version.id),
version_downloads::date.eq(date(now - 1.day())),
)).execute(&conn)
))
.execute(&conn)
.unwrap();

let version_before = versions::table
Expand Down Expand Up @@ -331,7 +339,8 @@ mod test {
version_downloads::counted.eq(2),
version_downloads::date.eq(date(now - 2.days())),
version_downloads::processed.eq(false),
)).execute(&conn)
))
.execute(&conn)
.unwrap();

::update(&conn).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions src/boot/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ pub fn sync_with_connection(toml_str: &str, conn: &PgConnection) -> CargoResult<
category.eq(c.name),
description.eq(c.description),
)
}).collect::<Vec<_>>();
})
.collect::<Vec<_>>();

conn.transaction(|| {
let slugs = diesel::insert_into(categories)
Expand All @@ -117,7 +118,8 @@ pub fn sync_with_connection(toml_str: &str, conn: &PgConnection) -> CargoResult<
.set((
category.eq(excluded(category)),
description.eq(excluded(description)),
)).returning(slug)
))
.returning(slug)
.get_results::<String>(&*conn)?;

diesel::delete(categories)
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ fn accept_invite(
owner_id: user_id,
created_by: pending_crate_owner.invited_by_user_id,
owner_kind: OwnerKind::User as i32,
}).on_conflict(crate_owners::table.primary_key())
})
.on_conflict(crate_owners::table.primary_key())
.do_update()
.set(crate_owners::deleted.eq(false))
.execute(conn)?;
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/krate/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ pub fn downloads(req: &mut dyn Request) -> CargoResult<Response> {
.select((
to_char(version_downloads::date, "YYYY-MM-DD"),
sum_downloads,
)).filter(version_downloads::date.gt(date(now - 90.days())))
))
.filter(version_downloads::date.gt(date(now - 90.days())))
.group_by(version_downloads::date)
.order(version_downloads::date.asc())
.load::<ExtraDownload>(&*conn)?;
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/krate/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pub fn summary(req: &mut dyn Request) -> CargoResult<Response> {
.zip(krates)
.map(|(max_version, krate)| {
Ok(krate.minimal_encodable(&max_version, None, false, None))
}).collect()
})
.collect()
};

let new_crates = crates
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
k[..].to_string(),
v.iter().map(|v| v[..].to_string()).collect(),
)
}).collect::<HashMap<String, Vec<String>>>();
})
.collect::<HashMap<String, Vec<String>>>();
let keywords = new_crate
.keywords
.as_ref()
Expand Down Expand Up @@ -146,7 +147,8 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
// Downcast is okay because the file length must be less than the max upload size
// to get here, and max upload sizes are way less than i32 max
file_length as i32,
)?.save(&conn, &new_crate.authors)?;
)?
.save(&conn, &new_crate.authors)?;

// Link this new version to all dependencies
let git_deps = dependency::add_dependencies(&conn, &new_crate.deps, version.id)?;
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ pub fn search(req: &mut dyn Request) -> CargoResult<Response> {
ALL_COLUMNS,
false.into_sql::<Bool>(),
recent_crate_downloads::downloads.nullable(),
)).into_boxed();
))
.into_boxed();

if let Some(q_string) = params.get("q") {
if !q_string.is_empty() {
Expand Down Expand Up @@ -189,7 +190,8 @@ pub fn search(req: &mut dyn Request) -> CargoResult<Response> {
Some(recent_downloads),
)
},
).collect();
)
.collect();

#[derive(Serialize)]
struct R {
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/user/me.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pub fn me(req: &mut dyn Request) -> CargoResult<Response> {
emails::verified.nullable(),
emails::email.nullable(),
emails::token_generated_at.nullable().is_not_null(),
)).first::<(User, Option<bool>, Option<String>, bool)>(&*conn)?;
))
.first::<(User, Option<bool>, Option<String>, bool)>(&*conn)?;

let verified = verified.unwrap_or(false);
let verification_sent = verified || verification_sent;
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/user/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub fn stats(req: &mut dyn Request) -> CargoResult<Response> {
crate_owners::owner_id
.eq(user_id)
.and(crate_owners::owner_kind.eq(OwnerKind::User as i32)),
).select(sum(crates::downloads))
)
.select(sum(crates::downloads))
.first::<Option<i64>>(&*conn)?
.unwrap_or(0);

Expand Down
3 changes: 2 additions & 1 deletion src/controllers/user/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ pub fn github_access_token(req: &mut dyn Request) -> CargoResult<Response> {
ghuser.name.as_ref().map(|s| &s[..]),
ghuser.avatar_url.as_ref().map(|s| &s[..]),
&token.access_token,
).create_or_update(&*req.db_conn()?)?;
)
.create_or_update(&*req.db_conn()?)?;
req.session()
.insert("user_id".to_string(), user.id.to_string());
req.mut_extensions().insert(user);
Expand Down
3 changes: 2 additions & 1 deletion src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ fn send_email(recipient: &str, subject: &str, body: &str) -> CargoResult<()> {
.credentials(Credentials::new(
mailgun_config.smtp_login,
mailgun_config.smtp_password,
)).smtp_utf8(true)
))
.smtp_utf8(true)
.authentication_mechanism(Mechanism::Plain)
.build();

Expand Down
3 changes: 2 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ pub fn yank(app: &App, krate: &str, version: &semver::Version, yanked: bool) ->
}
git_crate.yanked = Some(yanked);
Ok(serde_json::to_string(&git_crate).unwrap())
}).collect::<CargoResult<Vec<String>>>();
})
.collect::<CargoResult<Vec<String>>>();
let new = new?.join("\n");
let mut f = File::create(&dst)?;
f.write_all(new.as_bytes())?;
Expand Down
3 changes: 2 additions & 1 deletion src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ where
.header(
header::AUTHORIZATION,
format!("token {}", auth.access_token),
).send()?
)
.send()?
.error_for_status()
.map_err(|e| handle_error_response(&e))?
.json()
Expand Down
6 changes: 1 addition & 5 deletions src/models/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ pub struct CrateBadge {
}

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(
rename_all = "kebab-case",
tag = "badge_type",
content = "attributes"
)]
#[serde(rename_all = "kebab-case", tag = "badge_type", content = "attributes")]
pub enum Badge {
TravisCi {
repository: String,
Expand Down
Loading