From b27e34916ca7c9fd75856c3eba6e42a66f82f1fb Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 7 Jun 2024 12:39:04 -0700 Subject: [PATCH] Fix clippy::thread_local_initializer_can_be_made_const BUG=b:344974550 TEST=tools/clippy Change-Id: I9875f910fbe3ac249e8f855a7b806e77347fb6d6 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5609077 Reviewed-by: Alexandre Courbot Commit-Queue: Daniel Verkamp --- devices/src/virtio/fs/passthrough.rs | 2 +- devices/src/virtio/vhost/user/device/net.rs | 2 +- kvm/src/lib.rs | 2 +- src/crosvm/sys/linux/vcpu.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/devices/src/virtio/fs/passthrough.rs b/devices/src/virtio/fs/passthrough.rs index cc581100a8..5d62bfe906 100644 --- a/devices/src/virtio/fs/passthrough.rs +++ b/devices/src/virtio/fs/passthrough.rs @@ -354,7 +354,7 @@ fn set_creds( ScopedGid::new(gid, oldgid).and_then(|gid| Ok((ScopedUid::new(uid, olduid)?, gid))) } -thread_local!(static THREAD_FSCREATE: RefCell> = RefCell::new(None)); +thread_local!(static THREAD_FSCREATE: RefCell> = const { RefCell::new(None) }); // Opens and returns a write-only handle to /proc/thread-self/attr/fscreate. Panics if it fails to // open the file. diff --git a/devices/src/virtio/vhost/user/device/net.rs b/devices/src/virtio/vhost/user/device/net.rs index 1ed1e06b2d..8df6c41e77 100644 --- a/devices/src/virtio/vhost/user/device/net.rs +++ b/devices/src/virtio/vhost/user/device/net.rs @@ -40,7 +40,7 @@ use crate::virtio::Interrupt; use crate::virtio::Queue; thread_local! { - pub(crate) static NET_EXECUTOR: OnceCell = OnceCell::new(); + pub(crate) static NET_EXECUTOR: OnceCell = const { OnceCell::new() }; } // TODO(b/188947559): Come up with better way to include these constants. Compiler errors happen diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index 6a0284b87d..f38b487841 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -1033,7 +1033,7 @@ pub struct VcpuThread { signal_num: Option, } -thread_local!(static VCPU_THREAD: RefCell> = RefCell::new(None)); +thread_local!(static VCPU_THREAD: RefCell> = const { RefCell::new(None) }); impl Vcpu { /// Constructs a new VCPU for `vm`. diff --git a/src/crosvm/sys/linux/vcpu.rs b/src/crosvm/sys/linux/vcpu.rs index 4a80280ade..718e49133b 100644 --- a/src/crosvm/sys/linux/vcpu.rs +++ b/src/crosvm/sys/linux/vcpu.rs @@ -168,7 +168,7 @@ where Ok(vcpu) } -thread_local!(static VCPU_THREAD: RefCell> = RefCell::new(None)); +thread_local!(static VCPU_THREAD: RefCell> = const { RefCell::new(None) }); fn set_vcpu_thread_local(vcpu: Option<&dyn VcpuArch>, signal_num: c_int) { // Block signal while we add -- if a signal fires (very unlikely,