Skip to content

Commit

Permalink
Fix lints for Rust 1.84 (#638)
Browse files Browse the repository at this point in the history
The biggest two here are changing `map_or(false,` to `is_some_and` or
`is_ok_and`, and the changing of rules around how refs in patterns work
(which is technically a future-compat lint, but its easy enough to take
now), but there's also some elided lifetimes and other general cleanups.
  • Loading branch information
smalis-msft authored Jan 9, 2025
1 parent 483db84 commit 8d9d904
Show file tree
Hide file tree
Showing 51 changed files with 89 additions and 85 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,21 @@ rust-2024-compatibility = { level = "warn", priority = -1 }
edition_2024_expr_fragment_specifier = "allow"
impl_trait_overcaptures = "allow"
deprecated-safe-2024 = "allow"
tail-expr-drop-order = "allow"
if-let-rescope = "allow"

unused_qualifications = "warn"

# Code that needs unsafe should opt-in via a module-scoped allow.
unsafe_code = "deny"
unsafe_op_in_unsafe_fn = "forbid"

# TODO: Needed for xshell compatibility, fixed in v0.2.7
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(trick_rust_analyzer_into_highlighting_interpolated_bits)'] }

# TODO: Remove when we update to Rust 1.84, needed for if-let-rescope
unknown_lints = "allow"

[workspace.lints.clippy]
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
Expand Down
2 changes: 1 addition & 1 deletion openhcl/openhcl_boot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ fn validate_vp_hw_ids(partition_info: &PartitionInfo) {
if let Some((i, &vp_index)) = vp_indexes
.iter()
.enumerate()
.find(|(i, &vp_index)| *i as u32 != vp_index)
.find(|&(i, vp_index)| i as u32 != *vp_index)
{
panic!(
"CPU hardware ID {:#x} does not correspond to VP index {}",
Expand Down
2 changes: 1 addition & 1 deletion openhcl/sidecar_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl<'a> SidecarVp<'a> {
match &mut *vp {
VpState::Stopped => unreachable!(),
VpState::Running(waker) => {
if !waker.as_ref().map_or(false, |w| cx.waker().will_wake(w)) {
if waker.as_ref().is_none_or(|w| !cx.waker().will_wake(w)) {
*waker = Some(cx.waker().clone());
}
Poll::Pending
Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_confidentiality/src/getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static CONFIDENTIAL: OnceLock<bool> = OnceLock::new();
static CONFIDENTIAL_DEBUG: OnceLock<bool> = OnceLock::new();

fn get_bool_env_var(name: &str) -> bool {
std::env::var_os(name).map_or(false, |v| !v.is_empty() && v != "0")
std::env::var_os(name).is_some_and(|v| !v.is_empty() && v != "0")
}

/// Gets whether the current VM is a confidential VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ pub(crate) async fn handle_vtl2_config_rpc(
}
}

pub async fn disk_from_disk_type<'a>(
pub async fn disk_from_disk_type(
disk_type: Resource<DiskHandleKind>,
read_only: bool,
resolver: &ResourceResolver,
Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_core/src/get_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl GetTracingBackend {

/// Enables tracing output to the tracing task and to stderr.
pub fn init_tracing(spawn: impl Spawn, tracer: RemoteTracer) -> anyhow::Result<()> {
if legacy_openvmm_env("OPENVMM_DISABLE_TRACING_RATELIMITS").map_or(false, |v| !v.is_empty()) {
if legacy_openvmm_env("OPENVMM_DISABLE_TRACING_RATELIMITS").is_ok_and(|v| !v.is_empty()) {
tracelimit::disable_rate_limiting(true);
}

Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_core/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Options {

fn parse_bool(value: Option<&OsString>) -> bool {
value
.map(|v| v.to_ascii_lowercase() == "true" || v == "1")
.map(|v| v.eq_ignore_ascii_case("true") || v == "1")
.unwrap_or_default()
}

Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_crash/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Options {
);

let verbose_var = std::env::var("UNDERHILL_CRASH_VERBOSE").unwrap_or_default();
let verbose = verbose_var == "1" || verbose_var.to_ascii_lowercase() == "true";
let verbose = verbose_var == "1" || verbose_var.eq_ignore_ascii_case("true");

Self {
pid,
Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_dump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn main() -> ! {
pub fn do_main() -> anyhow::Result<()> {
let mut args = std::env::args().skip(1).peekable();

let level = if args.peek().map_or(false, |x| x == "-v") {
let level = if args.peek().is_some_and(|x| x == "-v") {
args.next();
Level::DEBUG
} else {
Expand Down
2 changes: 1 addition & 1 deletion openhcl/virt_mshv_vtl/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ impl<'p, T: Backing> Processor for UhProcessor<'p, T> {
// Ensure the waker is set.
if !last_waker
.as_ref()
.map_or(false, |waker| cx.waker().will_wake(waker))
.is_some_and(|waker| cx.waker().will_wake(waker))
{
last_waker = Some(cx.waker().clone());
self.inner.waker.write().clone_from(&last_waker);
Expand Down
6 changes: 3 additions & 3 deletions openvmm/openvmm_entry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,9 +1329,9 @@ fn cleanup_socket(path: &Path) {
#[cfg(windows)]
let is_socket = pal::windows::fs::is_unix_socket(path).unwrap_or(false);
#[cfg(not(windows))]
let is_socket = path.metadata().map_or(false, |meta| {
std::os::unix::fs::FileTypeExt::is_socket(&meta.file_type())
});
let is_socket = path
.metadata()
.is_ok_and(|meta| std::os::unix::fs::FileTypeExt::is_socket(&meta.file_type()));

if is_socket {
let _ = std::fs::remove_file(path);
Expand Down
2 changes: 1 addition & 1 deletion openvmm/openvmm_entry/src/tracing_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn enable_tracing() -> anyhow::Result<()> {
.add_directive(base.parse().unwrap())
};

if legacy_openvmm_env("OPENVMM_DISABLE_TRACING_RATELIMITS").map_or(false, |v| !v.is_empty()) {
if legacy_openvmm_env("OPENVMM_DISABLE_TRACING_RATELIMITS").is_ok_and(|v| !v.is_empty()) {
tracelimit::disable_rate_limiting(true);
}

Expand Down
2 changes: 1 addition & 1 deletion support/cache_topology/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mod linux {
.file_name()
.unwrap()
.to_str()
.map_or(false, |s| s.starts_with("index"))
.is_some_and(|s| s.starts_with("index"))
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion support/console_relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn choose_terminal_apps(app: Option<&Path>) -> Vec<App<'_>> {

let mut apps = Vec::new();

let env_set = |key| std::env::var_os(key).map_or(false, |x| !x.is_empty());
let env_set = |key| std::env::var_os(key).is_some_and(|x| !x.is_empty());

// If we're running in tmux, use tmux.
if env_set("TMUX") {
Expand Down
6 changes: 3 additions & 3 deletions support/inspect_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn parse_attr_list<T: Parse>(input: ParseStream<'_>) -> syn::Result<Punctuated<A
fn parse_attrs<T: Parse>(attrs: &[Attribute]) -> syn::Result<Vec<Attr<T>>> {
let mut idents = Vec::new();
for attr in attrs {
if !attr.path().get_ident().map_or(false, |x| x == "inspect") {
if attr.path().get_ident().is_none_or(|x| x != "inspect") {
continue;
}
let attrs = attr.parse_args_with(parse_attr_list)?;
Expand All @@ -276,7 +276,7 @@ fn parse_attrs<T: Parse>(attrs: &[Attribute]) -> syn::Result<Vec<Attr<T>>> {
/// Parses a `bitfield(u32)` style attribute, returning the bitfield type.
fn parse_bitfield_attr(attrs: &[Attribute]) -> syn::Result<Option<Ident>> {
for attr in attrs {
if attr.path().get_ident().map_or(false, |x| x == "bitfield") {
if attr.path().get_ident().is_some_and(|x| x == "bitfield") {
return Ok(Some(attr.parse_args()?));
}
}
Expand Down Expand Up @@ -403,7 +403,7 @@ fn fields_response(
&& field
.ident
.as_ref()
.map_or(false, |id| id.to_string().starts_with('_'));
.is_some_and(|id| id.to_string().starts_with('_'));

(!skip).then(|| {
let ident = field.ident.as_ref().map_or_else(
Expand Down
2 changes: 1 addition & 1 deletion support/mesh/mesh_channel_core/src/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl ReceiverCore {
if !local
.waker
.as_ref()
.map_or(false, |waker| waker.will_wake(cx.waker()))
.is_some_and(|waker| waker.will_wake(cx.waker()))
&& !this.is_closed()
{
local.waker = Some(cx.waker().clone());
Expand Down
2 changes: 1 addition & 1 deletion support/mesh/mesh_node/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod debug {

pub fn next(&self) -> Option<Uuid> {
CHECK_ONCE.call_once(|| {
if std::env::var_os("__MESH_UNSAFE_DEBUG_IDS__").map_or(false, |x| !x.is_empty()) {
if std::env::var_os("__MESH_UNSAFE_DEBUG_IDS__").is_some_and(|x| !x.is_empty()) {
tracing::error!("using unsafe debugging mesh IDs--this mesh could be compromised by external callers");
USE_LINEAR_IDS.store(true, Ordering::Relaxed);
}
Expand Down
4 changes: 2 additions & 2 deletions support/mesh/mesh_protobuf/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ impl<T, R, E: FieldEncode<T, R>> FieldEncode<Vec<T>, R> for VecField<E> {
// Other packed sequences may still get a bytes value at runtime, but
// they also support non-packed encodings and so must be wrapped when
// they're nested in another sequence.
let bytes = E::packed().map_or(false, |p| p.must_pack());
let bytes = E::packed().is_some_and(|p| p.must_pack());
!bytes
}
}
Expand Down Expand Up @@ -1116,7 +1116,7 @@ impl<'a, T, R, E: FieldDecode<'a, T, R>> FieldDecode<'a, Vec<T>, R> for VecField
// Other packed sequences may still get a bytes value at runtime, but
// they also support non-packed encodings and so must be wrapped when
// they're nested in another sequence.
let bytes = E::packed::<Vec<T>>().map_or(false, |p| p.must_pack());
let bytes = E::packed::<Vec<T>>().is_some_and(|p| p.must_pack());
!bytes
}
}
Expand Down
4 changes: 2 additions & 2 deletions support/mesh/mesh_protobuf/src/protofile/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a> DescriptorWriter<'a> {
let mut n = 0;
while descriptors
.peek()
.map_or(false, |d| d.package == first.package)
.is_some_and(|d| d.package == first.package)
{
let desc = descriptors.next().unwrap();
desc.message.collect_imports(&mut writer, &mut imports)?;
Expand Down Expand Up @@ -376,7 +376,7 @@ impl FieldDescriptor<'_> {
.collect::<Vec<_>>();
let fields = fields
.iter()
.map(|(&ty, number, name)| FieldDescriptor::new("", ty, name.as_ref(), *number))
.map(|&(ty, number, ref name)| FieldDescriptor::new("", *ty, name.as_ref(), number))
.collect::<Vec<_>>();
MessageDescriptor::new(&self.name.to_upper_camel_case(), "", &fields, &[], &[]).fmt(w)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion support/openssl_kdf/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ParamsBuilder {
// Data is allocated by the openssl allocator, so assumed in a memory stable realm.
// It's important the data does not move from the time we create the "output" slice and the
// moment it's read by the EVP_KDF_CTX_set_params functions.
for (name, ref mut p) in &mut params.fixed {
for (name, p) in &mut params.fixed {
use Param::*;
// SAFETY: Name is guaranteed to be a valid C string, and the bufs are only constructed by alloc_slice_inner,
// which makes sure they are valid and have correct lengths.
Expand Down
2 changes: 1 addition & 1 deletion support/pal/pal_async/src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl PollInterestSet {
if !interest
.waker
.as_ref()
.map_or(false, |w| w.will_wake(cx.waker()))
.is_some_and(|w| w.will_wake(cx.waker()))
{
interest.waker = Some(cx.waker().clone());
}
Expand Down
2 changes: 1 addition & 1 deletion support/pal/pal_async/src/multi_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<const N: usize> Inner<N> {
/// Sets the waker for index `i`.
fn set(&self, i: usize, waker: &Waker) {
let mut wakers = self.wakers.lock();
if !wakers[i].as_ref().map_or(false, |old| old.will_wake(waker)) {
if !wakers[i].as_ref().is_some_and(|old| old.will_wake(waker)) {
let _old = wakers[i].replace(waker.clone());
drop(wakers);
}
Expand Down
2 changes: 1 addition & 1 deletion support/pal/pal_async/src/windows/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl State {
if !entry
.waker
.as_ref()
.map_or(false, |old| old.will_wake(cx.waker()))
.is_some_and(|old| old.will_wake(cx.waker()))
{
entry.waker = Some(cx.waker().clone());
}
Expand Down
11 changes: 6 additions & 5 deletions support/task_control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ impl<T: AsyncRun<S>, S> PollReady for StopTaskInner<'_, T, S> {
if !shared.calls.is_empty() || shared.stop {
return Poll::Ready(());
}
if !shared
if shared
.inner_waker
.as_ref()
.map_or(false, |waker| cx.waker().will_wake(waker))
.is_none_or(|waker| !cx.waker().will_wake(waker))
{
shared.inner_waker = Some(cx.waker().clone());
}
Expand Down Expand Up @@ -468,9 +468,10 @@ impl<T: AsyncRun<S>, S: 'static + Send> TaskControl<T, S> {
loop {
let (mut task_and_state, stop) = poll_fn(|cx| {
let mut shared = shared.lock();
let has_work = shared.task_and_state.as_ref().map_or(false, |ts| {
!shared.calls.is_empty() || (!shared.stop && !ts.done)
});
let has_work = shared
.task_and_state
.as_ref()
.is_some_and(|ts| !shared.calls.is_empty() || (!shared.stop && !ts.done));
if !has_work {
shared.inner_waker = Some(cx.waker().clone());
return Poll::Pending;
Expand Down
4 changes: 2 additions & 2 deletions support/uevent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl UeventListener {
|| (kvs.get("RESIZE") == Some("1")
&& kvs.get("SUBSYSTEM") == Some("block")
&& kvs.get("ACTION") == Some("change")
&& kvs.get("MAJOR").map_or(false, |x| x.parse() == Ok(major))
&& kvs.get("MINOR").map_or(false, |x| x.parse() == Ok(minor)))
&& kvs.get("MAJOR").is_some_and(|x| x.parse() == Ok(major))
&& kvs.get("MINOR").is_some_and(|x| x.parse() == Ok(minor)))
{
notify();
}
Expand Down
2 changes: 1 addition & 1 deletion vm/devices/chipset/src/i8042/ps2mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ mod save_restore {
type SavedState = state::SavedState;

fn save(&mut self) -> Result<Self::SavedState, SaveError> {
let Self { ref output_buffer } = self;
let Self { output_buffer } = self;

let saved_state = state::SavedState {
output_buffer: output_buffer.iter().copied().collect(),
Expand Down
5 changes: 1 addition & 4 deletions vm/devices/serial/serial_core/src/serial_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ impl<T: SerialIo + Unpin> IoDetacher<T> {

impl<T: SerialIo + Unpin> SerialIo for DetachableIo<T> {
fn is_connected(&self) -> bool {
self.inner
.lock()
.as_ref()
.map_or(false, |s| s.is_connected())
self.inner.lock().as_ref().is_some_and(|s| s.is_connected())
}

fn poll_connect(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Expand Down
2 changes: 1 addition & 1 deletion vm/devices/storage/disk_layered/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Bitmap {
.filter_map(move |bits| {
let start = n;
n += bits.len();
if bits.first().map_or(false, |&x| !x) {
if bits.first().is_some_and(|&x| !x) {
Some(SectorBitmapRange {
bits,
start_sector: sector + start as u64,
Expand Down
2 changes: 1 addition & 1 deletion vm/devices/storage/disk_nvme/nvme_driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl<T: DeviceBacking> NvmeDriver<T> {
.per_cpu
.iter()
.enumerate()
.filter(|&(cpu, c)| c.get().map_or(false, |c| c.cpu != cpu as u32))
.filter(|&(cpu, c)| c.get().is_some_and(|c| c.cpu != cpu as u32))
.count()
}

Expand Down
2 changes: 1 addition & 1 deletion vm/devices/support/fs/lxutil/src/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub fn dos_to_nt_path(
let path = if root.is_none() {
// Windows has legacy behavior where specifying just a drive letter will return the last path on that drive
// from the current cmd.exe instance. This is likely not the intended behavior and is generally not safe.
if path.as_os_str().len() == 2 && path.to_str().map_or(false, |s| s.ends_with(':')) {
if path.as_os_str().len() == 2 && path.to_str().is_some_and(|s| s.ends_with(':')) {
windows::dos_to_nt_path(path.join("\\"))?
} else {
windows::dos_to_nt_path(path)?
Expand Down
6 changes: 2 additions & 4 deletions vm/devices/virtio/virtio_p9/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct VirtioPlan9Device {
impl VirtioPlan9Device {
pub fn new(tag: &str, fs: Plan9FileSystem, memory: GuestMemory) -> VirtioPlan9Device {
// The tag uses the same format as 9p protocol strings (2 byte length followed by string).
let length = tag.as_bytes().len() + size_of::<u16>();
let length = tag.len() + size_of::<u16>();

// Round the length up to a multiple of 4 to make the read function simpler.
let length = (length + 3) & !3;
Expand All @@ -38,9 +38,7 @@ impl VirtioPlan9Device {
{
use std::io::Write;
let mut cursor = std::io::Cursor::new(&mut tag_buffer);
cursor
.write_all(&(tag.as_bytes().len() as u16).to_le_bytes())
.unwrap();
cursor.write_all(&(tag.len() as u16).to_le_bytes()).unwrap();
cursor.write_all(tag.as_bytes()).unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion vm/devices/virtio/virtiofs/src/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl VirtioFsDevice {
};

// Copy the tag into the config space (truncate it for now if too long).
let length = std::cmp::min(tag.as_bytes().len(), config.tag.len());
let length = std::cmp::min(tag.len(), config.tag.len());
config.tag[..length].copy_from_slice(&tag.as_bytes()[..length]);

Self {
Expand Down
4 changes: 2 additions & 2 deletions vm/devices/vmbus/vmbus_ring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ pub fn inspect_ring<M: RingMem>(mem: M, req: inspect::Request<'_>) {
/// Returns whether a ring buffer is in a state where the receiving end might
/// need a signal.
pub fn reader_needs_signal<M: RingMem>(mem: M) -> bool {
InnerRing::new(mem).map_or(false, |ring| {
InnerRing::new(mem).is_ok_and(|ring| {
let control = ring.control();
control.interrupt_mask().load(Ordering::Relaxed) == 0
&& (control.inp().load(Ordering::Relaxed) != control.outp().load(Ordering::Relaxed))
Expand All @@ -1165,7 +1165,7 @@ pub fn reader_needs_signal<M: RingMem>(mem: M) -> bool {
/// Returns whether a ring buffer is in a state where the sending end might need
/// a signal.
pub fn writer_needs_signal<M: RingMem>(mem: M) -> bool {
InnerRing::new(mem).map_or(false, |ring| {
InnerRing::new(mem).is_ok_and(|ring| {
let control = ring.control();
let pending_size = control.pending_send_size().load(Ordering::Relaxed);
pending_size != 0
Expand Down
Loading

0 comments on commit 8d9d904

Please sign in to comment.