Skip to content

Commit

Permalink
Merge pull request #9158 from habitat-sh/bump_rust
Browse files Browse the repository at this point in the history
bump rust to 1.75 and resolve clippy violations
  • Loading branch information
mwrock authored Jan 31, 2024
2 parents 4801645 + 6db2cba commit eef9586
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 49 deletions.
3 changes: 1 addition & 2 deletions components/butterfly/src/rumor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ mod storage {
/// * `RumorStore::list` (write)
pub fn insert_rsw(&self, rumor: R) -> bool {
let mut list = self.list.write();
let rumors = list.entry(String::from(rumor.key()))
.or_insert_with(HashMap::new);
let rumors = list.entry(String::from(rumor.key())).or_default();
let kind_ignored_count =
IGNORED_RUMOR_COUNT.with_label_values(&[&rumor.kind().to_string()]);
// Result reveals if there was a change so we can increment the counter if needed.
Expand Down
3 changes: 1 addition & 2 deletions components/butterfly/src/rumor/departure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ mod tests {
}

#[test]
#[should_panic(expected = "assertion failed")]
fn departures_with_different_member_ids_are_not_equal() {
let s1 = create_departure("mastodon");
let s2 = create_departure("limpbizkit");
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

// Order
Expand Down
9 changes: 3 additions & 6 deletions components/butterfly/src/rumor/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,29 +254,26 @@ mod tests {
}

#[test]
#[should_panic(expected = "assertion failed")]
fn services_with_different_member_ids_are_not_equal() {
let s1 = create_service("adam");
let s2 = create_service("shanku");
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

#[test]
#[should_panic(expected = "assertion failed")]
fn services_with_different_incarnations_are_not_equal() {
let s1 = create_service("adam");
let mut s2 = create_service("adam");
s2.incarnation = 1;
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

#[test]
#[should_panic(expected = "assertion failed")]
fn services_with_different_service_groups_are_not_equal() {
let s1 = create_service("adam");
let mut s2 = create_service("adam");
s2.service_group = ServiceGroup::from_str("adam.fragile").unwrap();
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

// Order
Expand Down
6 changes: 2 additions & 4 deletions components/butterfly/src/rumor/service_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,19 @@ mod tests {
}

#[test]
#[should_panic(expected = "assertion failed")]
fn service_configs_with_different_incarnations_are_not_equal() {
let s1 = create_service_config("adam", "yep");
let mut s2 = create_service_config("adam", "yep");
s2.incarnation = 1;
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

#[test]
#[should_panic(expected = "assertion failed")]
fn service_configs_with_different_service_groups_are_not_equal() {
let s1 = create_service_config("adam", "yep");
let mut s2 = create_service_config("adam", "yep");
s2.service_group = ServiceGroup::from_str("adam.fragile").unwrap();
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

// Order
Expand Down
6 changes: 2 additions & 4 deletions components/butterfly/src/rumor/service_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,19 @@ mod tests {
}

#[test]
#[should_panic(expected = "assertion failed")]
fn service_files_with_different_incarnations_are_not_equal() {
let s1 = create_service_file("adam", "yep", "tcp-backlog = 128");
let mut s2 = create_service_file("adam", "yep", "tcp-backlog = 128");
s2.incarnation = 1;
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

#[test]
#[should_panic(expected = "assertion failed")]
fn service_files_with_different_service_groups_are_not_equal() {
let s1 = create_service_file("adam", "yep", "tcp-backlog = 128");
let mut s2 = create_service_file("adam", "yep", "tcp-backlog = 128");
s2.service_group = ServiceGroup::from_str("adam.fragile").unwrap();
assert_eq!(s1, s2);
assert_ne!(s1, s2);
}

// Order
Expand Down
2 changes: 1 addition & 1 deletion components/common/src/package_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl PackageGraph {

for dep in deps {
let dep_idx = self.node_idx(dep);
self.graph.extend_with_edges(&[(idx, dep_idx)]);
self.graph.extend_with_edges([(idx, dep_idx)]);
}

assert_eq!(self.graph.node_count(), self.nodes.len());
Expand Down
6 changes: 3 additions & 3 deletions components/common/src/templating/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,9 +1094,9 @@ mod test {
fs::create_dir_all(&dir_a).expect("create dir_a");
fs::create_dir_all(&dir_c).expect("create dir_b and dir_c");

create_with_content(&dir_a.join("foo.txt"), "Hello world!");
create_with_content(&dir_b.join("bar.txt"), "Hello world!");
create_with_content(&dir_c.join("baz.txt"), "Hello world!");
create_with_content(dir_a.join("foo.txt"), "Hello world!");
create_with_content(dir_b.join("bar.txt"), "Hello world!");
create_with_content(dir_c.join("baz.txt"), "Hello world!");

let renderer = load_templates(&input_dir, &PathBuf::new(), TemplateRenderer::new())
.expect("visit config dirs");
Expand Down
3 changes: 1 addition & 2 deletions components/core/src/crypto/keys/ring_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::{crypto::{keys::NamedRevision,
/// Private module to re-export the various sodiumoxide concepts we
/// use, to keep them all consolidated and abstracted.
mod primitives {
pub use sodiumoxide::crypto::secretbox::{self,
gen_key,
pub use sodiumoxide::crypto::secretbox::{gen_key,
gen_nonce,
open,
seal,
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/crypto/keys/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod tests {
let key: SecretOriginSigningKey =
fixture_key("keys/origin-key-valid-20160509190508.sig.key");
let file_to_sign = fixture("signme.dat");
let signed_message = key.sign(&file_to_sign).unwrap();
let signed_message = key.sign(file_to_sign).unwrap();
let expected = SIGNED_SIGNME_DAT_BLAKE2B_HASH.to_vec();

assert_eq!(signed_message.len(), expected.len());
Expand Down
1 change: 1 addition & 0 deletions components/core/src/package/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl PartialOrd for PackageIdent {
/// * If the names are not equal, they cannot be compared.
/// * If the versions are greater/lesser, return that as the ordering.
/// * If the versions are equal, return the greater/lesser for the release.
#[allow(clippy::non_canonical_partial_ord_impl)]
fn partial_cmp(&self, other: &PackageIdent) -> Option<Ordering> {
if self.name != other.name {
return None;
Expand Down
12 changes: 5 additions & 7 deletions components/core/src/package/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,7 @@ impl PackageInstall {
paths.push(p);
}

let ordered_pkgs = self.load_deps()?
.into_iter()
.chain(self.load_tdeps()?.into_iter());
let ordered_pkgs = self.load_deps()?.into_iter().chain(self.load_tdeps()?);
for pkg in ordered_pkgs {
for p in pkg.paths()? {
if seen.contains(&p) {
Expand Down Expand Up @@ -1091,7 +1089,7 @@ mod test {
&pkg_install,
MetaFile::Path,
env::join_paths(
vec![
[
pkg_prefix_for(&pkg_install).join("bin"),
pkg_prefix_for(&other_pkg_install).join("bin"),
pkg_prefix_for(&other_pkg_install).join("sbin"),
Expand All @@ -1117,9 +1115,9 @@ mod test {
// Create `RUNTIME_ENVIROMENT` metafile which has path entries from another package to
// replicate certain older packages
let path_val =
env::join_paths(vec![pkg_prefix_for(&pkg_install).join("bin"),
pkg_prefix_for(&other_pkg_install).join("bin"),
pkg_prefix_for(&other_pkg_install).join("sbin"),].iter()).unwrap();
env::join_paths([pkg_prefix_for(&pkg_install).join("bin"),
pkg_prefix_for(&other_pkg_install).join("bin"),
pkg_prefix_for(&other_pkg_install).join("sbin")].iter()).unwrap();
write_metafile(&pkg_install,
MetaFile::RuntimeEnvironment,
&format!("PATH={}\n", path_val.to_string_lossy().as_ref()));
Expand Down
2 changes: 1 addition & 1 deletion components/hab/src/command/bldr/job/promote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub fn get_ident_list(ui: &mut UI,
let mut idents: Vec<String> =
group_status.projects
.iter()
.filter(|&p| p.state == "Success" && in_origin(&p.ident, origin))
.cloned()
.filter(|p| p.state == "Success" && in_origin(&p.ident, origin))
.map(|p| p.ident)
.collect();

Expand Down
2 changes: 1 addition & 1 deletion components/hab/src/command/studio/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const HAB_STUDIO_SECRET: &str = "HAB_STUDIO_SECRET_";

pub fn start_docker_studio(_ui: &mut UI, args: &[OsString]) -> Result<()> {
let mut args = args.to_vec();
if args.get(0) == Some(&OsString::from("rm")) {
if args.first() == Some(&OsString::from("rm")) {
return Err(Error::CannotRemoveDockerStudio);
}

Expand Down
3 changes: 1 addition & 2 deletions components/launcher/src/sys/windows/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ fn build_proc_table() -> ProcessTable {
let mut process_success: i32 = 1;
// Loop through all processes until we find one where `szExeFile` == `name`.
while process_success == 1 {
let children = table.entry(process_entry.th32ParentProcessID)
.or_insert_with(Vec::new);
let children = table.entry(process_entry.th32ParentProcessID).or_default();
(*children).push(process_entry.th32ProcessID);
process_success =
unsafe { tlhelp32::Process32NextW(processes_snap_handle, &mut process_entry) };
Expand Down
4 changes: 1 addition & 3 deletions components/sup/src/census.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,7 @@ impl CensusGroup {
self.changed_service_files.clear();
for (_m_id, service_file_rumor) in service_file_rumors.iter() {
let filename = service_file_rumor.filename.to_string();
let file = self.service_files
.entry(filename.clone())
.or_insert_with(ServiceFile::default);
let file = self.service_files.entry(filename.clone()).or_default();

if service_file_rumor.incarnation > file.incarnation {
match service_file_rumor.body(key_cache) {
Expand Down
4 changes: 2 additions & 2 deletions components/sup/src/manager/peer_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod tests {
lock.unset();
let mut members = peer_watcher_member_load_test(tmpdir.path(), &peer_lines).unwrap();

for mut member in &mut members {
for member in &mut members {
member.id = String::new();
}
let member1 = Member { id: String::new(),
Expand All @@ -237,7 +237,7 @@ mod tests {
lock.set("aarch64-darwin");
let mut members = peer_watcher_member_load_test(tmpdir.path(), &peer_lines).unwrap();
lock.unset();
for mut member in &mut members {
for member in &mut members {
member.id = String::new();
}
let member1 = Member { id: String::new(),
Expand Down
2 changes: 1 addition & 1 deletion components/sup/src/manager/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ impl From<&ServiceQueryModel> for habitat_sup_protocol::types::ServiceStatus {
}

#[cfg(test)]
#[cfg(any(all(target_os = "linux", any(target_arch = "x86_64")),
#[cfg(any(all(target_os = "linux", target_arch = "x86_64"),
all(target_os = "windows", target_arch = "x86_64"),))]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion components/sup/src/manager/service/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ fn read_pid<T>(pid_file: T) -> Option<Pid>
match reader.lines().next() {
Some(Ok(line)) => {
match line.parse::<Pid>() {
Ok(pid) if pid == 0 => {
Ok(0) => {
error!(target: "pidfile_tracing", "Read PID of 0 from {}!", p.display());
// Treat this the same as a corrupt pid
// file, because that's basically what it
Expand Down
3 changes: 1 addition & 2 deletions components/sup/src/sys/windows/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ fn build_proc_table() -> ProcessTable {
let mut process_success: i32 = 1;
// Loop through all processes until we find one where `szExeFile` == `name`.
while process_success == 1 {
let children = table.entry(process_entry.th32ParentProcessID)
.or_insert_with(Vec::new);
let children = table.entry(process_entry.th32ParentProcessID).or_default();
(*children).push(process_entry.th32ProcessID);
process_success =
unsafe { tlhelp32::Process32NextW(processes_snap_handle, &mut process_entry) };
Expand Down
4 changes: 1 addition & 3 deletions components/sup/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ pub mod test_sup;

// Re-export the key structs of this package for ergonomics.
pub use self::{fixture_root::FixtureRoot,
fs::{copy_dir,
setup_package_files,
FileSnapshot,
fs::{setup_package_files,
FileSystemSnapshot},
hab_root::HabRoot,
test_sup::TestSup};
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.68.2"
channel = "1.75.0"

0 comments on commit eef9586

Please sign in to comment.