build: Fix beta clippy issue (useless_vec)

warning: useless use of `vec!`
   --> test_infra/src/lib.rs:111:30
    |
111 |             let mut events = vec![epoll::Event::new(epoll::Events::empty(), 0); 1];
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[epoll::Event::new(epoll::Events::empty(), 0); 1]`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec
    = note: `#[warn(clippy::useless_vec)]` on by default

Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
This commit is contained in:
Yu Li 2023-07-12 12:25:25 +08:00 committed by Bo Chen
parent aac614e2ec
commit d0dbc7fb4d
4 changed files with 18 additions and 20 deletions

View File

@ -799,7 +799,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_cpus() { fn test_valid_vm_config_cpus() {
vec![ [
( (
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
@ -917,7 +917,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_kernel() { fn test_valid_vm_config_kernel() {
vec![( [(
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"], vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"],
r#"{ r#"{
"payload": {"kernel": "/path/to/kernel"} "payload": {"kernel": "/path/to/kernel"}
@ -932,7 +932,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_cmdline() { fn test_valid_vm_config_cmdline() {
vec![( [(
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
"--kernel", "--kernel",
@ -953,7 +953,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_disks() { fn test_valid_vm_config_disks() {
vec![ [
( (
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
@ -1227,7 +1227,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_rng() { fn test_valid_vm_config_rng() {
vec![( [(
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
"--kernel", "--kernel",
@ -1249,8 +1249,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_fs() { fn test_valid_vm_config_fs() {
vec![ [(
(
vec![ vec![
"cloud-hypervisor", "--kernel", "/path/to/kernel", "cloud-hypervisor", "--kernel", "/path/to/kernel",
"--memory", "shared=true", "--memory", "shared=true",
@ -1320,8 +1319,7 @@ mod unit_tests {
] ]
}"#, }"#,
true, true,
), )]
]
.iter() .iter()
.for_each(|(cli, openapi, equal)| { .for_each(|(cli, openapi, equal)| {
compare_vm_config_cli_vs_json(cli, openapi, *equal); compare_vm_config_cli_vs_json(cli, openapi, *equal);
@ -1330,7 +1328,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_pmem() { fn test_valid_vm_config_pmem() {
vec![ [
( (
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
@ -1394,7 +1392,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_serial_console() { fn test_valid_vm_config_serial_console() {
vec![ [
( (
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"], vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"],
r#"{ r#"{
@ -1445,7 +1443,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_serial_pty_console_pty() { fn test_valid_vm_config_serial_pty_console_pty() {
vec![ [
( (
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"], vec!["cloud-hypervisor", "--kernel", "/path/to/kernel"],
r#"{ r#"{
@ -1593,7 +1591,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_vdpa() { fn test_valid_vm_config_vdpa() {
vec![ [
( (
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
@ -1640,7 +1638,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_vsock() { fn test_valid_vm_config_vsock() {
vec![ [
( (
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
@ -1723,7 +1721,7 @@ mod unit_tests {
#[test] #[test]
fn test_valid_vm_config_tpm_socket() { fn test_valid_vm_config_tpm_socket() {
vec![( [(
vec![ vec![
"cloud-hypervisor", "cloud-hypervisor",
"--kernel", "--kernel",

View File

@ -108,7 +108,7 @@ impl GuestNetworkConfig {
epoll::Event::new(epoll::Events::EPOLLIN, 0), epoll::Event::new(epoll::Events::EPOLLIN, 0),
) )
.expect("Cannot add 'tcp_listener' event to epoll"); .expect("Cannot add 'tcp_listener' event to epoll");
let mut events = vec![epoll::Event::new(epoll::Events::empty(), 0); 1]; let mut events = [epoll::Event::new(epoll::Events::empty(), 0); 1];
loop { loop {
let num_events = match epoll::wait(epoll_fd, timeout * 1000_i32, &mut events[..]) { let num_events = match epoll::wait(epoll_fd, timeout * 1000_i32, &mut events[..]) {
Ok(num_events) => Ok(num_events), Ok(num_events) => Ok(num_events),
@ -252,7 +252,7 @@ impl DiskConfig for UbuntuDiskConfig {
.join("ubuntu") .join("ubuntu")
.join("ci"); .join("ci");
vec!["meta-data"].iter().for_each(|x| { ["meta-data"].iter().for_each(|x| {
rate_limited_copy(source_file_dir.join(x), cloud_init_directory.join(x)) rate_limited_copy(source_file_dir.join(x), cloud_init_directory.join(x))
.expect("Expect copying cloud-init meta-data to succeed"); .expect("Expect copying cloud-init meta-data to succeed");
}); });
@ -308,7 +308,7 @@ impl DiskConfig for UbuntuDiskConfig {
.output() .output()
.expect("Expect creating disk image to succeed"); .expect("Expect creating disk image to succeed");
vec!["user-data", "meta-data", "network-config"] ["user-data", "meta-data", "network-config"]
.iter() .iter()
.for_each(|x| { .for_each(|x| {
std::process::Command::new("mcopy") std::process::Command::new("mcopy")

View File

@ -971,7 +971,7 @@ mod tests {
self.init_pkt(local_port, peer_port, uapi::VSOCK_OP_RESPONSE); self.init_pkt(local_port, peer_port, uapi::VSOCK_OP_RESPONSE);
self.send(); self.send();
let mut buf = vec![0u8; 32]; let mut buf = [0u8; 32];
let len = stream.read(&mut buf[..]).unwrap(); let len = stream.read(&mut buf[..]).unwrap();
assert_eq!(&buf[..len], format!("OK {local_port}\n").as_bytes()); assert_eq!(&buf[..len], format!("OK {local_port}\n").as_bytes());

View File

@ -229,7 +229,7 @@ impl SerialManager {
const EPOLL_EVENTS_LEN: usize = 3; const EPOLL_EVENTS_LEN: usize = 3;
let mut events = let mut events =
vec![epoll::Event::new(epoll::Events::empty(), 0); EPOLL_EVENTS_LEN]; [epoll::Event::new(epoll::Events::empty(), 0); EPOLL_EVENTS_LEN];
loop { loop {
let num_events = match epoll::wait(epoll_fd, timeout, &mut events[..]) { let num_events = match epoll::wait(epoll_fd, timeout, &mut events[..]) {