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) {
Ok(r) => {
if r.unwrap_or_default() > 100 {
return Err(io::Error::new(
Err(io::Error::new(
io::ErrorKind::InvalidData,
format!("{} greater than 100", r.unwrap_or_default()),
));
))
} else {
Ok(r)
}

View File

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

View File

@ -42,7 +42,7 @@ impl CloudHypervisorInner {
match device {
Device::ShareFsDevice(cfg) => self.handle_share_fs_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 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
.context(timeout_msg)?;
result
.context(timeout_msg)?
}
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]);
Ok(IpAddr::V6(Ipv6Addr::from(octets)))
}
_ => {
return Err(anyhow!("unknown IP network family {}", family));
}
_ => 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> {
if b.len() != 6 {
return Err(anyhow!("invalid mac address {:?}", b));
Err(anyhow!("invalid mac address {:?}", b))
} else {
Ok(format!(
"{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",

View File

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

View File

@ -397,12 +397,11 @@ fn load_config(spec: &oci::Spec, option: &Option<Vec<u8>>) -> Result<TomlConfig>
path
} else if let Some(option) = option {
// 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()
} else {
String::from("")
};
path
}
} else {
String::from("")
};

View File

@ -132,7 +132,7 @@ impl Process {
info!(self.logger, "run io copy for {}", io_name);
let io_name = io_name.to_string();
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 {
Err(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 status = self.status.clone();
let _ = tokio::spawn(async move {
tokio::spawn(async move {
// wait on all of the container's io stream terminated
info!(logger, "begin wait group io");
wg.wait().await;

View File

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

View File

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

View File

@ -314,7 +314,7 @@ fn real_main() -> Result<()> {
Ok(())
}
"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
);
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")
}
// Others will be INVALID URI.
_ => {
return Err(anyhow!("invalid URI scheme: {:?}", scheme));
}
_ => 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 Err(anyhow!("no sandbox found for {}", volume_path));
Err(anyhow!("no sandbox found for {}", volume_path))
}
#[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> {
let fields: Vec<&str> = line.split(delimiter).collect();
if fields.len() < 2 {
return Err(anyhow!("Unexpected file contents for {}", file_name));
Err(anyhow!("Unexpected file contents for {}", file_name))
} else {
let val = fields[1].trim();
Ok(String::from(val))

View File

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

View File

@ -27,7 +27,7 @@ pub fn remove_cgroup_dir(cgroup: &cgroups::Cgroup) -> Result<()> {
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.

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::Pause(pause) => commands::pause::run(pause, root_path, logger),
CommonCmd::Resume(resume) => commands::resume::run(resume, root_path, logger),
_ => {
return Err(anyhow!("command is not implemented yet"));
}
_ => Err(anyhow!("command is not implemented yet")),
},
_ => unreachable!(),
}

View File

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