From 62c1c01acc529e0d8472d873694c8935202a4505 Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Fri, 19 Nov 2021 12:01:31 -0800 Subject: [PATCH] switch to 2021 edition of Rust (#21) Make 2 changes that are not strictly required but make sense given the changes in the 2021 edition: 1. TryFrom/TryInto no longer need to be imported, as they are part of the standard prelude. Remove the redundant `use` statements. 2. When possible, closures capture members of local variables, rather than the entire variable. This can cause the non-captured members to be dropped later than in the 2018 edition. In our case (in ZettaCache::open()), this doesn't really matter, but it brought to my attention that we're cloning and then discarding a bunch of the members of ZettaCache (without using them). So I changed this to just clone the few members that are actually needed by the closures. --- cmd/zfs_object_agent/client/Cargo.toml | 2 +- cmd/zfs_object_agent/object_perf/Cargo.toml | 4 ++-- cmd/zfs_object_agent/object_perf/src/s3perf.rs | 1 - cmd/zfs_object_agent/server/Cargo.toml | 2 +- cmd/zfs_object_agent/util/Cargo.toml | 2 +- cmd/zfs_object_agent/util/src/from64.rs | 2 -- cmd/zfs_object_agent/zcdb/Cargo.toml | 4 ++-- cmd/zfs_object_agent/zettacache/Cargo.toml | 2 +- cmd/zfs_object_agent/zettacache/src/block_access.rs | 2 -- .../zettacache/src/block_allocator.rs | 1 - cmd/zfs_object_agent/zettacache/src/zettacache.rs | 12 ++++++------ cmd/zfs_object_agent/zettaobject/Cargo.toml | 2 +- cmd/zfs_object_agent/zettaobject/src/data_object.rs | 1 - .../zettaobject/src/object_access.rs | 1 - cmd/zfs_object_agent/zettaobject/src/pool.rs | 1 - cmd/zfs_object_agent/zoa/Cargo.toml | 2 +- 16 files changed, 16 insertions(+), 25 deletions(-) diff --git a/cmd/zfs_object_agent/client/Cargo.toml b/cmd/zfs_object_agent/client/Cargo.toml index ee9e9337c554..8bc3d9b5a5e9 100644 --- a/cmd/zfs_object_agent/client/Cargo.toml +++ b/cmd/zfs_object_agent/client/Cargo.toml @@ -2,7 +2,7 @@ name = "zoa_test" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/cmd/zfs_object_agent/object_perf/Cargo.toml b/cmd/zfs_object_agent/object_perf/Cargo.toml index e72759342513..e592d1000ad5 100644 --- a/cmd/zfs_object_agent/object_perf/Cargo.toml +++ b/cmd/zfs_object_agent/object_perf/Cargo.toml @@ -2,7 +2,7 @@ name = "zfs_object_perf" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -15,4 +15,4 @@ futures = "0.3.16" serde = { version = "1.0.125", features = ["derive"] } uuid = {version = "0.8"} tokio = { version = "1.4", features = ["full"] } -zettaobject = { path = "../zettaobject" } \ No newline at end of file +zettaobject = { path = "../zettaobject" } diff --git a/cmd/zfs_object_agent/object_perf/src/s3perf.rs b/cmd/zfs_object_agent/object_perf/src/s3perf.rs index 5e8fc7350352..c6ffc1fdb7a3 100644 --- a/cmd/zfs_object_agent/object_perf/src/s3perf.rs +++ b/cmd/zfs_object_agent/object_perf/src/s3perf.rs @@ -6,7 +6,6 @@ use metered::hdr_histogram::AtomicHdrHistogram; use metered::metered; use metered::time_source::StdInstantMicros; use std::cmp::max; -use std::convert::TryInto; use std::error::Error; use std::string::String; use std::sync::Arc; diff --git a/cmd/zfs_object_agent/server/Cargo.toml b/cmd/zfs_object_agent/server/Cargo.toml index 055b2d65dfa7..cab7fb80218c 100644 --- a/cmd/zfs_object_agent/server/Cargo.toml +++ b/cmd/zfs_object_agent/server/Cargo.toml @@ -2,7 +2,7 @@ name = "zfs_object_agent" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/cmd/zfs_object_agent/util/Cargo.toml b/cmd/zfs_object_agent/util/Cargo.toml index 7227cfab215d..81352bf82325 100644 --- a/cmd/zfs_object_agent/util/Cargo.toml +++ b/cmd/zfs_object_agent/util/Cargo.toml @@ -2,7 +2,7 @@ name = "util" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/cmd/zfs_object_agent/util/src/from64.rs b/cmd/zfs_object_agent/util/src/from64.rs index 2dca4a7ed4e2..ba72ee665f3d 100644 --- a/cmd/zfs_object_agent/util/src/from64.rs +++ b/cmd/zfs_object_agent/util/src/from64.rs @@ -1,5 +1,3 @@ -use std::convert::TryInto; - /// Conversions that are safe assuming that we are on LP64 (usize == u64) pub trait From64 { fn from64(a: A) -> Self; diff --git a/cmd/zfs_object_agent/zcdb/Cargo.toml b/cmd/zfs_object_agent/zcdb/Cargo.toml index 059f903875d5..8cbcdaf65776 100644 --- a/cmd/zfs_object_agent/zcdb/Cargo.toml +++ b/cmd/zfs_object_agent/zcdb/Cargo.toml @@ -2,7 +2,7 @@ name = "zcachedb" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -12,4 +12,4 @@ git-version = "0.3.5" libc = "0.2" log = "0.4" tokio = { version = "1.4", features = ["full"] } -zettacache = { path = "../zettacache" } \ No newline at end of file +zettacache = { path = "../zettacache" } diff --git a/cmd/zfs_object_agent/zettacache/Cargo.toml b/cmd/zfs_object_agent/zettacache/Cargo.toml index d1c7a4fa4a34..3ecfe2b590e5 100644 --- a/cmd/zfs_object_agent/zettacache/Cargo.toml +++ b/cmd/zfs_object_agent/zettacache/Cargo.toml @@ -2,7 +2,7 @@ name = "zettacache" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/cmd/zfs_object_agent/zettacache/src/block_access.rs b/cmd/zfs_object_agent/zettacache/src/block_access.rs index 7c55339e698c..f7f2ee239d24 100644 --- a/cmd/zfs_object_agent/zettacache/src/block_access.rs +++ b/cmd/zfs_object_agent/zettacache/src/block_access.rs @@ -15,8 +15,6 @@ use num::Num; use num::NumCast; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; -use std::convert::TryFrom; -use std::convert::TryInto; use std::io::Read; use std::io::Write; use std::os::unix::prelude::AsRawFd; diff --git a/cmd/zfs_object_agent/zettacache/src/block_allocator.rs b/cmd/zfs_object_agent/zettacache/src/block_allocator.rs index 9d1f289025c9..197d89f618e9 100644 --- a/cmd/zfs_object_agent/zettacache/src/block_allocator.rs +++ b/cmd/zfs_object_agent/zettacache/src/block_allocator.rs @@ -10,7 +10,6 @@ use roaring::RoaringBitmap; use serde::{Deserialize, Serialize}; use std::cmp::{self, min}; use std::collections::{BTreeMap, BTreeSet, HashSet}; -use std::convert::TryFrom; use std::ops::Bound::*; use std::sync::Arc; use std::time::Instant; diff --git a/cmd/zfs_object_agent/zettacache/src/zettacache.rs b/cmd/zfs_object_agent/zettacache/src/zettacache.rs index 78f00295a631..07d507c52ea1 100644 --- a/cmd/zfs_object_agent/zettacache/src/zettacache.rs +++ b/cmd/zfs_object_agent/zettacache/src/zettacache.rs @@ -27,7 +27,6 @@ use more_asserts::*; use serde::{Deserialize, Serialize}; use std::collections::btree_map; use std::collections::BTreeMap; -use std::convert::TryFrom; use std::ops::Bound::{Excluded, Unbounded}; use std::pin::Pin; use std::sync::Arc; @@ -685,17 +684,18 @@ impl ZettaCache { my_cache.checkpoint_task(merge_rx, merge_index).await; }); - let my_cache = this.clone(); + let state = this.state.clone(); + let metrics = this.metrics.clone(); tokio::spawn(async move { let mut interval = tokio::time::interval(Duration::from_secs(10)); loop { interval.tick().await; - debug!("metrics: {:#?}", my_cache.metrics); - my_cache.state.lock().await.block_access.dump_metrics(); + debug!("metrics: {:#?}", metrics); + state.lock().await.block_access.dump_metrics(); } }); - let my_cache = this.clone(); + let state = this.state.clone(); tokio::spawn(async move { // XXX maybe we should bump the atime after a set number of // accesses, so each histogram bucket starts with the same count. @@ -704,7 +704,7 @@ impl ZettaCache { let mut interval = tokio::time::interval(Duration::from_secs(10)); loop { interval.tick().await; - let mut state = my_cache.state.lock().await; + let mut state = state.lock().await; state.atime = state.atime.next(); } }); diff --git a/cmd/zfs_object_agent/zettaobject/Cargo.toml b/cmd/zfs_object_agent/zettaobject/Cargo.toml index 55ce5f260668..27027e521a9e 100644 --- a/cmd/zfs_object_agent/zettaobject/Cargo.toml +++ b/cmd/zfs_object_agent/zettaobject/Cargo.toml @@ -2,7 +2,7 @@ name = "zettaobject" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/cmd/zfs_object_agent/zettaobject/src/data_object.rs b/cmd/zfs_object_agent/zettaobject/src/data_object.rs index f560405621ee..b4c90a8c46b5 100644 --- a/cmd/zfs_object_agent/zettaobject/src/data_object.rs +++ b/cmd/zfs_object_agent/zettaobject/src/data_object.rs @@ -6,7 +6,6 @@ use log::*; use more_asserts::*; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::convert::{TryFrom, TryInto}; use std::fmt; use std::fmt::Display; use std::time::Instant; diff --git a/cmd/zfs_object_agent/zettaobject/src/object_access.rs b/cmd/zfs_object_agent/zettaobject/src/object_access.rs index 16ee9e7fa5f2..b138e4ee7f9c 100644 --- a/cmd/zfs_object_agent/zettaobject/src/object_access.rs +++ b/cmd/zfs_object_agent/zettaobject/src/object_access.rs @@ -22,7 +22,6 @@ use rusoto_s3::{ ListObjectsV2Request, ObjectIdentifier, PutObjectError, PutObjectOutput, PutObjectRequest, S3Client, S3, }; -use std::convert::TryFrom; use std::error::Error; use std::fmt::Formatter; use std::iter; diff --git a/cmd/zfs_object_agent/zettaobject/src/pool.rs b/cmd/zfs_object_agent/zettaobject/src/pool.rs index 21798ad0aa97..4550eaa47142 100644 --- a/cmd/zfs_object_agent/zettaobject/src/pool.rs +++ b/cmd/zfs_object_agent/zettaobject/src/pool.rs @@ -38,7 +38,6 @@ use std::borrow::Borrow; use std::cmp::{max, min}; use std::collections::hash_map; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; -use std::convert::{TryFrom, TryInto}; use std::fmt; use std::fmt::Display; use std::mem; diff --git a/cmd/zfs_object_agent/zoa/Cargo.toml b/cmd/zfs_object_agent/zoa/Cargo.toml index 5a26b94fa210..55d5644c876e 100644 --- a/cmd/zfs_object_agent/zoa/Cargo.toml +++ b/cmd/zfs_object_agent/zoa/Cargo.toml @@ -2,7 +2,7 @@ name = "zoa" version = "0.1.0" authors = ["Delphix"] -edition = "2018" +edition = "2021" build = "src/build.rs" [build-dependencies]