Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,13 @@ exclude = [
]

[workspace.lints.rust]
function_casts_as_integer = "allow"
mismatched_lifetime_syntaxes = "allow"
missing_crate_level_docs = "warn"
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(baseline_asterinas)', 'cfg(ktest)'] }
unpredictable-function-pointer-comparisons = "allow"
unsafe_op_in_unsafe_fn = "deny"
unused_parens = "allow"

[workspace.lints.clippy]
allow_attributes = "warn"
collapsible_match = "allow"
collapsible-if = "allow"
derivable_impls = "allow"
explicit_counter_loop = "allow"
filter_next = "allow"
implicit_saturating_sub = "allow"
iter_kv_map = "allow"
let_and_return = "allow"
manual_is_multiple_of = "allow"
manual_saturating_arithmetic = "allow"
mem-replace-option-with-some = "allow"
question_mark = "allow"
unnecessary_cast = "allow"
unnecessary_option_map_or_else = "allow"
unnecessary_sort_by = "allow"
unnecessary_unwrap = "allow"
while_let_loop = "allow"

# TODO(arthurp, #48): Enable once the code can pass it.
# undocumented_unsafe_blocks = "deny"
Expand Down
4 changes: 2 additions & 2 deletions kernel/comps/block/src/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ impl From<BioDirection> for DmaDirection {

/// Checks if the given offset is aligned to sector.
pub fn is_sector_aligned(offset: usize) -> bool {
offset % SECTOR_SIZE == 0
offset.is_multiple_of(SECTOR_SIZE)
}

/// An aligned unsigned integer number.
Expand Down Expand Up @@ -918,7 +918,7 @@ pub struct AlignedUsize<const N: u16>(usize);
impl<const N: u16> AlignedUsize<N> {
/// Constructs a new instance of aligned integer if the given value is aligned.
pub fn new(val: usize) -> Option<Self> {
if val % (N as usize) == 0 {
if val.is_multiple_of(N as usize) {
Some(Self(val))
} else {
None
Expand Down
13 changes: 6 additions & 7 deletions kernel/comps/block/src/request_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ impl BioRequestSingleQueue {
}

let mut queue = self.queue.lock();
if let Some(request) = queue.front_mut() {
if request.can_merge(&bio)
&& request.num_segments() + bio.segments().len() <= self.max_nr_segments_per_bio
{
request.merge_bio(bio);
return Ok(());
}
if let Some(request) = queue.front_mut()
&& request.can_merge(&bio)
&& request.num_segments() + bio.segments().len() <= self.max_nr_segments_per_bio
{
request.merge_bio(bio);
return Ok(());
}

let new_request = BioRequest::from(bio);
Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/framebuffer/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl FrameBuffer {
}

/// Calculates the offset of a pixel at the specified position.
pub fn calc_offset(&self, x: usize, y: usize) -> PixelOffset {
pub fn calc_offset(&self, x: usize, y: usize) -> PixelOffset<'_> {
PixelOffset {
fb: self,
offset: ((y * self.width + x) * self.pixel_format.nbytes()) as isize,
Expand Down
4 changes: 2 additions & 2 deletions kernel/comps/mlsdisk/src/layers/0-bio/block_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> TryFrom<&'a [u8]> for BufRef<'a> {
if buf.is_empty() {
return_errno_with_msg!(InvalidArgs, "empty buf in `BufRef::try_from`");
}
if buf.len() % BLOCK_SIZE != 0 {
if !buf.len().is_multiple_of(BLOCK_SIZE) {
return_errno_with_msg!(
NotBlockSizeAligned,
"buf not block size aligned `BufRef::try_from`"
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<'a> TryFrom<&'a mut [u8]> for BufMut<'a> {
if buf.is_empty() {
return_errno_with_msg!(InvalidArgs, "empty buf in `BufMut::try_from`");
}
if buf.len() % BLOCK_SIZE != 0 {
if !buf.len().is_multiple_of(BLOCK_SIZE) {
return_errno_with_msg!(
NotBlockSizeAligned,
"buf not block size aligned `BufMut::try_from`"
Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/mlsdisk/src/layers/0-bio/block_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub trait BlockSet: Sync + Send {
blocks.as_mut_slice()[start_offset..end_offset].copy_from_slice(buf);

// Maybe we should read the last block partially.
if end_offset % BLOCK_SIZE != 0 {
if !end_offset.is_multiple_of(BLOCK_SIZE) {
let mut end_block = Buf::alloc(1)?;
self.read(end_pos, end_block.as_mut())?;
blocks.as_mut_slice()[end_offset..]
Expand Down
25 changes: 10 additions & 15 deletions kernel/comps/mlsdisk/src/layers/1-crypto/crypto_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,9 @@ impl<L: BlockLog> CryptoLog<L> {
let data_nodes: Vec<Arc<DataNode>> = buf
.iter()
.map(|block_buf| {
let data_node = {
let mut node = DataNode::new_uninit();
node.0.copy_from_slice(block_buf.as_slice());
Arc::new(node)
};
data_node
let mut node = DataNode::new_uninit();
node.0.copy_from_slice(block_buf.as_slice());
Arc::new(node)
})
.collect();

Expand Down Expand Up @@ -489,17 +486,15 @@ impl<L: BlockLog> MhtStorage<L> {
let num_append = nodes.len();
let mut node_entries = Vec::with_capacity(num_append);
let mut cipher_buf = Buf::alloc(num_append)?;
let mut pos = self.block_log.nblocks() as BlockId;
let start_pos = pos;
for (i, node) in nodes.iter().enumerate() {
let start_pos = self.block_log.nblocks() as BlockId;
for (pos, (i, node)) in (start_pos..).zip(nodes.iter().enumerate()) {
let plain = node.as_bytes();
let cipher = &mut cipher_buf.as_mut_slice()[i * BLOCK_SIZE..(i + 1) * BLOCK_SIZE];
let key = Key::random();
let mac = Aead::new().encrypt(plain, &key, &Iv::new_zeroed(), &[], cipher)?;

node_entries.push(MhtNodeEntry { pos, key, mac });
self.node_cache.put(pos, node.clone());
pos += 1;
}

let append_pos = self.block_log.append(cipher_buf.as_ref())?;
Expand All @@ -515,15 +510,13 @@ impl<L: BlockLog> MhtStorage<L> {
}

let mut cipher_buf = Buf::alloc(num_append)?;
let mut pos = self.block_log.nblocks() as BlockId;
let start_pos = pos;
for (i, node) in nodes.iter().enumerate() {
let start_pos = self.block_log.nblocks() as BlockId;
for (pos, (i, node)) in (start_pos..).zip(nodes.iter().enumerate()) {
let cipher = &mut cipher_buf.as_mut_slice()[i * BLOCK_SIZE..(i + 1) * BLOCK_SIZE];
let key = Key::random();
let mac = Aead::new().encrypt(&node.0, &key, &Iv::new_zeroed(), &[], cipher)?;

node_entries.push(MhtNodeEntry { pos, key, mac });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just inline "start_pos + i" here and avoid the zip? It's a bit harder to understand for no real gain imo

pos += 1;
}

let append_pos = self.block_log.append(cipher_buf.as_ref())?;
Expand Down Expand Up @@ -607,7 +600,9 @@ impl MhtNode {
}

pub fn num_complete_children(&self) -> usize {
if self.num_data_nodes() % MHT_NBRANCHES == 0 || Self::is_lowest_level(self.height()) {
if self.num_data_nodes().is_multiple_of(MHT_NBRANCHES)
|| Self::is_lowest_level(self.height())
{
self.num_valid_entries()
} else {
self.num_valid_entries() - 1
Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/mlsdisk/src/layers/4-lsm/mem_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<K: RecordKey<K>, V: RecordValue> MemTableManager<K, V> {
}

/// Gets the immutable `MemTable` instance (read-only).
pub fn immutable_memtable(&self) -> RwLockReadGuard<MemTable<K, V>> {
pub fn immutable_memtable(&self) -> RwLockReadGuard<'_, MemTable<K, V>> {
self.immutable.read()
}
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/mlsdisk/src/layers/4-lsm/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<D: BlockSet + 'static> WalAppendTx<D> {
wal_tx: &CurrentTx<'_>,
log: &Arc<TxLog<D>>,
) -> Result<()> {
debug_assert!(!record_buf.is_empty() && record_buf.len() % BLOCK_SIZE == 0);
debug_assert!(!record_buf.is_empty() && record_buf.len().is_multiple_of(BLOCK_SIZE));
let res = wal_tx.context(|| {
let buf = BufRef::try_from(record_buf).unwrap();
log.append(buf)
Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/mlsdisk/src/layers/5-disk/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl BioReq {
/// or accessed by block devices and their users. Each of the extension objects
/// must have a different type. To avoid conflicts, it is recommended to use only
/// private types for the extension objects.
pub fn ext(&self) -> MutexGuard<HashMap<TypeId, Box<dyn Any + Send + Sync>>> {
pub fn ext(&self) -> MutexGuard<'_, HashMap<TypeId, Box<dyn Any + Send + Sync>>> {
self.ext.lock()
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/comps/mlsdisk/src/layers/5-disk/mlsdisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<D: BlockSet + 'static> aster_block::BlockDevice for MlsDisk<D> {
}

// Read the last unaligned block.
if end_offset % BLOCK_SIZE != 0 {
if !end_offset.is_multiple_of(BLOCK_SIZE) {
let offset = buf.as_slice().len() - BLOCK_SIZE;
let buf_mut = BufMut::try_from(&mut buf.as_mut_slice()[offset..]).unwrap();
if self.read(end_lba - 1, buf_mut).is_err() {
Expand Down Expand Up @@ -434,7 +434,7 @@ impl<D: BlockSet + 'static> DiskInner<D> {

let mut res = range_query_ctx.into_results();
let record_batches = {
res.sort_by(|(_, v1), (_, v2)| v1.hba.cmp(&v2.hba));
res.sort_by_key(|(_, v1)| v1.hba);
res.chunk_by(|(_, v1), (_, v2)| v2.hba - v1.hba == 1)
};

Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/mlsdisk/src/util/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl BitMap {
}

// Set the unused bits in the last u64 with zero.
if nbits % 64 != 0 {
if !nbits.is_multiple_of(64) {
bits[vec_len - 1]
.iter_ones()
.filter(|index| (*index as usize) >= nbits % 64)
Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/systree/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub trait SysBranchNode: SysNode {
fn visit_children_with(
&self,
min_id: u64,
f: &mut dyn for<'a> FnMut(&'a Arc<(dyn SysObj)>) -> Option<()>,
f: &mut dyn for<'a> FnMut(&'a Arc<dyn SysObj>) -> Option<()>,
);

/// Returns a child with a specified name.
Expand Down
2 changes: 1 addition & 1 deletion kernel/comps/time/src/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn init_timer() {
let update = move || {
let counter = TSC_UPDATE_COUNTER.fetch_add(1, Ordering::Relaxed);

if counter % delay_counts == 0 {
if counter.is_multiple_of(delay_counts) {
update_clocksource();
}
};
Expand Down
8 changes: 4 additions & 4 deletions kernel/libs/aster-bigtcp/src/iface/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ impl<E: Ext> IfaceCommon<E> {
/// Releases the port so that it can be used again (if it is not being reused).
fn release_port(&self, port: u16) {
let mut used_ports = self.used_ports.lock();
if let Some(used_times) = used_ports.remove(&port) {
if used_times != 1 {
used_ports.insert(port, used_times - 1);
}
if let Some(used_times) = used_ports.remove(&port)
&& used_times != 1
{
used_ports.insert(port, used_times - 1);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions kernel/libs/aster-bigtcp/src/iface/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,14 @@ impl<E: Ext> PollContext<'_, E> {
}));
});

if let Some((ip_repr, ip_payload)) = deferred {
if let Some(reply) = self.parse_and_process_udp(
if let Some((ip_repr, ip_payload)) = deferred
&& let Some(reply) = self.parse_and_process_udp(
&ip_repr,
&ip_payload,
&ChecksumCapabilities::ignored(),
) {
dispatch_phy(&reply, self.iface.context_mut(), tx_token.take().unwrap());
}
)
{
dispatch_phy(&reply, self.iface.context_mut(), tx_token.take().unwrap());
}

if tx_token.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion kernel/libs/aster-bigtcp/src/iface/poll_iface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<E: Ext> PollableIface<E> {
}
}

pub(super) fn as_mut(&mut self) -> PollableIfaceMut<E> {
pub(super) fn as_mut(&'_ mut self) -> PollableIfaceMut<'_, E> {
PollableIfaceMut {
context: self.interface.context(),
pending_conns: &mut self.pending_conns,
Expand Down
2 changes: 1 addition & 1 deletion kernel/libs/aster-bigtcp/src/socket/bound/tcp_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<E: Ext> TcpConnectionInner<E> {
}
}

pub(super) fn lock(&self) -> SpinLockGuard<RawTcpSocketExt<E>, BottomHalfDisabled> {
pub(super) fn lock(&self) -> SpinLockGuard<'_, RawTcpSocketExt<E>, BottomHalfDisabled> {
self.socket.lock()
}
}
Expand Down
5 changes: 1 addition & 4 deletions kernel/libs/aster-bigtcp/src/socket/bound/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ impl<E: Ext> UdpSocket<E> {
return Err(SendError::TooLarge);
}

let buffer = match socket.send(size, meta) {
Ok(data) => data,
Err(err) => return Err(err.into()),
};
let buffer = socket.send(size, meta)?;
let result = f(buffer);

self.0
Expand Down
2 changes: 1 addition & 1 deletion kernel/libs/aster-util/src/safe_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<T: PodOnce, M: VmIoOnce, R: TRights> SafePtr<T, M, TRightSet<R>> {
// =============== Address-related methods ==============
impl<T, M, R> SafePtr<T, M, R> {
pub const fn is_aligned(&self) -> bool {
self.offset % core::mem::align_of::<T>() == 0
self.offset.is_multiple_of(core::mem::align_of::<T>())
}

/// Increase the address in units of bytes occupied by the generic T.
Expand Down
9 changes: 2 additions & 7 deletions kernel/libs/cpio-decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl FileMetadata {

/// The type of the file.
#[repr(u32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, TryFromInt)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, TryFromInt, Default)]
pub enum FileType {
/// FIFO special file
FiFo = 0o010000,
Expand All @@ -292,19 +292,14 @@ pub enum FileType {
/// Block device
Block = 0o060000,
/// Regular file
#[default]
File = 0o100000,
/// Symbolic link
Link = 0o120000,
/// Socket
Socket = 0o140000,
}

impl Default for FileType {
fn default() -> Self {
Self::File
}
}

const MAGIC: &[u8] = b"070701";
const TRAILER_NAME: &str = "TRAILER!!!";

Expand Down
2 changes: 1 addition & 1 deletion kernel/libs/typeflags/src/type_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl TypeFlagDef {
}

/// return the items iter
pub fn items_iter(&self) -> syn::punctuated::Iter<TypeFlagItem> {
pub fn items_iter(&self) -> syn::punctuated::Iter<'_, TypeFlagItem> {
self.items.iter()
}

Expand Down
10 changes: 3 additions & 7 deletions kernel/libs/xarray/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,19 @@ use crate::{
/// A cursor never ends up on an interior node. In other words, when methods
/// of `Cursor` or `CursorMut` finish, the cursor will either not positioned on any node
/// or positioned on some leaf node.
#[derive(Default)]
enum CursorState<'a, P>
where
P: NonNullPtr + Send + Sync,
{
#[default]
Inactive,
AtNode {
node: NodeEntryRef<'a, P>,
operation_offset: u8,
},
}

impl<P: NonNullPtr + Send + Sync> Default for CursorState<'_, P> {
fn default() -> Self {
Self::Inactive
}
}

impl<'a, P: NonNullPtr + Send + Sync> CursorState<'a, P> {
fn move_to(&mut self, node: NodeEntryRef<'a, P>, index: u64) {
let operation_offset = node.entry_offset(index);
Expand Down Expand Up @@ -271,7 +267,7 @@ impl<'a, P: NonNullPtr + Send + Sync, M> CursorMut<'a, P, M> {
}

/// Returns an `XLockGuard` that marks the `XArray` is locked.
fn lock_guard(&self) -> XLockGuard {
fn lock_guard(&self) -> XLockGuard<'_> {
// Having a `CursorMut` means that the `XArray` is locked.
XLockGuard(self.guard)
}
Expand Down
Loading
Loading