diff options
author | Keiichi Watanabe <keiichiw@chromium.org> | 2020-04-10 21:49:10 +0900 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-04-15 18:01:32 +0000 |
commit | 275c1ef45db270b9cf0d7c614e5bdf59cb91bb41 (patch) | |
tree | 493e9898931f777d6158bd77a7b926b0351c2a85 | |
parent | 6eb0ca94aca6f2bd3f3c028ae8d8fb9bd00f5b67 (diff) | |
download | crosvm-275c1ef45db270b9cf0d7c614e5bdf59cb91bb41.tar crosvm-275c1ef45db270b9cf0d7c614e5bdf59cb91bb41.tar.gz crosvm-275c1ef45db270b9cf0d7c614e5bdf59cb91bb41.tar.bz2 crosvm-275c1ef45db270b9cf0d7c614e5bdf59cb91bb41.tar.lz crosvm-275c1ef45db270b9cf0d7c614e5bdf59cb91bb41.tar.xz crosvm-275c1ef45db270b9cf0d7c614e5bdf59cb91bb41.tar.zst crosvm-275c1ef45db270b9cf0d7c614e5bdf59cb91bb41.zip |
crosvm: Apply cargo fix for some clippy errors
Executed the following command to fix trivial style problems automatically. $ rustup run nightly cargo fix -Z unstable-options --clippy \ --all-features --all-targets BUG=chromium:908640 TEST=build Change-Id: I8a42806dc573b25d4ca918112e7b420793261d37 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145537 Tested-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
-rw-r--r-- | src/argument.rs | 10 | ||||
-rw-r--r-- | src/linux.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 44 | ||||
-rw-r--r-- | tests/plugins.rs | 2 |
4 files changed, 28 insertions, 30 deletions
diff --git a/src/argument.rs b/src/argument.rs index 9c00ae5..02e97f0 100644 --- a/src/argument.rs +++ b/src/argument.rs @@ -292,14 +292,12 @@ where State::Positional } State::Value { name } => { - if arg.starts_with("-") { + if arg.starts_with('-') { arg_consumed = false; f(&name, None)?; - } else { - if let Err(e) = f(&name, Some(&arg)) { - arg_consumed = false; - f(&name, None).map_err(|_| e)?; - } + } else if let Err(e) = f(&name, Some(&arg)) { + arg_consumed = false; + f(&name, None).map_err(|_| e)?; } State::Top } diff --git a/src/linux.rs b/src/linux.rs index a5af858..c469e0c 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -1398,7 +1398,7 @@ fn run_vcpu( // implementation accomplishes that. let _scoped_exit_evt = ScopedEvent::from(exit_evt); - if vcpu_affinity.len() != 0 { + if !vcpu_affinity.is_empty() { if let Err(e) = set_cpu_affinity(vcpu_affinity) { error!("Failed to set CPU affinity: {}", e); } diff --git a/src/main.rs b/src/main.rs index 6900099..bab9adc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ fn parse_cpu_set(s: &str) -> argument::Result<Vec<usize>> { let mut cpuset = Vec::new(); for part in s.split(',') { let range: Vec<&str> = part.split('-').collect(); - if range.len() == 0 || range.len() > 2 { + if range.is_empty() || range.len() > 2 { return Err(argument::Error::InvalidValue { value: part.to_owned(), expected: String::from("invalid list syntax"), @@ -120,8 +120,8 @@ fn parse_gpu_options(s: Option<&str>) -> argument::Result<GpuParameters> { if let Some(s) = s { let opts = s - .split(",") - .map(|frag| frag.split("=")) + .split(',') + .map(|frag| frag.split('=')) .map(|mut kv| (kv.next().unwrap_or(""), kv.next().unwrap_or(""))); for (k, v) in opts { @@ -255,8 +255,8 @@ fn parse_ac97_options(s: &str) -> argument::Result<Ac97Parameters> { let mut ac97_params: Ac97Parameters = Default::default(); let opts = s - .split(",") - .map(|frag| frag.split("=")) + .split(',') + .map(|frag| frag.split('=')) .map(|mut kv| (kv.next().unwrap_or(""), kv.next().unwrap_or(""))); for (k, v) in opts { @@ -276,7 +276,7 @@ fn parse_ac97_options(s: &str) -> argument::Result<Ac97Parameters> { } "capture_effects" => { ac97_params.capture_effects = v - .split("|") + .split('|') .map(|val| { val.parse::<StreamEffect>() .map_err(|e| argument::Error::InvalidValue { @@ -308,8 +308,8 @@ fn parse_serial_options(s: &str) -> argument::Result<SerialParameters> { }; let opts = s - .split(",") - .map(|frag| frag.split("=")) + .split(',') + .map(|frag| frag.split('=')) .map(|mut kv| (kv.next().unwrap_or(""), kv.next().unwrap_or(""))); for (k, v) in opts { @@ -358,7 +358,7 @@ fn parse_serial_options(s: &str) -> argument::Result<SerialParameters> { } fn parse_plugin_mount_option(value: &str) -> argument::Result<BindMount> { - let components: Vec<&str> = value.split(":").collect(); + let components: Vec<&str> = value.split(':').collect(); if components.is_empty() || components.len() > 3 || components[0].is_empty() { return Err(argument::Error::InvalidValue { value: value.to_owned(), @@ -405,7 +405,7 @@ fn parse_plugin_mount_option(value: &str) -> argument::Result<BindMount> { } fn parse_plugin_gid_map_option(value: &str) -> argument::Result<GidMap> { - let components: Vec<&str> = value.split(":").collect(); + let components: Vec<&str> = value.split(':').collect(); if components.is_empty() || components.len() > 3 || components[0].is_empty() { return Err(argument::Error::InvalidValue { value: value.to_owned(), @@ -504,7 +504,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: ) } "cpu-affinity" => { - if cfg.vcpu_affinity.len() != 0 { + if !cfg.vcpu_affinity.is_empty() { return Err(argument::Error::TooManyArguments( "`cpu-affinity` already given".to_owned(), )); @@ -1033,7 +1033,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: let reader = BufReader::new(file); for l in reader.lines() { let line = l.unwrap(); - let trimmed_line = line.splitn(2, '#').nth(0).unwrap().trim(); + let trimmed_line = line.splitn(2, '#').next().unwrap().trim(); if !trimmed_line.is_empty() { let mount = parse_plugin_mount_option(trimmed_line)?; cfg.plugin_mounts.push(mount); @@ -1052,7 +1052,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: let reader = BufReader::new(file); for l in reader.lines() { let line = l.unwrap(); - let trimmed_line = line.splitn(2, '#').nth(0).unwrap().trim(); + let trimmed_line = line.splitn(2, '#').next().unwrap().trim(); if !trimmed_line.is_empty() { let map = parse_plugin_gid_map_option(trimmed_line)?; cfg.plugin_gid_maps.push(map); @@ -1087,7 +1087,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: "`single-touch` already given".to_owned(), )); } - let mut it = value.unwrap().split(":"); + let mut it = value.unwrap().split(':'); let mut single_touch_spec = TouchDeviceOption::new(PathBuf::from(it.next().unwrap().to_owned())); @@ -1105,7 +1105,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: "`trackpad` already given".to_owned(), )); } - let mut it = value.unwrap().split(":"); + let mut it = value.unwrap().split(':'); let mut trackpad_spec = TouchDeviceOption::new(PathBuf::from(it.next().unwrap().to_owned())); @@ -1462,7 +1462,7 @@ fn balloon_vms(mut args: std::env::Args) -> std::result::Result<(), ()> { println!("Set the ballon size of the crosvm instance to `SIZE` bytes."); return Err(()); } - let num_bytes = match args.nth(0).unwrap().parse::<u64>() { + let num_bytes = match args.next().unwrap().parse::<u64>() { Ok(n) => n, Err(_) => { error!("Failed to parse number of bytes"); @@ -1533,7 +1533,7 @@ fn create_qcow2(args: std::env::Args) -> std::result::Result<(), ()> { .map_err(|e| { error!("Unable to parse command line arguments: {}", e); })?; - if file_path.len() == 0 || !(size.is_some() ^ backing_file.is_some()) { + if file_path.is_empty() || !(size.is_some() ^ backing_file.is_some()) { print_help("crosvm create_qcow2", "PATH [SIZE]", &arguments); println!( "Create a new QCOW2 image at `PATH` of either the specified `SIZE` in bytes or @@ -1574,11 +1574,11 @@ fn disk_cmd(mut args: std::env::Args) -> std::result::Result<(), ()> { println!(" resize DISK_INDEX NEW_SIZE VM_SOCKET"); return Err(()); } - let subcommand: &str = &args.nth(0).unwrap(); + let subcommand: &str = &args.next().unwrap(); let request = match subcommand { "resize" => { - let disk_index = match args.nth(0).unwrap().parse::<usize>() { + let disk_index = match args.next().unwrap().parse::<usize>() { Ok(n) => n, Err(_) => { error!("Failed to parse disk index"); @@ -1586,7 +1586,7 @@ fn disk_cmd(mut args: std::env::Args) -> std::result::Result<(), ()> { } }; - let new_size = match args.nth(0).unwrap().parse::<u64>() { + let new_size = match args.next().unwrap().parse::<u64>() { Ok(n) => n, Err(_) => { error!("Failed to parse disk size"); @@ -1648,7 +1648,7 @@ type ModifyUsbResult<T> = std::result::Result<T, ModifyUsbError>; fn parse_bus_id_addr(v: &str) -> ModifyUsbResult<(u8, u8, u16, u16)> { debug!("parse_bus_id_addr: {}", v); - let mut ids = v.split(":"); + let mut ids = v.split(':'); match (ids.next(), ids.next(), ids.next(), ids.next()) { (Some(bus_id), Some(addr), Some(vid), Some(pid)) => { let bus_id = bus_id @@ -1803,7 +1803,7 @@ fn pkg_version() -> std::result::Result<(), ()> { print!("crosvm {}", VERSION.unwrap_or("UNKNOWN")); match PKG_VERSION { Some(v) => println!("-{}", v), - None => println!(""), + None => println!(), } Ok(()) } diff --git a/tests/plugins.rs b/tests/plugins.rs index c45096f..1675a75 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -75,7 +75,7 @@ fn build_plugin(src: &str) -> RemovePath { let status = child.wait().expect("failed to wait for compiler"); assert!(status.success(), "failed to build plugin"); - RemovePath(PathBuf::from(out_bin)) + RemovePath(out_bin) } fn run_plugin(bin_path: &Path, with_sandbox: bool) { |