Skip to content
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

fix clippy lints and other minor improvements #688

Merged
merged 19 commits into from
Aug 8, 2024
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"ofborg",
"ofborg-simple-build"
]
resolver = "2"

[profile.release]
debug = true
Expand Down
2 changes: 1 addition & 1 deletion ofborg-simple-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ofborg-simple-build"
version = "0.1.0"
authors = ["Daiderd Jordan <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
ofborg = { path = "../ofborg" }
Expand Down
2 changes: 1 addition & 1 deletion ofborg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "ofborg"
version = "0.1.9"
authors = ["Graham Christensen <[email protected]>"]
build = "build.rs"
edition = "2018"
edition = "2021"

[dependencies]
async-std = { version = "=1.12.0", features = ["unstable", "tokio1"] }
Expand Down
12 changes: 6 additions & 6 deletions ofborg/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl MetricType {
let fields: Vec<String> = event
.fields
.iter()
.map(|&(ref _fieldname, ref fieldtype)| fieldtype.clone())
.map(|(_fieldname, fieldtype)| fieldtype.clone())
.collect();

fields
Expand Down Expand Up @@ -94,7 +94,7 @@ impl MetricType {
let fields: Vec<String> = event
.fields
.iter()
.map(|&(ref fieldname, ref _fieldtype)| fieldname.clone())
.map(|(fieldname, _fieldtype)| fieldname.clone())
.collect();

fields
Expand Down Expand Up @@ -352,7 +352,7 @@ fn events() -> Vec<MetricType> {
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("events.rs");
let mut f = File::create(&dest_path).unwrap();
let mut f = File::create(dest_path).unwrap();

println!("cargo:rerun-if-changed=build.rs");

Expand Down Expand Up @@ -427,7 +427,7 @@ pub struct MetricCollector {
let fields_str = {
let s = fields.join(", ");
if fields.len() > 1 {
format!("({})", s)
format!("({s})")
} else {
s
}
Expand Down Expand Up @@ -476,7 +476,7 @@ impl MetricCollector {

let mut index_fields = index_names.join(", ");
if index_names.len() > 1 {
index_fields = format!("({})", index_fields);
index_fields = format!("({index_fields})");
}

format!(
Expand Down Expand Up @@ -526,7 +526,7 @@ impl MetricCollector {

let key_value_pairs: Vec<String> = index_fields
.iter()
.map(|name| format!(" format!(\"{}=\\\"{{}}\\\"\", {})", &name, &name))
.map(|name| format!(" format!(\"{name}=\\\"{{}}\\\"\", {name})",))
.collect();
format!(
"
Expand Down
16 changes: 8 additions & 8 deletions ofborg/src/asynccmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ mod tests {
let mut spawned = acmd.spawn();
let lines: Vec<String> = spawned.lines().collect();
assert_eq!(lines, vec!["hi"]);
let ret = spawned.wait().unwrap().success();
assert_eq!(true, ret);
let exit_status = spawned.wait().unwrap();
assert!(exit_status.success());
}

#[test]
Expand All @@ -234,8 +234,8 @@ mod tests {
let mut spawned = acmd.spawn();
let lines: Vec<String> = spawned.lines().collect();
assert_eq!(lines, vec!["stdout", "stderr", "stdout2", "stderr2"]);
let ret = spawned.wait().unwrap().success();
assert_eq!(true, ret);
let exit_status = spawned.wait().unwrap();
assert!(exit_status.success());
}

#[test]
Expand All @@ -250,7 +250,7 @@ mod tests {
assert_eq!(lines.len(), 20000);
let thread_result = spawned.wait();
let exit_status = thread_result.expect("Thread should exit correctly");
assert_eq!(true, exit_status.success());
assert!(exit_status.success());
}

#[test]
Expand All @@ -265,7 +265,7 @@ mod tests {
assert_eq!(lines.len(), 200000);
let thread_result = spawned.wait();
let exit_status = thread_result.expect("Thread should exit correctly");
assert_eq!(true, exit_status.success());
assert!(exit_status.success());
}

#[test]
Expand All @@ -285,7 +285,7 @@ mod tests {
lines,
vec!["hi", "Non-UTF8 data omitted from the log.", "there"]
);
let ret = spawned.wait().unwrap().success();
assert_eq!(true, ret);
let exit_status = spawned.wait().unwrap();
assert!(exit_status.success());
}
}
2 changes: 1 addition & 1 deletion ofborg/src/bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn create_handle(
})?;

let queue_name = if cfg.runner.build_all_jobs != Some(true) {
let queue_name = format!("build-inputs-{}", system);
let queue_name = format!("build-inputs-{system}");
chan.declare_queue(easyamqp::QueueConfig {
queue: queue_name.clone(),
passive: false,
Expand Down
12 changes: 6 additions & 6 deletions ofborg/src/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl CachedCloner {

let mut new_root = self.root.clone();
new_root.push("repo");
new_root.push(format!("{:x}", md5::compute(&name)));
new_root.push(format!("{:x}", md5::compute(name)));

CachedProject {
root: new_root,
Expand Down Expand Up @@ -101,7 +101,7 @@ impl CachedProjectCo {
let result = Command::new("git")
.arg("fetch")
.arg("origin")
.arg(format!("+refs/pull/{}/head:pr", pr_id))
.arg(format!("+refs/pull/{pr_id}/head:pr"))
.current_dir(self.clone_to())
.stdout(Stdio::null())
.status()?;
Expand Down Expand Up @@ -162,7 +162,7 @@ impl CachedProjectCo {
let result = Command::new("git")
.arg("log")
.arg("--format=format:%s")
.arg(format!("HEAD..{}", commit))
.arg(format!("HEAD..{commit}"))
.current_dir(self.clone_to())
.output()?;

Expand All @@ -187,7 +187,7 @@ impl CachedProjectCo {
let result = Command::new("git")
.arg("diff")
.arg("--name-only")
.arg(format!("HEAD...{}", commit))
.arg(format!("HEAD...{commit}"))
.current_dir(self.clone_to())
.output()?;

Expand Down Expand Up @@ -278,8 +278,8 @@ mod tests {
.expect("building the test PR failed");

let stderr =
String::from_utf8(output.stderr).unwrap_or_else(|err| format!("warning: {}", err));
println!("{}", stderr);
String::from_utf8(output.stderr).unwrap_or_else(|err| format!("warning: {err}"));
println!("{stderr}");

let hash = String::from_utf8(output.stdout).expect("Should just be a hash");
return hash.trim().to_owned();
Expand Down
56 changes: 31 additions & 25 deletions ofborg/src/maintainers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ impl ImpactedMaintainers {
) -> Result<ImpactedMaintainers, CalculationError> {
let mut path_file = NamedTempFile::new()?;
let pathstr = serde_json::to_string(&paths)?;
write!(path_file, "{}", pathstr)?;
write!(path_file, "{pathstr}")?;

let mut attr_file = NamedTempFile::new()?;
let attrstr = serde_json::to_string(&attributes)?;
write!(attr_file, "{}", attrstr)?;
write!(attr_file, "{attrstr}")?;

let mut argstrs: HashMap<&str, &str> = HashMap::new();
argstrs.insert("changedattrsjson", attr_file.path().to_str().unwrap());
Expand All @@ -78,10 +78,10 @@ impl ImpactedMaintainers {
Ok(serde_json::from_str(&String::from_utf8(ret.stdout)?)?)
}

pub fn maintainers(&self) -> Vec<String> {
pub fn maintainers(&self) -> Vec<&str> {
self.0
.iter()
.map(|(maintainer, _)| maintainer.0.clone())
.keys()
.map(|Maintainer(name)| name.as_str())
.collect()
}

Expand All @@ -93,7 +93,7 @@ impl ImpactedMaintainers {
bypkg
.0
.entry(package.clone())
.or_insert_with(HashSet::new)
.or_default()
.insert(maintainer.clone());
}
}
Expand All @@ -104,23 +104,29 @@ impl ImpactedMaintainers {

impl std::fmt::Display for ImpactedMaintainers {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let d = self
.0
.iter()
.map(|(maintainer, packages)| {
format!(
"{}: {}",
maintainer.0,
packages
.iter()
.map(|pkg| pkg.0.clone())
.collect::<Vec<String>>()
.join(", ")
)
})
.collect::<Vec<String>>()
.join("\n");
write!(f, "{}", d)
let mut is_first = true;
for (Maintainer(maintainer), packages) in &self.0 {
if is_first {
is_first = false;
} else {
f.write_str("\n")?;
}

f.write_fmt(format_args!("{maintainer}"))?;

let (first, rest) = {
let mut packages = packages.iter();
(packages.next(), packages)
};
if let Some(Package(package)) = first {
f.write_fmt(format_args!(": {package}"))?;

for Package(package) in rest {
f.write_fmt(format_args!(", {package}"))?;
}
}
}
Ok(())
}
}

Expand Down Expand Up @@ -156,8 +162,8 @@ mod tests {
.expect("building the test PR failed");

let stderr =
String::from_utf8(output.stderr).unwrap_or_else(|err| format!("warning: {}", err));
println!("{}", stderr);
String::from_utf8(output.stderr).unwrap_or_else(|err| format!("warning: {err}"));
println!("{stderr}");

let hash = String::from_utf8(output.stdout).expect("Should just be a hash");
return hash.trim().to_owned();
Expand Down
2 changes: 1 addition & 1 deletion ofborg/src/message/buildjob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl BuildJob {
statusreport: Option<ExchangeQueue>,
request_id: String,
) -> BuildJob {
let logbackrk = format!("{}.{}", repo.full_name, pr.number).to_lowercase();
let logbackrk = format!("{}.{}", repo.full_name.to_lowercase(), pr.number);

BuildJob {
repo,
Expand Down
2 changes: 1 addition & 1 deletion ofborg/src/message/buildresult.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl From<BuildStatus> for String {
BuildStatus::Failure => "Failure".into(),
BuildStatus::HashMismatch => "A fixed output derivation's hash was incorrect".into(),
BuildStatus::TimedOut => "Timed out, unknown build status".into(),
BuildStatus::UnexpectedError { ref err } => format!("Unexpected error: {}", err),
BuildStatus::UnexpectedError { ref err } => format!("Unexpected error: {err}"),
}
}
}
Expand Down
Loading
Loading