Skip to content

Commit

Permalink
fix clippy lints - further action recommended (see TODOs)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatol Ulrich committed Aug 10, 2024
1 parent b45865f commit 80928e4
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 20 deletions.
13 changes: 11 additions & 2 deletions platforms/allwinner-d1/d1-core/src/dmac/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
// separate the bits by which field they represent, rather than by their byte.
#![allow(clippy::unusual_byte_groupings)]

use self::errors::*;
use core::{cmp, mem, ptr::NonNull};

use d1_pac::generic::{Reg, RegisterSpec};
use mycelium_bitfield::{bitfield, enum_from_bits};

use self::errors::*;

#[derive(Clone, Debug)]
#[repr(C, align(4))]
pub struct Descriptor {
Expand Down Expand Up @@ -195,6 +197,12 @@ bitfield! {
}
}

impl Default for DescriptorBuilder {
fn default() -> Self {
Self::new()
}
}

impl DescriptorBuilder {
pub const fn new() -> Self {
Self {
Expand Down Expand Up @@ -557,9 +565,10 @@ impl Descriptor {
}

pub mod errors {
use super::*;
use core::fmt;

use super::*;

/// Errors returned by [`DescriptorBuilder::build`].
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InvalidDescriptor {
Expand Down
9 changes: 6 additions & 3 deletions platforms/allwinner-d1/d1-core/src/drivers/smhc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use core::{
task::{Poll, Waker},
};

use crate::ccu::Ccu;
use d1_pac::{smhc, Interrupt, GPIO, SMHC0, SMHC1, SMHC2};
use kernel::{
mnemos_alloc::containers::FixedVec,
Expand All @@ -25,6 +24,8 @@ use kernel::{
tracing, Kernel,
};

use crate::ccu::Ccu;

pub struct Smhc {
isr: &'static IsrData,
smhc: &'static smhc::RegisterBlock,
Expand Down Expand Up @@ -518,6 +519,8 @@ impl Smhc {
self.smhc.smhc_resp2.read().bits(),
self.smhc.smhc_resp3.read().bits(),
];
// TODO warning: transmute used without annotations
#[allow(clippy::missing_transmute_annotations)]
Ok(sdmmc::Response::Long(unsafe { core::mem::transmute(rsp) }))
} else {
Ok(sdmmc::Response::Short {
Expand Down Expand Up @@ -715,8 +718,8 @@ impl SmhcData {

/// Internal DMA controller
mod idmac {
use core::mem;
use core::ptr::NonNull;
use core::{mem, ptr::NonNull};

use mycelium_bitfield::bitfield;

/// A descriptor that describes how memory needs to transfer data
Expand Down
18 changes: 10 additions & 8 deletions platforms/allwinner-d1/d1-core/src/drivers/uart.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// Note: We sometimes force a pass by ref mut to enforce exclusive access
#![allow(clippy::needless_pass_by_ref_mut)]

use d1_pac::{GPIO, UART0};

use core::{
ptr::{null_mut, NonNull},
sync::atomic::{AtomicPtr, Ordering},
};

use crate::ccu::Ccu;
use crate::dmac::{
descriptor::{BlockSize, DataWidth, Descriptor, DestDrqType},
ChannelMode, Dmac,
};
use d1_pac::{GPIO, UART0};
use kernel::{
comms::bbq::{new_bidi_channel, BidiHandle, Consumer, GrantW, SpscProducer},
maitake::sync::WaitCell,
Expand All @@ -21,9 +15,17 @@ use kernel::{
services::simple_serial::{Request, Response, SimpleSerialError, SimpleSerialService},
Kernel,
};

use tracing::Level;

use crate::{
ccu::Ccu,
dmac::{
descriptor::{BlockSize, DataWidth, Descriptor, DestDrqType},
ChannelMode, Dmac,
},
};

#[allow(dead_code)]
struct GrantWriter {
grant: GrantW,
used: usize,
Expand Down
1 change: 1 addition & 0 deletions platforms/allwinner-d1/d1-core/src/plic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ trait IntoBits: Sized + Copy {
fn into_bits(self) -> u32;
}

#[allow(dead_code)]
trait TryFromBits: Sized + Copy {
type Error;
fn try_from_bits(bits: u32) -> Result<Self, Self::Error>;
Expand Down
6 changes: 6 additions & 0 deletions platforms/allwinner-d1/d1-core/src/ram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ pub struct Ram<const N: usize> {
}

unsafe impl<const N: usize> Sync for Ram<N> {}

impl<const N: usize> Default for Ram<N> {
fn default() -> Self {
Self::new()
}
}
impl<const N: usize> Ram<N> {
pub const fn new() -> Self {
Self {
Expand Down
3 changes: 2 additions & 1 deletion platforms/esp32c3-buddy/src/drivers/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use esp32c3_hal::{
prelude::interrupt,
uart::{Instance, Uart},
};

use kernel::{
comms::bbq::{new_bidi_channel, BidiHandle, Consumer, GrantW, SpscProducer},
maitake::sync::WaitCell,
Expand All @@ -18,6 +17,8 @@ use kernel::{
Kernel,
};

// TODO warning: struct `GrantWriter` is never constructed
#[allow(dead_code)]
struct GrantWriter {
grant: GrantW,
used: usize,
Expand Down
4 changes: 3 additions & 1 deletion platforms/esp32c3-buddy/src/drivers/usb_serial.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use esp32c3_hal::{peripherals::USB_DEVICE, prelude::*};

use futures::FutureExt;
use kernel::{
comms::bbq::{new_bidi_channel, BidiHandle, GrantW},
Expand All @@ -13,6 +12,9 @@ pub struct UsbSerialServer {
dev: USB_DEVICE,
}

// TODO warning: struct `GrantWriter` is never constructed
#[allow(dead_code)]

struct GrantWriter {
grant: GrantW,
used: usize,
Expand Down
6 changes: 6 additions & 0 deletions source/abi/src/bbqueue_ipc/bbbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ impl<'a> BBBuffer {
}
}

impl Default for BBBuffer {
fn default() -> Self {
Self::new()
}
}

impl BBBuffer {
/// Create a new constant inner portion of a `BBBuffer`.
///
Expand Down
6 changes: 6 additions & 0 deletions source/alloc/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ pub enum InitError {
#[cfg(feature = "stats")]
pub use self::stats::State;

impl<U: UnderlyingAllocator> Default for MnemosAlloc<U> {
fn default() -> Self {
Self::new()
}
}

impl<U: UnderlyingAllocator> MnemosAlloc<U> {
const INITIALIZING: usize = usize::MAX;

Expand Down
6 changes: 6 additions & 0 deletions source/bitslab/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ macro_rules! make_index_allocs {
max_mask: $Int,
}

impl Default for $Name {
fn default() -> Self {
Self::new()
}
}

impl $Name {
#[doc = concat!("Returns a new allocator for up to ", stringify!($cap), " unique indices.")]
#[must_use]
Expand Down
4 changes: 2 additions & 2 deletions source/kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
#![cfg_attr(not(test), no_std)]
#![allow(clippy::missing_safety_doc)]
#![feature(impl_trait_in_assoc_type)]
#![feature(async_fn_in_trait)] // needed for `embedded-hal-async`

extern crate alloc;

Expand All @@ -88,12 +87,13 @@ pub mod services;
#[cfg(test)]
pub(crate) mod test_util;

use core::{convert::identity, future::Future, ptr::NonNull};

use abi::{
bbqueue_ipc::BBBuffer,
syscall::{KernelResponse, UserRequest},
};
use comms::kchannel::KChannel;
use core::{convert::identity, future::Future, ptr::NonNull};
pub use embedded_hal_async;
pub use maitake;
use maitake::{
Expand Down
6 changes: 4 additions & 2 deletions source/kernel/src/services/sdmmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
//! while the platform driver will implement the device specific part
//! (how to send and receive the data).
#![warn(missing_docs)]
use maitake::time::{self, Duration};
use uuid::Uuid;

use crate::{
comms::oneshot::Reusable,
mnemos_alloc::containers::FixedVec,
registry::{self, known_uuids, Envelope, KernelHandle, RegisteredDriver},
Kernel,
};
use maitake::time::{self, Duration};
use uuid::Uuid;

////////////////////////////////////////////////////////////////////////////////
// Service Definition
Expand Down Expand Up @@ -244,6 +245,7 @@ pub struct CardStatus(u32);
/// | Manufacturing date | `[19:8]` |
/// | CRC7 checksum | `[7:1]` |
/// | Not used, always 1 | `[0:0]` |
#[allow(dead_code)]
pub struct CardIdentification(u128);

/// Published RCA in R6 response format
Expand Down
5 changes: 4 additions & 1 deletion source/spitebuf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#![no_std]
#![allow(clippy::missing_safety_doc)]

use core::marker::PhantomData;
use core::{
cell::UnsafeCell,
marker::PhantomData,
mem::MaybeUninit,
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
};

use maitake::sync::{WaitCell, WaitQueue};

pub unsafe trait Storage<T> {
Expand Down Expand Up @@ -178,6 +179,8 @@ pub fn cell_array<const N: usize, T: Sized>() -> [Cell<T>; N] {
}

impl<T> Cell<T> {
// TODO https://rust-lang.github.io/rust-clippy/master/index.html#/declare_interior_mutable_const
#[allow(clippy::declare_interior_mutable_const)]
const SINGLE_CELL: Self = Self::new(0);

const fn new(seq: usize) -> Self {
Expand Down

0 comments on commit 80928e4

Please sign in to comment.