Skip to content

Commit

Permalink
style: fix a ton of new Clippy lints
Browse files Browse the repository at this point in the history
Mostly, but not entirely, `clippy::needless_lifetimes`.
  • Loading branch information
hawkw committed Jan 11, 2025
1 parent 1359cfe commit 2b16d98
Show file tree
Hide file tree
Showing 35 changed files with 56 additions and 66 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bitfield/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ mod tests {
prop_assert_bits_eq!(packed, pack_from_src.set_all(0), state);
prop_assert_bits_eq!(pack_from_src.unpack_bits(packed), pack_from_dst.unpack_bits(dst), &state);

let dst = <$Bits>::max_value();
let dst = <$Bits>::MAX;
let packed = pair.pack_from_src(src, dst);
prop_assert_bits_eq!(packed, pack_from_src.set_all(0), state);
prop_assert_bits_eq!(pack_from_src.unpack_bits(packed), pack_from_dst.unpack_bits(dst), &state);
Expand Down
4 changes: 2 additions & 2 deletions hal-core/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ macro_rules! deref_draw_body {
};
}

impl<'lock, D, L> Draw for blocking::MutexGuard<'lock, D, L>
impl<D, L> Draw for blocking::MutexGuard<'_, D, L>
where
D: Draw,
L: blocking::RawMutex,
{
deref_draw_body! {}
}

impl<'draw, D> Draw for &'draw mut D
impl<D> Draw for &'_ mut D
where
D: Draw,
{
Expand Down
2 changes: 1 addition & 1 deletion hal-core/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ enum RegistrationErrorKind {

// === impl CriticalGuard ===

impl<'a, C: Control + ?Sized> Drop for CriticalGuard<'a, C> {
impl<C: Control + ?Sized> Drop for CriticalGuard<'_, C> {
fn drop(&mut self) {
unsafe {
self.ctrl.enable();
Expand Down
2 changes: 1 addition & 1 deletion hal-x86_64/src/cpu/msr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<V> Msr<V> {
options(nomem, nostack, preserves_flags)
);
}
(hi as u64) << 32 | (lo as u64)
((hi as u64) << 32) | (lo as u64)
}

/// Writes the given raw `u64` value to this MSR.
Expand Down
4 changes: 2 additions & 2 deletions hal-x86_64/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
}
}

impl<'buf, B> Draw for Framebuffer<'buf, B>
impl<B> Draw for Framebuffer<'_, B>
where
B: Deref<Target = [u8]> + DerefMut,
{
Expand Down Expand Up @@ -101,7 +101,7 @@ where

// `Volatile<B>` is only `Debug` if `<B as Deref>::Target: Copy`,
// so we must implement this manually.
impl<'buf, B> fmt::Debug for Framebuffer<'buf, B>
impl<B> fmt::Debug for Framebuffer<'_, B>
where
B: Deref<Target = [u8]>,
{
Expand Down
10 changes: 5 additions & 5 deletions hal-x86_64/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl Controller {
}
}

impl<'a, T> hal_core::interrupt::Context for Context<'a, T> {
impl<T> hal_core::interrupt::Context for Context<'_, T> {
type Registers = Registers;

fn registers(&self) -> &Registers {
Expand All @@ -402,7 +402,7 @@ impl<'a, T> hal_core::interrupt::Context for Context<'a, T> {
}
}

impl<'a> ctx::PageFault for Context<'a, PageFaultCode> {
impl ctx::PageFault for Context<'_, PageFaultCode> {
fn fault_vaddr(&self) -> crate::VAddr {
crate::control_regs::Cr2::read()
}
Expand All @@ -416,7 +416,7 @@ impl<'a> ctx::PageFault for Context<'a, PageFaultCode> {
}
}

impl<'a> ctx::CodeFault for Context<'a, CodeFault<'a>> {
impl ctx::CodeFault for Context<'_, CodeFault<'_>> {
fn is_user_mode(&self) -> bool {
false // TODO(eliza)
}
Expand All @@ -434,13 +434,13 @@ impl<'a> ctx::CodeFault for Context<'a, CodeFault<'a>> {
}
}

impl<'a> Context<'a, ErrorCode> {
impl Context<'_, ErrorCode> {
pub fn error_code(&self) -> ErrorCode {
self.code
}
}

impl<'a> Context<'a, PageFaultCode> {
impl Context<'_, PageFaultCode> {
pub fn page_fault_code(&self) -> PageFaultCode {
self.code
}
Expand Down
3 changes: 1 addition & 2 deletions hal-x86_64/src/interrupt/apic/ioapic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl IoApic {
fn entry_raw(&mut self, register_low: u32) -> RedirectionEntry {
let low = self.read(register_low);
let high = self.read(register_low + 1);
RedirectionEntry::from_bits((high as u64) << 32 | low as u64)
RedirectionEntry::from_bits(((high as u64) << 32) | low as u64)
}

#[inline]
Expand All @@ -453,7 +453,6 @@ impl IoApic {
}

#[must_use]

fn read(&mut self, offset: u32) -> u32 {
self.set_offset(offset);
self.registers.map_mut(|ioapic| &mut ioapic.data).read()
Expand Down
8 changes: 4 additions & 4 deletions hal-x86_64/src/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ where
/// This value should only be set once, early in the kernel boot process before
/// we have access to multiple cores. So, technically, it could be a `static
/// mut`. But, using an atomic is safe, even though it's not strictly necessary.
static VM_OFFSET: AtomicUsize = AtomicUsize::new(core::usize::MAX);
static VM_OFFSET: AtomicUsize = AtomicUsize::new(usize::MAX);

// XXX(eliza): this sucks
pub fn vm_offset() -> VAddr {
let off = VM_OFFSET.load(Ordering::Acquire);
assert_ne!(
off,
core::usize::MAX,
usize::MAX,
"`init_paging` must be called before calling `vm_offset`!"
);
VAddr::from_usize(off)
Expand Down Expand Up @@ -204,7 +204,7 @@ impl PageCtrl {
let vm_offset = VM_OFFSET.load(Ordering::Acquire);
assert_ne!(
vm_offset,
core::usize::MAX,
usize::MAX,
"`init_paging` must be called before calling `PageTable::current`!"
);
let vm_offset = VAddr::from_usize(vm_offset);
Expand Down Expand Up @@ -587,7 +587,7 @@ impl<L: level::PointsToPage> page::PageFlags<L::Size> for Entry<L> {
impl<L: Level> fmt::Debug for Entry<L> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
struct FmtFlags<'a, L>(&'a Entry<L>);
impl<'a, L> fmt::Debug for FmtFlags<'a, L> {
impl<L> fmt::Debug for FmtFlags<'_, L> {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
macro_rules! write_flags {
Expand Down
2 changes: 1 addition & 1 deletion hal-x86_64/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<B> Lock<'_, B> {
}

let divisor = Port::MAX_BAUD_RATE / baud;
if divisor > (core::u16::MAX as usize) {
if divisor > (u16::MAX as usize) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"divisor for target baud rate is too high!",
Expand Down
1 change: 0 additions & 1 deletion maitake-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg, doc_cfg_hide))]
#![cfg_attr(docsrs, doc(cfg_hide(docsrs, loom)))]
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(feature = "core-error", feature(error_in_core))]
#![warn(missing_docs, missing_debug_implementations)]

#[cfg(any(feature = "alloc", test))]
Expand Down
1 change: 0 additions & 1 deletion maitake-sync/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ mod tests;
// for some reason, intra-doc links don't work in footnotes?
/// [storage]: https://mycelium.elizas.website/maitake/task/trait.Storage.html
/// [no-unwinding]: https://mycelium.elizas.website/maitake/index.html#maitake-does-not-support-unwinding
pub struct Mutex<T: ?Sized, L: ScopedRawMutex = DefaultMutex> {
wait: WaitQueue<L>,
data: UnsafeCell<T>,
Expand Down
1 change: 0 additions & 1 deletion maitake-sync/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ pub(crate) mod test {
///
/// Returns a [TestGuard] that must be held for the duration of test to ensure
/// tracing messages are correctly output
#[cfg(all(test, not(loom)))]
pub(crate) fn trace_init() -> TestGuard {
trace_init_with_default("maitake=debug,cordyceps=debug")
Expand Down
1 change: 0 additions & 1 deletion maitake-sync/src/util/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ impl<T> CheckedMaybeUninit<T> {
/// foo.assume_init()
/// };
/// ```
#[inline(always)]
#[track_caller]
pub unsafe fn assume_init_mut(&mut self) -> &mut T {
Expand Down
2 changes: 1 addition & 1 deletion maitake-sync/src/wait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ where
wait: Pin<&'a mut Wait<'b, K, V, Lock>>,
}

impl<'a, 'b, K, V, Lock> Future for Subscribe<'a, 'b, K, V, Lock>
impl<K, V, Lock> Future for Subscribe<'_, '_, K, V, Lock>
where
K: PartialEq,
Lock: ScopedRawMutex,
Expand Down
1 change: 0 additions & 1 deletion maitake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg, doc_cfg_hide))]
#![cfg_attr(docsrs, doc(cfg_hide(docsrs, loom)))]
#![cfg_attr(not(test), no_std)]
#![cfg_attr(feature = "core-error", feature(error_in_core))]
#![allow(unused_unsafe)]

#[cfg(feature = "alloc")]
Expand Down
2 changes: 1 addition & 1 deletion maitake/src/task/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ feature! {

// === impl Settings ===

impl<'a> Settings<'a> {
impl Settings<'_> {
/// Returns a new, empty task builder with no settings configured.
#[must_use]
pub(crate) const fn new() -> Self {
Expand Down
3 changes: 2 additions & 1 deletion maitake/src/task/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ impl mycelium_bitfield::FromBits<usize> for JoinWakerState {
const BITS: u32 = 2;

#[inline]
#[allow(clippy::literal_string_with_formatting_args)]
fn try_from_bits(bits: usize) -> Result<Self, Self::Error> {
match bits {
b if b == Self::Registering as usize => Ok(Self::Registering),
Expand Down Expand Up @@ -590,7 +591,7 @@ mod tests {
fn packing_specs_valid() {
State::assert_valid()
}

#[test]
// No sense spending time running these trivial tests under Miri...
#[cfg_attr(miri, ignore)]
Expand Down
4 changes: 1 addition & 3 deletions maitake/src/task/tests/alloc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use tokio_test::{assert_pending, assert_ready_err, assert_ready_ok};
/// vtable methods are valid.
#[test]
fn task_is_valid_for_casts() {
let task = Box::new(Task::<NopSchedule, _, BoxStorage>::new(async {
unimplemented!("this task should never be polled")
}));
let task = Box::new(Task::<NopSchedule, _, BoxStorage>::new(async {}));

let task_ptr = Box::into_raw(task);

Expand Down
3 changes: 1 addition & 2 deletions maitake/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ use core::future::Future;
/// [global]: #global-timers
/// [max]: Timer::max_duration
#[track_caller]

pub fn sleep(duration: Duration) -> Sleep<'static> {
util::expect_display(try_sleep(duration), "cannot create `Sleep` future")
}
Expand All @@ -105,7 +104,7 @@ pub fn sleep(duration: Duration) -> Sleep<'static> {
/// # Returns
///
/// - [`Ok`]`(`[`Sleep`]`)` if a new [`Sleep`] future was created
/// successfully.
/// successfully.
/// - [`Err`]`(`[`TimerError::NoGlobalTimer`]`)` if a [global timer][global] was
/// not set by calling [`set_global_timer`] first.
/// - [`Err`]`(`[`TimerError::DurationTooLong`]`)` if the requested sleep
Expand Down
2 changes: 1 addition & 1 deletion maitake/src/time/timer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::time::{timer::Ticks, Clock};
use std::time::Duration;

crate::loom::thread_local! {
static CLOCK: RefCell<Option<Arc<TestClockState>>> = RefCell::new(None);
static CLOCK: RefCell<Option<Arc<TestClockState>>> = const { RefCell::new(None) };
}

#[derive(Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions mycotest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ macro_rules! decl_test {

// === impl TestName ===

impl<'a, S> TestName<'a, S> {
impl<S> TestName<'_, S> {
pub const fn new(module: S, name: S) -> Self {
Self {
name,
Expand All @@ -101,7 +101,7 @@ impl<'a, S> TestName<'a, S> {
}
}

impl<'a, S> TestName<'a, S>
impl<S> TestName<'_, S>
where
S: AsRef<str>,
{
Expand Down
2 changes: 1 addition & 1 deletion pci/src/express.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum MmKind<'device> {
PciBridge(Volatile<&'device mut PciBridgeDetails>),
}

impl<'device> MemoryMappedDevice<'device> {
impl MemoryMappedDevice<'_> {
pub fn header(&self) -> device::Header {
self.header.read()
}
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/oops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<'a> From<&'a PanicInfo<'a>> for Oops<'a> {

// === impl OopsSituation ===

impl<'a> OopsSituation<'a> {
impl OopsSituation<'_> {
fn header(&self) -> &'static str {
match self {
Self::Fault { .. } => " OOPSIE-WOOPSIE! ",
Expand Down
2 changes: 1 addition & 1 deletion src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl<'cmd> Context<'cmd> {
T::Err: core::fmt::Display,
{
self.parse_optional_flag(names).and_then(|val| {
val.ok_or_else(|| Error {
val.ok_or(Error {
line: self.line,
kind: ErrorKind::FlagRequired { flags: names },
})
Expand Down
8 changes: 4 additions & 4 deletions trace/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<W: SetColor> SetColor for &'_ mut W {

// === impl WithFgColor ===

impl<'writer, W> fmt::Write for WithFgColor<'writer, W>
impl<W> fmt::Write for WithFgColor<'_, W>
where
W: fmt::Write + SetColor,
{
Expand All @@ -116,7 +116,7 @@ where
}
}

impl<'writer, W> Drop for WithFgColor<'writer, W>
impl<W> Drop for WithFgColor<'_, W>
where
W: fmt::Write + SetColor,
{
Expand All @@ -127,7 +127,7 @@ where

// === impl WithBold ===

impl<'writer, W> fmt::Write for WithBold<'writer, W>
impl<W> fmt::Write for WithBold<'_, W>
where
W: fmt::Write + SetColor,
{
Expand All @@ -147,7 +147,7 @@ where
}
}

impl<'writer, W> Drop for WithBold<'writer, W>
impl<W> Drop for WithBold<'_, W>
where
W: fmt::Write + SetColor,
{
Expand Down
Loading

0 comments on commit 2b16d98

Please sign in to comment.