clippy fixes

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-12-15 10:38:53 +01:00
parent 86f538fe3f
commit e5a46a38ef
7 changed files with 24 additions and 8 deletions

View File

@ -227,7 +227,7 @@ impl serde::Serialize for Array {
use serde::ser::SerializeSeq;
if raw_value::is_enabled() {
return raw_value::serialize_raw(&self, serializer);
return raw_value::serialize_raw(self, serializer);
}
let mut seq = serializer.serialize_seq(Some(self.len()))?;

View File

@ -508,7 +508,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
value: None,
})
} else {
return Error::fail("expected an enum value");
Error::fail("expected an enum value")
}
}
_ => unreachable!(),
@ -536,7 +536,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
}),
}
}
_ => return Error::fail("expected a string or hash for an enum"),
_ => Error::fail("expected a string or hash for an enum"),
}
}

View File

@ -39,6 +39,7 @@ pub struct MAGIC {
_ffi: usize,
}
#[allow(clippy::len_without_is_empty)]
impl MAGIC {
pub fn vtbl(&self) -> Option<&MGVTBL> {
unsafe { RSPL_MAGIC_virtual(self as *const MAGIC).as_ref() }
@ -187,7 +188,7 @@ impl MGVTBL {
/// This must not be deallocated as long as it is attached to a perl value, so best use this as
/// `const` variables, rather than dynamically allocating it.
pub const fn zero() -> Self {
*&Self::EMPTY
Self::EMPTY
}
}

View File

@ -207,7 +207,7 @@ impl serde::Serialize for Hash {
use serde::ser::SerializeMap;
if raw_value::is_enabled() {
return raw_value::serialize_raw(&self, serializer);
return raw_value::serialize_raw(self, serializer);
}
let mut map = serializer.serialize_map(Some(self.len()))?;

View File

@ -75,8 +75,23 @@ use crate::ScalarRef;
/// balance out reference counts, and so forth.
pub unsafe trait Leakable {
type Pointee;
/// Leak this value as a pointer.
fn leak(self) -> *const libc::c_char;
/// Reclaim a value from a pointer.
///
/// # Safety
///
/// This must only be called *once* on values previously created by calling [`get_ref`] on a
/// value obtained from [`leak`].
/// Implementors must ensure that it is always safe to call this exactly *once* on *each*
/// leaked value.
///
/// [`get_ref`]: Leakable::get_ref
/// [`leak`]: Leakable::leak
unsafe fn reclaim(ptr: &Self::Pointee) -> Self;
fn get_ref<'a>(ptr: *const libc::c_char) -> Option<&'a Self::Pointee> {
unsafe { (ptr as *const Self::Pointee).as_ref() }
}

View File

@ -439,7 +439,7 @@ impl ScalarRef {
/// Attach a magic tag to this value. This is a more convenient alternative to using
/// [`add_raw_magic`](ScalarRef::add_raw_magic()) manually.
pub fn add_magic<'spec, 'o, T: Leakable>(&self, spec: MagicValue<'spec, 'o, 'static, T>) {
pub fn add_magic<T: Leakable>(&self, spec: MagicValue<'_, '_, 'static, T>) {
unsafe {
self.add_raw_magic(
spec.spec.obj,
@ -552,7 +552,7 @@ impl serde::Serialize for Scalar {
use serde::ser::Error;
if raw_value::is_enabled() {
return raw_value::serialize_raw(&self, serializer);
return raw_value::serialize_raw(self, serializer);
}
match self.ty() {

View File

@ -460,7 +460,7 @@ impl Serialize for Value {
use serde::ser::Error;
if raw_value::is_enabled() {
raw_value::serialize_raw(&self, serializer)
raw_value::serialize_raw(self, serializer)
} else {
match self {
Value::Scalar(this) => this.serialize(serializer),