Skip to content

Commit f99192b

Browse files
authored
Merge pull request #1872 from tshepang/code-cleaning
code cleaning
2 parents e61c210 + fb06679 commit f99192b

File tree

11 files changed

+32
-36
lines changed

11 files changed

+32
-36
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[package]
22
name = "rust-team"
3-
version = "0.1.0"
4-
authors = ["Alex Crichton <alex@alexcrichton.com>", "Pietro Albini <pietro@pietroalbini.org>"]
5-
edition = '2018'
3+
edition = '2021'
64
license.workspace = true
75

86
[dependencies]

src/api/github.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl GitHubApi {
5858
let url = if url.starts_with("https://") {
5959
Cow::Borrowed(url)
6060
} else {
61-
Cow::Owned(format!("{}{}", API_BASE, url))
61+
Cow::Owned(format!("{API_BASE}{url}"))
6262
};
6363
if require_auth {
6464
self.require_auth()?;
@@ -68,7 +68,7 @@ impl GitHubApi {
6868
if let Some(token) = &self.token {
6969
req = req.header(
7070
header::AUTHORIZATION,
71-
HeaderValue::from_str(&format!("token {}", token))?,
71+
HeaderValue::from_str(&format!("token {token}"))?,
7272
);
7373
}
7474
Ok(req)
@@ -108,7 +108,7 @@ impl GitHubApi {
108108

109109
pub(crate) fn user(&self, login: &str) -> Result<User, Error> {
110110
Ok(self
111-
.prepare(false, Method::GET, &format!("users/{}", login))?
111+
.prepare(false, Method::GET, &format!("users/{login}"))?
112112
.send()?
113113
.error_for_status()?
114114
.json()?)

src/api/zulip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl ZulipApi {
7777
) -> Result<Response, Error> {
7878
let mut req = self
7979
.client
80-
.request(method, format!("{}{}", ZULIP_BASE_URL, path));
80+
.request(method, format!("{ZULIP_BASE_URL}{path}"));
8181

8282
if let Some((username, token)) = &self.auth {
8383
req = req.basic_auth(username, Some(token))

src/ci.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ fn generate_codeowners_content(data: Data) -> String {
9191
})
9292
.flat_map(|(team, _)| {
9393
data.team(team)
94-
.expect(&format!("team {team} not found"))
94+
.unwrap_or_else(|| panic!("team {team} not found"))
9595
.members(&data)
96-
.expect(&format!("team {team} members couldn't be loaded"))
96+
.unwrap_or_else(|_| panic!("team {team} members couldn't be loaded"))
9797
}),
9898
);
9999

src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Data {
9595
{
9696
for entry in std::fs::read_dir(&dir).with_context(|| {
9797
let dir = dir.as_ref().display();
98-
format!("`load_dir` failed to read directory '{}'", dir)
98+
format!("`load_dir` failed to read directory '{dir}'")
9999
})? {
100100
let path = entry?.path();
101101
if nested && path.is_dir() {

src/main.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ impl FromStr for DataSource {
164164
path => {
165165
let path = PathBuf::from(path);
166166
if path.is_dir() {
167-
Ok(Self::Prebuilt {
168-
path: PathBuf::from(path),
169-
})
167+
Ok(Self::Prebuilt { path })
170168
} else {
171169
Err(
172170
"--src must be a path to an existing directory, `in-tree` or `production`"
@@ -201,7 +199,7 @@ fn main() {
201199
env.init();
202200

203201
if let Err(e) = run() {
204-
error!("{:?}", e);
202+
error!("{e:?}");
205203
std::process::exit(1);
206204
}
207205
}
@@ -257,7 +255,7 @@ fn run() -> Result<(), Error> {
257255
bail!("person already in the repo: {}", github_name);
258256
}
259257

260-
let file = format!("people/{}.toml", github_name);
258+
let file = format!("people/{github_name}.toml");
261259
std::fs::write(
262260
&file,
263261
toml::to_string_pretty(&PersonToAdd {
@@ -278,7 +276,7 @@ fn run() -> Result<(), Error> {
278276
.as_bytes(),
279277
)?;
280278

281-
info!("written data to {}", file);
279+
info!("written data to {file}");
282280
}
283281
Cli::StaticApi { ref dest } => {
284282
let dest = PathBuf::from(dest);
@@ -312,7 +310,7 @@ fn run() -> Result<(), Error> {
312310
}
313311
}
314312
if let Email::Present(email) = person.email() {
315-
println!("email: {}", email);
313+
println!("email: {email}");
316314
}
317315
println!();
318316

@@ -352,7 +350,7 @@ fn run() -> Result<(), Error> {
352350
println!(" (none)");
353351
} else {
354352
for (repo, perms) in bors_permissions {
355-
println!(" - {}", repo);
353+
println!(" - {repo}");
356354
if perms.review() {
357355
println!(" - review");
358356
}
@@ -373,7 +371,7 @@ fn run() -> Result<(), Error> {
373371
println!(" (none)");
374372
} else {
375373
for key in other_permissions {
376-
println!(" - {}", key);
374+
println!(" - {key}");
377375
}
378376
}
379377
}
@@ -399,7 +397,7 @@ fn run() -> Result<(), Error> {
399397
}
400398
println!("{} ({}):", team.name(), team.kind());
401399
if let Some(parent) = team.subteam_of() {
402-
println!(" parent team: {}", parent);
400+
println!(" parent team: {parent}");
403401
}
404402

405403
println!(" members: ");
@@ -418,7 +416,7 @@ fn run() -> Result<(), Error> {
418416
let mut emails = list.emails().iter().collect::<Vec<_>>();
419417
emails.sort();
420418
for email in emails {
421-
println!("{}", email);
419+
println!("{email}");
422420
}
423421
}
424422
Cli::DumpWebsite => {
@@ -456,7 +454,7 @@ fn run() -> Result<(), Error> {
456454
.collect::<Vec<_>>();
457455
allowed.sort_unstable();
458456
for github_username in &allowed {
459-
println!("{}", github_username);
457+
println!("{github_username}");
460458
}
461459
}
462460
Cli::DumpIndividualAccess { group_by } => {
@@ -526,9 +524,9 @@ fn run() -> Result<(), Error> {
526524
Cli::Sync(opts) => {
527525
if let Err(err) = perform_sync(opts, data) {
528526
// Display shows just the first element of the chain.
529-
error!("failed: {}", err);
527+
error!("failed: {err}");
530528
for cause in err.chain().skip(1) {
531-
error!("caused by: {}", cause);
529+
error!("caused by: {cause}");
532530
}
533531
std::process::exit(1);
534532
}

src/permissions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl Permissions {
4747
result.push(boolean.to_string());
4848
}
4949
for repo in config.permissions_bors_repos() {
50-
result.push(format!("bors.{}.review", repo));
51-
result.push(format!("bors.{}.try", repo));
50+
result.push(format!("bors.{repo}.review"));
51+
result.push(format!("bors.{repo}.try"));
5252
}
5353

5454
result

src/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Person {
9696
}
9797
}
9898

99-
pub(crate) fn email(&self) -> Email {
99+
pub(crate) fn email(&self) -> Email<'_> {
100100
match &self.email {
101101
EmailField::Disabled(false) => Email::Disabled,
102102
EmailField::Disabled(true) => Email::Missing,
@@ -674,7 +674,7 @@ impl WebsiteData {
674674
self.repo.as_deref()
675675
}
676676

677-
pub(crate) fn discord(&self) -> Option<DiscordInvite> {
677+
pub(crate) fn discord(&self) -> Option<DiscordInvite<'_>> {
678678
if let (Some(url), Some(channel)) = (&self.discord_invite, &self.discord_name) {
679679
Some(DiscordInvite {
680680
url: url.as_ref(),

src/static_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'a> Generator<'a> {
485485
where
486486
T: serde::Serialize + serde::de::DeserializeOwned + PartialEq,
487487
{
488-
info!("writing API object {}...", path);
488+
info!("writing API object {path}...");
489489
let json = serde_json::to_string_pretty(obj)?;
490490
self.write(path, json.as_bytes())?;
491491

0 commit comments

Comments
 (0)