warning_fix: fix warnings when build with cargo-1.68.0

Fixes: #6593

Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
alex.lyn 2023-04-26 19:18:49 +08:00
parent 509bc8b6c8
commit 17daeb9dd7
20 changed files with 91 additions and 75 deletions

View File

@ -417,10 +417,10 @@ impl Annotation {
match self.get_value::<u32>(KATA_ANNO_CONTAINER_RES_SWAPPINESS) { match self.get_value::<u32>(KATA_ANNO_CONTAINER_RES_SWAPPINESS) {
Ok(r) => { Ok(r) => {
if r.unwrap_or_default() > 100 { if r.unwrap_or_default() > 100 {
return Err(io::Error::new( Err(io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
format!("{} greater than 100", r.unwrap_or_default()), format!("{} greater than 100", r.unwrap_or_default()),
)); ))
} else { } else {
Ok(r) Ok(r)
} }

View File

@ -20,14 +20,9 @@ impl Empty {
} }
} }
impl Default for FSGroupChangePolicy { #[derive(Default, Debug, Clone, PartialEq)]
fn default() -> Self {
FSGroupChangePolicy::Always
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum FSGroupChangePolicy { pub enum FSGroupChangePolicy {
#[default]
Always = 0, Always = 0,
OnRootMismatch = 1, OnRootMismatch = 1,
} }
@ -65,18 +60,13 @@ pub struct Storage {
pub mount_point: String, pub mount_point: String,
} }
#[derive(Deserialize, Clone, PartialEq, Eq, Debug, Hash)] #[derive(Deserialize, Default, Clone, PartialEq, Eq, Debug, Hash)]
pub enum IPFamily { pub enum IPFamily {
#[default]
V4 = 0, V4 = 0,
V6 = 1, V6 = 1,
} }
impl ::std::default::Default for IPFamily {
fn default() -> Self {
IPFamily::V4
}
}
#[derive(Deserialize, Debug, PartialEq, Clone, Default)] #[derive(Deserialize, Debug, PartialEq, Clone, Default)]
pub struct IPAddress { pub struct IPAddress {
pub family: IPFamily, pub family: IPFamily,

View File

@ -42,7 +42,7 @@ impl CloudHypervisorInner {
match device { match device {
Device::ShareFsDevice(cfg) => self.handle_share_fs_device(cfg).await, Device::ShareFsDevice(cfg) => self.handle_share_fs_device(cfg).await,
Device::HybridVsock(cfg) => self.handle_hvsock_device(&cfg).await, Device::HybridVsock(cfg) => self.handle_hvsock_device(&cfg).await,
_ => return Err(anyhow!("unhandled device: {:?}", device)), _ => Err(anyhow!("unhandled device: {:?}", device)),
} }
} }

View File

@ -228,11 +228,9 @@ impl CloudHypervisorInner {
let join_handle = self.cloud_hypervisor_ping_until_ready(CH_POLL_TIME_MS); let join_handle = self.cloud_hypervisor_ping_until_ready(CH_POLL_TIME_MS);
let result = tokio::time::timeout(Duration::new(timeout_secs as u64, 0), join_handle) tokio::time::timeout(Duration::new(timeout_secs as u64, 0), join_handle)
.await .await
.context(timeout_msg)?; .context(timeout_msg)?
result
} }
async fn cloud_hypervisor_ensure_not_launched(&self) -> Result<()> { async fn cloud_hypervisor_ensure_not_launched(&self) -> Result<()> {

View File

@ -80,9 +80,7 @@ pub(crate) fn parse_ip(ip: &[u8], family: u8) -> Result<IpAddr> {
octets.copy_from_slice(&ip[..16]); octets.copy_from_slice(&ip[..16]);
Ok(IpAddr::V6(Ipv6Addr::from(octets))) Ok(IpAddr::V6(Ipv6Addr::from(octets)))
} }
_ => { _ => Err(anyhow!("unknown IP network family {}", family)),
return Err(anyhow!("unknown IP network family {}", family));
}
} }
} }

View File

@ -25,7 +25,7 @@ pub(crate) fn parse_mac(s: &str) -> Option<hypervisor::Address> {
pub(crate) fn get_mac_addr(b: &[u8]) -> Result<String> { pub(crate) fn get_mac_addr(b: &[u8]) -> Result<String> {
if b.len() != 6 { if b.len() != 6 {
return Err(anyhow!("invalid mac address {:?}", b)); Err(anyhow!("invalid mac address {:?}", b))
} else { } else {
Ok(format!( Ok(format!(
"{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",

View File

@ -79,7 +79,7 @@ impl RootFsResource {
.context("new share fs rootfs")?, .context("new share fs rootfs")?,
)) ))
} else { } else {
return Err(anyhow!("share fs is unavailable")); Err(anyhow!("share fs is unavailable"))
} }
} }
mounts_vec if is_single_layer_rootfs(mounts_vec) => { mounts_vec if is_single_layer_rootfs(mounts_vec) => {
@ -114,12 +114,10 @@ impl RootFsResource {
inner.rootfs.push(Arc::clone(&rootfs)); inner.rootfs.push(Arc::clone(&rootfs));
Ok(rootfs) Ok(rootfs)
} }
_ => { _ => Err(anyhow!(
return Err(anyhow!(
"unsupported rootfs mounts count {}", "unsupported rootfs mounts count {}",
rootfs_mounts.len() rootfs_mounts.len()
)) )),
}
} }
} }

View File

@ -397,12 +397,11 @@ fn load_config(spec: &oci::Spec, option: &Option<Vec<u8>>) -> Result<TomlConfig>
path path
} else if let Some(option) = option { } else if let Some(option) = option {
// get rid of the special characters in options to get the config path // get rid of the special characters in options to get the config path
let path = if option.len() > 2 { if option.len() > 2 {
from_utf8(&option[2..])?.to_string() from_utf8(&option[2..])?.to_string()
} else { } else {
String::from("") String::from("")
}; }
path
} else { } else {
String::from("") String::from("")
}; };

View File

@ -132,7 +132,7 @@ impl Process {
info!(self.logger, "run io copy for {}", io_name); info!(self.logger, "run io copy for {}", io_name);
let io_name = io_name.to_string(); let io_name = io_name.to_string();
let logger = self.logger.new(o!("io_name" => io_name)); let logger = self.logger.new(o!("io_name" => io_name));
let _ = tokio::spawn(async move { tokio::spawn(async move {
match tokio::io::copy(&mut reader, &mut writer).await { match tokio::io::copy(&mut reader, &mut writer).await {
Err(e) => { Err(e) => {
warn!(logger, "run_io_copy: failed to copy stream: {}", e); warn!(logger, "run_io_copy: failed to copy stream: {}", e);
@ -156,7 +156,7 @@ impl Process {
let exit_notifier = self.exit_watcher_tx.take(); let exit_notifier = self.exit_watcher_tx.take();
let status = self.status.clone(); let status = self.status.clone();
let _ = tokio::spawn(async move { tokio::spawn(async move {
// wait on all of the container's io stream terminated // wait on all of the container's io stream terminated
info!(logger, "begin wait group io"); info!(logger, "begin wait group io");
wg.wait().await; wg.wait().await;

View File

@ -47,7 +47,7 @@ impl HealthCheck {
let stop_rx = self.stop_rx.clone(); let stop_rx = self.stop_rx.clone();
let keep_abnormal = self.keep_abnormal; let keep_abnormal = self.keep_abnormal;
let _ = tokio::spawn(async move { tokio::spawn(async move {
let mut version_check_threshold_count = 0; let mut version_check_threshold_count = 0;
loop { loop {

View File

@ -285,7 +285,7 @@ impl Sandbox for VirtSandbox {
let agent = self.agent.clone(); let agent = self.agent.clone();
let sender = self.msg_sender.clone(); let sender = self.msg_sender.clone();
info!(sl!(), "oom watcher start"); info!(sl!(), "oom watcher start");
let _ = tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
match agent match agent
.get_oom_event(agent::Empty::new()) .get_oom_event(agent::Empty::new())

View File

@ -314,7 +314,7 @@ fn real_main() -> Result<()> {
Ok(()) Ok(())
} }
"connect" => connect(name, args), "connect" => connect(name, args),
_ => return Err(anyhow!(format!("invalid sub-command: {:?}", subcmd))), _ => Err(anyhow!(format!("invalid sub-command: {:?}", subcmd))),
} }
} }

View File

@ -225,7 +225,7 @@ mod arch_specific {
expected_param_value expected_param_value
); );
return Err(anyhow!("{} {}", error_msg, action_msg)); Err(anyhow!("{} {}", error_msg, action_msg))
} }
} }

View File

@ -326,9 +326,7 @@ fn setup_client(server_url: String, dbg_console_port: u32) -> anyhow::Result<Uni
vsock.setup_sock().context("set up vsock") vsock.setup_sock().context("set up vsock")
} }
// Others will be INVALID URI. // Others will be INVALID URI.
_ => { _ => Err(anyhow!("invalid URI scheme: {:?}", scheme)),
return Err(anyhow!("invalid URI scheme: {:?}", scheme));
}
} }
} }

View File

@ -162,7 +162,7 @@ pub fn get_sandbox_id_for_volume(volume_path: &str) -> Result<String> {
return Ok(String::from(file_name)); return Ok(String::from(file_name));
} }
return Err(anyhow!("no sandbox found for {}", volume_path)); Err(anyhow!("no sandbox found for {}", volume_path))
} }
#[cfg(test)] #[cfg(test)]

View File

@ -53,7 +53,7 @@ const UNKNOWN: &str = "unknown";
fn get_field_fn(line: &str, delimiter: &str, file_name: &str) -> Result<String> { fn get_field_fn(line: &str, delimiter: &str, file_name: &str) -> Result<String> {
let fields: Vec<&str> = line.split(delimiter).collect(); let fields: Vec<&str> = line.split(delimiter).collect();
if fields.len() < 2 { if fields.len() < 2 {
return Err(anyhow!("Unexpected file contents for {}", file_name)); Err(anyhow!("Unexpected file contents for {}", file_name))
} else { } else {
let val = fields[1].trim(); let val = fields[1].trim();
Ok(String::from(val)) Ok(String::from(val))

View File

@ -1303,9 +1303,16 @@ name = "protobuf"
version = "2.27.1" version = "2.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96"
[[package]]
name = "protobuf"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e"
dependencies = [ dependencies = [
"serde", "once_cell",
"serde_derive", "protobuf-support",
"thiserror",
] ]
[[package]] [[package]]
@ -1314,17 +1321,47 @@ version = "2.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.27.1",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure" name = "protobuf-codegen"
version = "2.27.1" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen", "once_cell",
"protobuf 3.2.0",
"protobuf-parse",
"regex",
"tempfile",
"thiserror",
]
[[package]]
name = "protobuf-parse"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49"
dependencies = [
"anyhow",
"indexmap",
"log",
"protobuf 3.2.0",
"protobuf-support",
"tempfile",
"thiserror",
"which",
]
[[package]]
name = "protobuf-support"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372"
dependencies = [
"thiserror",
] ]
[[package]] [[package]]
@ -1332,7 +1369,7 @@ name = "protocols"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"ttrpc", "ttrpc",
"ttrpc-codegen", "ttrpc-codegen",
] ]
@ -1530,7 +1567,7 @@ dependencies = [
"nix 0.24.2", "nix 0.24.2",
"oci", "oci",
"path-absolutize", "path-absolutize",
"protobuf", "protobuf 3.2.0",
"protocols", "protocols",
"regex", "regex",
"rlimit", "rlimit",
@ -1911,43 +1948,43 @@ dependencies = [
[[package]] [[package]]
name = "ttrpc" name = "ttrpc"
version = "0.6.1" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"libc", "libc",
"log", "log",
"nix 0.23.1", "nix 0.23.1",
"protobuf", "protobuf 3.2.0",
"protobuf-codegen-pure", "protobuf-codegen 3.2.0",
"thiserror", "thiserror",
] ]
[[package]] [[package]]
name = "ttrpc-codegen" name = "ttrpc-codegen"
version = "0.2.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.27.1",
"protobuf-codegen", "protobuf-codegen 3.2.0",
"protobuf-codegen-pure", "protobuf-support",
"ttrpc-compiler", "ttrpc-compiler",
] ]
[[package]] [[package]]
name = "ttrpc-compiler" name = "ttrpc-compiler"
version = "0.4.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2978ed3fa047d8fd55cbeb4d4a61d461fb3021a90c9618519c73ce7e5bb66c15" checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647"
dependencies = [ dependencies = [
"derive-new", "derive-new",
"prost", "prost",
"prost-build", "prost-build",
"prost-types", "prost-types",
"protobuf", "protobuf 2.27.1",
"protobuf-codegen", "protobuf-codegen 2.27.1",
"tempfile", "tempfile",
] ]

View File

@ -27,7 +27,7 @@ pub fn remove_cgroup_dir(cgroup: &cgroups::Cgroup) -> Result<()> {
retries -= 1; retries -= 1;
} }
return Err(anyhow!("failed to remove cgroups paths")); Err(anyhow!("failed to remove cgroups paths"))
} }
// Make sure we get a stable freezer state, so retry if the cgroup is still undergoing freezing. // Make sure we get a stable freezer state, so retry if the cgroup is still undergoing freezing.

View File

@ -66,9 +66,7 @@ async fn cmd_run(subcmd: SubCommand, root_path: &Path, logger: &Logger) -> Resul
CommonCmd::Ps(ps) => commands::ps::run(ps, root_path, logger), CommonCmd::Ps(ps) => commands::ps::run(ps, root_path, logger),
CommonCmd::Pause(pause) => commands::pause::run(pause, root_path, logger), CommonCmd::Pause(pause) => commands::pause::run(pause, root_path, logger),
CommonCmd::Resume(resume) => commands::resume::run(resume, root_path, logger), CommonCmd::Resume(resume) => commands::resume::run(resume, root_path, logger),
_ => { _ => Err(anyhow!("command is not implemented yet")),
return Err(anyhow!("command is not implemented yet"));
}
}, },
_ => unreachable!(), _ => unreachable!(),
} }

View File

@ -321,12 +321,12 @@ languages:
rust: rust:
description: "Rust language" description: "Rust language"
notes: "'version' is the default minimum version used by this project." notes: "'version' is the default minimum version used by this project."
version: "1.66.0" version: "1.68.0"
meta: meta:
description: | description: |
'newest-version' is the latest version known to work when 'newest-version' is the latest version known to work when
building Kata building Kata
newest-version: "1.66.0" newest-version: "1.68.0"
golangci-lint: golangci-lint:
description: "golangci-lint" description: "golangci-lint"