Address lints in bevy_platform_support (#18477)

# Objective

@mockersf noticed there were some failing lints in
`bevy_platform_support`.

## Solution

Addressed the lints!

## Testing

- CI
This commit is contained in:
Zachary Harrold 2025-03-22 22:21:18 +11:00 committed by François Mockers
parent 39b1ffc905
commit 04a0a74157
7 changed files with 46 additions and 44 deletions

View File

@ -1,12 +1,12 @@
//! Provides `Barrier` and `BarrierWaitResult` //! Provides `Barrier` and `BarrierWaitResult`
pub use barrier::{Barrier, BarrierWaitResult}; pub use implementation::{Barrier, BarrierWaitResult};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as barrier; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod barrier { mod implementation {
use core::fmt; use core::fmt;
/// Fallback implementation of `Barrier` from the standard library. /// Fallback implementation of `Barrier` from the standard library.

View File

@ -1,11 +1,11 @@
//! Provides `LazyLock` //! Provides `LazyLock`
pub use lazy_lock::LazyLock; pub use implementation::LazyLock;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as lazy_lock; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod lazy_lock { mod implementation {
pub use spin::Lazy as LazyLock; pub use spin::Lazy as LazyLock;
} }

View File

@ -1,12 +1,12 @@
//! Provides `Mutex` and `MutexGuard` //! Provides `Mutex` and `MutexGuard`
pub use mutex::{Mutex, MutexGuard}; pub use implementation::{Mutex, MutexGuard};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as mutex; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod mutex { mod implementation {
use crate::sync::{LockResult, TryLockError, TryLockResult}; use crate::sync::{LockResult, TryLockError, TryLockResult};
use core::fmt; use core::fmt;
@ -81,7 +81,7 @@ mod mutex {
} }
} }
impl<T: ?Sized + Default> Default for Mutex<T> { impl<T: Default> Default for Mutex<T> {
fn default() -> Mutex<T> { fn default() -> Mutex<T> {
Mutex::new(Default::default()) Mutex::new(Default::default())
} }

View File

@ -1,12 +1,12 @@
//! Provides `Once`, `OnceState`, `OnceLock` //! Provides `Once`, `OnceState`, `OnceLock`
pub use once::{Once, OnceLock, OnceState}; pub use implementation::{Once, OnceLock, OnceState};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as once; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod once { mod implementation {
use core::{ use core::{
fmt, fmt,
panic::{RefUnwindSafe, UnwindSafe}, panic::{RefUnwindSafe, UnwindSafe},
@ -145,6 +145,7 @@ mod once {
/// Creates a new `Once` value. /// Creates a new `Once` value.
/// ///
/// See the standard library for further details. /// See the standard library for further details.
#[expect(clippy::new_without_default, reason = "matching std::sync::Once")]
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
inner: OnceLock::new(), inner: OnceLock::new(),

View File

@ -1,12 +1,12 @@
//! Provides `LockResult`, `PoisonError`, `TryLockError`, `TryLockResult` //! Provides `LockResult`, `PoisonError`, `TryLockError`, `TryLockResult`
pub use poison::{LockResult, PoisonError, TryLockError, TryLockResult}; pub use implementation::{LockResult, PoisonError, TryLockError, TryLockResult};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as poison; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod poison { mod implementation {
use core::{error::Error, fmt}; use core::{error::Error, fmt};
/// Fallback implementation of `PoisonError` from the standard library. /// Fallback implementation of `PoisonError` from the standard library.

View File

@ -1,12 +1,12 @@
//! TODO: Implement `RwLock`, `RwLockReadGuard`, `RwLockWriteGuard` //! Provides `RwLock`, `RwLockReadGuard`, `RwLockWriteGuard`
pub use rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; pub use implementation::{RwLock, RwLockReadGuard, RwLockWriteGuard};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as rwlock; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod rwlock { mod implementation {
use crate::sync::{LockResult, TryLockError, TryLockResult}; use crate::sync::{LockResult, TryLockError, TryLockResult};
use core::fmt; use core::fmt;

View File

@ -36,7 +36,7 @@ impl Instant {
let getter = ELAPSED_GETTER.load(Ordering::Acquire); let getter = ELAPSED_GETTER.load(Ordering::Acquire);
// SAFETY: Function pointer is always valid // SAFETY: Function pointer is always valid
let getter = unsafe { core::mem::transmute::<_, fn() -> Duration>(getter) }; let getter = unsafe { core::mem::transmute::<*mut (), fn() -> Duration>(getter) };
Self((getter)()) Self((getter)())
} }
@ -149,28 +149,29 @@ impl fmt::Debug for Instant {
} }
fn unset_getter() -> Duration { fn unset_getter() -> Duration {
let _nanos: u64; cfg_if::cfg_if! {
if #[cfg(target_arch = "x86")] {
#[cfg(target_arch = "x86")] // SAFETY: standard technique for getting a nanosecond counter on x86
unsafe { let nanos = unsafe {
_nanos = core::arch::x86::_rdtsc(); core::arch::x86::_rdtsc()
};
Duration::from_nanos(nanos)
} else if #[cfg(target_arch = "x86_64")] {
// SAFETY: standard technique for getting a nanosecond counter on x86_64
let nanos = unsafe {
core::arch::x86_64::_rdtsc()
};
Duration::from_nanos(nanos)
} else if #[cfg(target_arch = "aarch64")] {
// SAFETY: standard technique for getting a nanosecond counter of aarch64
let nanos = unsafe {
let mut ticks: u64;
core::arch::asm!("mrs {}, cntvct_el0", out(reg) ticks);
ticks
};
Duration::from_nanos(nanos)
} else {
panic!("An elapsed time getter has not been provided to `Instant`. Please use `Instant::set_elapsed(...)` before calling `Instant::now()`")
}
} }
#[cfg(target_arch = "x86_64")]
unsafe {
_nanos = core::arch::x86_64::_rdtsc();
}
#[cfg(target_arch = "aarch64")]
unsafe {
let mut ticks: u64;
core::arch::asm!("mrs {}, cntvct_el0", out(reg) ticks);
_nanos = ticks;
}
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
panic!("An elapsed time getter has not been provided to `Instant`. Please use `Instant::set_elapsed(...)` before calling `Instant::now()`");
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
return Duration::from_nanos(_nanos);
} }