From 2cc1e8cf4c2c2b659eb7b80e77740e6186f3ee98 Mon Sep 17 00:00:00 2001 From: Kalle Wachsmuth Date: Sun, 3 Nov 2024 20:20:17 +0100 Subject: [PATCH] update lints + minor improvements --- Cargo.toml | 11 +++++++++-- src/alloc.rs | 15 +++++---------- src/blob.rs | 11 ++++------- src/lib.rs | 3 ++- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf4f707..c391eae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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 diff --git a/src/alloc.rs b/src/alloc.rs index fdea3c5..224a4ef 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -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. @@ -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())) diff --git a/src/blob.rs b/src/blob.rs index b564abe..d026d4d 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -53,7 +53,7 @@ pub(crate) struct Header { } impl Header { - pub const SIZE: usize = size_of::(); + pub(crate) const SIZE: usize = size_of::(); } /// Devicetree blob. @@ -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); } @@ -586,5 +583,5 @@ pub(crate) struct RawReserveEntry { } impl RawReserveEntry { - pub const FIELD_COUNT: usize = size_of::() / DTB_OPTIMAL_ALIGN; + pub(crate) const FIELD_COUNT: usize = size_of::() / DTB_OPTIMAL_ALIGN; } diff --git a/src/lib.rs b/src/lib.rs index 76be719..0ad47fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,7 +173,7 @@ impl Path for str { fn as_components(&self) -> Result> { 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 { @@ -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], }