Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Oct 9, 2023
1 parent b53c9cf commit 844a391
Show file tree
Hide file tree
Showing 24 changed files with 50 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: ['1.66', stable]
rust: ['1.72', stable]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.68
- uses: dtolnay/rust-toolchain@1.72
with:
components: clippy
- run: cargo clippy --all-targets -- -D warnings
Expand Down
2 changes: 1 addition & 1 deletion crates/musli-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-common"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
Common utilities shared among Müsli encodings.
"""
Expand Down
4 changes: 2 additions & 2 deletions crates/musli-common/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub use self::no_std::NoStd;
mod default_alloc {
#![allow(missing_docs)]

#[cfg(all(feature = "alloc"))]
#[cfg(feature = "alloc")]
pub type Default = super::Alloc;
#[cfg(all(not(feature = "alloc")))]
#[cfg(not(feature = "alloc"))]
pub type Default = super::NoStd<1024>;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/musli-common/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn from_utf8_owned(bytes: Vec<u8>) -> Result<String, Utf8Error> {
#[inline(always)]
#[cfg(all(feature = "alloc", feature = "simdutf8"))]
pub fn from_utf8_owned(bytes: Vec<u8>) -> Result<String, Utf8Error> {
if let Err(..) = from_utf8(&bytes) {
if from_utf8(&bytes).is_err() {
return Err(Utf8Error);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/musli-descriptive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-descriptive"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
A fully self-descriptive format for Müsli.
"""
Expand Down
4 changes: 1 addition & 3 deletions crates/musli-descriptive/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ where
{
#[inline]
fn clone(&self) -> Self {
Self {
_marker: marker::PhantomData,
}
*self
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/musli-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-json"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
JSON support for Müsli.
"""
Expand Down
4 changes: 1 addition & 3 deletions crates/musli-json/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ where
impl<M> Clone for Encoding<M> {
#[inline]
fn clone(&self) -> Self {
Self {
_marker: marker::PhantomData,
}
*self
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/musli-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-macros"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
Macros for Müsli.
"""
Expand Down
2 changes: 1 addition & 1 deletion crates/musli-macros/src/zero_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a> Expander<'a> {
pub fn expand(&self) -> Result<TokenStream, Vec<syn::Error>> {
let cx = Ctxt::default();

let Ok(output) = expand(&cx, &self.input) else {
let Ok(output) = expand(&cx, self.input) else {
return Err(cx.errors.into_inner());
};

Expand Down
2 changes: 1 addition & 1 deletion crates/musli-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-storage"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
Partially upgrade stable format for Müsli suitable for storage.
"""
Expand Down
4 changes: 1 addition & 3 deletions crates/musli-storage/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ where
{
#[inline]
fn clone(&self) -> Self {
Self {
_marker: marker::PhantomData,
}
*self
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/musli-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-tests"
version = "0.0.3"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
Müsli is a flexible and generic binary serialization framework.
"""
Expand Down
2 changes: 1 addition & 1 deletion crates/musli-value/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-value"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
Buffered value support for Müsli.
"""
Expand Down
2 changes: 1 addition & 1 deletion crates/musli-wire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli-wire"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
Fully upgrade stable format for Müsli suitable for network communication.
"""
Expand Down
4 changes: 1 addition & 3 deletions crates/musli-wire/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ where
{
#[inline]
fn clone(&self) -> Self {
Self {
_marker: marker::PhantomData,
}
*self
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/musli-zerocopy/examples/insert_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use musli_zerocopy::{Error, OwnedBuf};
fn main() -> Result<(), Error> {
let mut buf = OwnedBuf::new();

let mut values = Vec::new();

values.push(buf.insert_unsized("first")?);
values.push(buf.insert_unsized("second")?);
let values = vec![buf.insert_unsized("first")?, buf.insert_unsized("second")?];

let slice_ref = buf.insert_slice(&values)?;

Expand Down
14 changes: 12 additions & 2 deletions crates/musli-zerocopy/src/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ where
}

/// Trait used for loading any kind of reference.
///
/// # Safety
///
/// This can only be implemented by types under certain conditions:
/// * The type has a strict, well-defined layout or is `repr(C)`.
pub unsafe trait AnyRef {
/// The target being read.
type Target: ?Sized;
Expand All @@ -52,7 +57,7 @@ pub unsafe trait AnyRef {

/// Trait used for handling any kind of zero copy value, be they references or
/// not.
pub unsafe trait AnyValue {
pub trait AnyValue {
/// The target being read.
type Target: ?Sized;

Expand All @@ -62,7 +67,7 @@ pub unsafe trait AnyValue {
V: FnOnce(&Self::Target) -> O;
}

unsafe impl<T: ?Sized> AnyValue for T
impl<T: ?Sized> AnyValue for T
where
T: AnyRef,
{
Expand Down Expand Up @@ -174,6 +179,11 @@ impl Buf {
self.data.len()
}

/// Test if the current buffer is empty.
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}

/// Get the given range while checking its required alignment.
pub fn get(&self, range: Range<usize>, align: usize) -> Result<&Buf, Error> {
let Some(data) = self.data.get(range.clone()) else {
Expand Down
10 changes: 5 additions & 5 deletions crates/musli-zerocopy/src/map/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ pub(crate) struct HashState {
pub(crate) map: Vec<usize>,
}

pub(crate) fn generate_hash<'a, K, V>(buf: &Buf, entries: &[Pair<K, V>]) -> Result<HashState, Error>
pub(crate) fn generate_hash<K, V>(buf: &Buf, entries: &[Pair<K, V>]) -> Result<HashState, Error>
where
K: AnyValue,
K::Target: Hash,
{
for key in SmallRng::seed_from_u64(FIXED_SEED).sample_iter(Standard) {
if let Some(hash) = try_generate_hash(buf, &entries, key)? {
if let Some(hash) = try_generate_hash(buf, entries, key)? {
return Ok(hash);
}
}

Err(Error::new(ErrorKind::FailedPhf))
}

fn try_generate_hash<'a, K, V>(
fn try_generate_hash<K, V>(
buf: &Buf,
entries: &[Pair<K, V>],
key: HashKey,
Expand All @@ -62,11 +62,11 @@ where
let mut buckets = vec![Vec::<usize>::new(); buckets_len];

for (index, hash) in hashes.iter().enumerate() {
let to = hash.g as usize % buckets.len();
let to = hash.g % buckets.len();
buckets[to].push(index);
}

buckets.sort_by(|a, b| b.len().cmp(&a.len()));
buckets.sort_by_key(|a| a.len());

let table_len = hashes.len();
let mut map = vec![usize::MAX; table_len];
Expand Down
5 changes: 1 addition & 4 deletions crates/musli-zerocopy/src/ref_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ unsafe impl<T> ZeroCopy for Ref<T> {
impl<T> Clone for Ref<T> {
#[inline]
fn clone(&self) -> Self {
Self {
ptr: self.ptr,
_marker: PhantomData,
}
*self
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/musli-zerocopy/src/slice_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ unsafe impl<T> ZeroCopy for SliceRef<T> {

impl<T> Clone for SliceRef<T> {
fn clone(&self) -> Self {
Self {
ptr: self.ptr,
len: self.len,
_marker: PhantomData,
}
*self
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/musli-zerocopy/src/unsized_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ unsafe impl<T: ?Sized> ZeroCopy for UnsizedRef<T> {

impl<T: ?Sized> Clone for UnsizedRef<T> {
fn clone(&self) -> Self {
Self {
ptr: self.ptr,
len: self.len,
_marker: PhantomData,
}
*self
}
}

Expand Down
11 changes: 10 additions & 1 deletion crates/musli-zerocopy/src/zero_copy.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::len_without_is_empty)]

use core::alloc::Layout;
use core::mem;
use core::str;
Expand All @@ -6,6 +8,13 @@ use crate::buf::{AnyValue, Buf, BufMut};
use crate::error::{Error, ErrorKind};

/// Trait governing how to write an unsized buffer.
///
/// # Safety
///
/// This can only be implemented correctly by types under certain conditions:
/// * The type has a strict, well-defined layout or is `repr(C)`.
/// * The base type has a statically known alignment, such as how `[u32]` is
/// aligned on 4 bytes.
pub unsafe trait UnsizedZeroCopy {
/// Alignment of the pointed to data. We can only support unsized types
/// which have a known alignment.
Expand Down Expand Up @@ -124,7 +133,7 @@ macro_rules! impl_number {
}
}

unsafe impl AnyValue for $ty {
impl AnyValue for $ty {
type Target = $ty;

fn visit<V, O>(&self, _: &Buf, visitor: V) -> Result<O, Error>
Expand Down
2 changes: 1 addition & 1 deletion crates/musli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "musli"
version = "0.0.49"
authors = ["John-John Tedro <udoprog@tedro.se>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
description = """
Müsli is a flexible and generic binary serialization framework.
"""
Expand Down

0 comments on commit 844a391

Please sign in to comment.