Skip to content

Commit

Permalink
update lints + minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kadiwa4 committed Nov 3, 2024
1 parent 37614a8 commit 2cc1e8c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
members = ["deforest_derive"]

[workspace.lints.rust]
rust_2018_idioms = "warn"
rust_2018_idioms = { level = "warn", priority = -1 }
macro_use_extern_crate = "warn"
meta_variable_misuse = "warn"
missing_abi = "warn"
redundant_lifetimes = "warn"
unnameable_types = "warn"
unreachable_pub = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

[workspace.lints.rustdoc]
unescaped_backticks = "warn"

[package]
name = "deforest"
version = "0.3.2"
Expand Down Expand Up @@ -50,9 +56,10 @@ zerocopy = { version = "0.7.31", default-features = false, features = ["derive"]

[features]
alloc = ["fallible-iterator/alloc"]
std = ["alloc", "fallible-iterator/std"]

derive = ["deforest_derive"]
model = []
std = ["alloc", "fallible-iterator/std"]

[lints]
workspace = true
15 changes: 5 additions & 10 deletions src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{

/// Starting point for constructing a [`Devicetree`] yourself.
#[derive(Clone, Debug)]
#[must_use]
#[non_exhaustive]
pub struct DevicetreeBuilder<'a> {
/// Defaults to 0.
Expand Down Expand Up @@ -96,16 +97,10 @@ impl<'a> DevicetreeBuilder<'a> {
// the constructed Devicetree would pass all of the checks, so we can skip them
unsafe {
let ptr = blob.as_mut_ptr() as *mut u8;
core::ptr::copy_nonoverlapping(
self.struct_blob.as_ptr(),
ptr.add(struct_offset) as *mut u32,
self.struct_blob.len(),
);
core::ptr::copy_nonoverlapping(
self.strings_blob.as_ptr(),
ptr.add(strings_offset),
self.strings_blob.len(),
);
(ptr.add(struct_offset) as *mut u32)
.copy_from_nonoverlapping(self.struct_blob.as_ptr(), self.struct_blob.len());
ptr.add(strings_offset)
.copy_from_nonoverlapping(self.strings_blob.as_ptr(), self.strings_blob.len());
blob.set_len(capacity);

Some(Devicetree::from_box_unchecked(blob.into_boxed_slice()))
Expand Down
11 changes: 4 additions & 7 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) struct Header {
}

impl Header {
pub const SIZE: usize = size_of::<Self>();
pub(crate) const SIZE: usize = size_of::<Self>();
}

/// Devicetree blob.
Expand Down Expand Up @@ -150,11 +150,8 @@ impl Devicetree {

// SAFETY: after the requested buffer is filled with data, len can be set to the capacity
unsafe {
core::ptr::copy_nonoverlapping(
blob.as_ptr(),
aligned_blob.as_mut_ptr() as *mut u8,
blob.len(),
);
(aligned_blob.as_mut_ptr() as *mut u8)
.copy_from_nonoverlapping(blob.as_ptr(), blob.len());
aligned_blob.set_len(capacity);
}

Expand Down Expand Up @@ -586,5 +583,5 @@ pub(crate) struct RawReserveEntry {
}

impl RawReserveEntry {
pub const FIELD_COUNT: usize = size_of::<Self>() / DTB_OPTIMAL_ALIGN;
pub(crate) const FIELD_COUNT: usize = size_of::<Self>() / DTB_OPTIMAL_ALIGN;
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Path for str {

fn as_components(&self) -> Result<Self::ComponentsIter<'_>> {
let mut components = self.split('/');
if components.next() != Some("") || components.clone().next().is_none() {
if self.is_empty() || components.next() != Some("") {
return Err(Error::InvalidPath);
}
if self.len() == 1 {
Expand All @@ -197,6 +197,7 @@ pub struct MemReserveEntry {
///
/// [`Devicetree`]: blob::Devicetree
#[derive(Clone)]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct MemReserveEntries<'dtb> {
blob: &'dtb [u64],
}
Expand Down

0 comments on commit 2cc1e8c

Please sign in to comment.