mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-01 04:26:12 +00:00
various clippy lint fixes
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
43a25b7713
commit
def1d54aa6
@ -200,7 +200,7 @@ impl Schema {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_default_property(&mut self, key: &str, value: syn::Expr) {
|
pub fn add_default_property(&mut self, key: &str, value: syn::Expr) {
|
||||||
if !self.find_schema_property(key).is_some() {
|
if self.find_schema_property(key).is_none() {
|
||||||
self.properties.push((Ident::new(key, Span::call_site()), value));
|
self.properties.push((Ident::new(key, Span::call_site()), value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,10 +212,8 @@ fn handle_function_signature(
|
|||||||
// try to infer the type in the schema if it is not specified explicitly:
|
// try to infer the type in the schema if it is not specified explicitly:
|
||||||
let is_option = util::infer_type(schema, &*pat_type.ty)?;
|
let is_option = util::infer_type(schema, &*pat_type.ty)?;
|
||||||
let has_default = schema.find_schema_property("default").is_some();
|
let has_default = schema.find_schema_property("default").is_some();
|
||||||
if !is_option && *optional {
|
if !is_option && *optional && !has_default {
|
||||||
if !has_default {
|
bail!(pat_type => "optional types need a default or be an Option<T>");
|
||||||
bail!(pat_type => "optional types need a default or be an Option<T>");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if has_default && !*optional {
|
if has_default && !*optional {
|
||||||
bail!(pat_type => "non-optional parameter cannot have a default");
|
bail!(pat_type => "non-optional parameter cannot have a default");
|
||||||
|
@ -94,23 +94,21 @@ fn handle_newtype_struct(
|
|||||||
// create "linked" schemas. We cannot do this purely via the macro.
|
// create "linked" schemas. We cannot do this purely via the macro.
|
||||||
|
|
||||||
let mut schema: Schema = attribs.try_into()?;
|
let mut schema: Schema = attribs.try_into()?;
|
||||||
match schema.item {
|
if let SchemaItem::Inferred(_span) = schema.item {
|
||||||
SchemaItem::Inferred(_span) => {
|
// The schema has no `type` and we failed to guess it. Infer it from the contained field!
|
||||||
// The schema has no `type` and we failed to guess it. Infer it from the contained
|
|
||||||
// field!
|
|
||||||
|
|
||||||
let fields = match &stru.fields {
|
let fields = match &stru.fields {
|
||||||
syn::Fields::Unnamed(fields) => &fields.unnamed,
|
syn::Fields::Unnamed(fields) => &fields.unnamed,
|
||||||
_ => panic!("handle_unit_struct on non-unit struct"), // `handle_struct()` verified this!
|
|
||||||
};
|
|
||||||
// this is also part of `handle_struct()`'s verification!
|
|
||||||
assert_eq!(fields.len(), 1, "handle_unit_struct needs a struct with exactly 1 field");
|
|
||||||
|
|
||||||
// Now infer the type information:
|
// `handle_struct()` verified this!
|
||||||
util::infer_type(&mut schema, &fields[0].ty)?;
|
_ => panic!("handle_unit_struct on non-unit struct"),
|
||||||
}
|
};
|
||||||
_ => (),
|
// this is also part of `handle_struct()`'s verification!
|
||||||
};
|
assert_eq!(fields.len(), 1, "handle_unit_struct needs a struct with exactly 1 field");
|
||||||
|
|
||||||
|
// Now infer the type information:
|
||||||
|
util::infer_type(&mut schema, &fields[0].ty)?;
|
||||||
|
}
|
||||||
|
|
||||||
get_struct_description(&mut schema, &stru)?;
|
get_struct_description(&mut schema, &stru)?;
|
||||||
|
|
||||||
|
@ -105,6 +105,11 @@ pub trait ReadExt {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This should only used for types with a defined storage representation, usually
|
||||||
|
/// `#[repr(C)]`, otherwise the results may be inconsistent.
|
||||||
|
///
|
||||||
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
||||||
unsafe fn read_host_value<T: Endian>(&mut self) -> io::Result<T>;
|
unsafe fn read_host_value<T: Endian>(&mut self) -> io::Result<T>;
|
||||||
|
|
||||||
@ -137,6 +142,11 @@ pub trait ReadExt {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This should only used for types with a defined storage representation, usually
|
||||||
|
/// `#[repr(C)]`, otherwise the results may be inconsistent.
|
||||||
|
///
|
||||||
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
||||||
unsafe fn read_le_value<T: Endian>(&mut self) -> io::Result<T>;
|
unsafe fn read_le_value<T: Endian>(&mut self) -> io::Result<T>;
|
||||||
|
|
||||||
@ -169,6 +179,11 @@ pub trait ReadExt {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This should only used for types with a defined storage representation, usually
|
||||||
|
/// `#[repr(C)]`, otherwise the results may be inconsistent.
|
||||||
|
///
|
||||||
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
||||||
unsafe fn read_be_value<T: Endian>(&mut self) -> io::Result<T>;
|
unsafe fn read_be_value<T: Endian>(&mut self) -> io::Result<T>;
|
||||||
|
|
||||||
@ -201,6 +216,11 @@ pub trait ReadExt {
|
|||||||
/// # }
|
/// # }
|
||||||
/// # code(&input[..]).unwrap();
|
/// # code(&input[..]).unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This should only used for types with a defined storage representation, usually
|
||||||
|
/// `#[repr(C)]`, otherwise the results may be inconsistent.
|
||||||
unsafe fn read_host_value_boxed<T>(&mut self) -> io::Result<Box<T>>;
|
unsafe fn read_host_value_boxed<T>(&mut self) -> io::Result<Box<T>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,11 @@ pub trait WriteExt {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This should only used for types with a defined storage representation, usually
|
||||||
|
/// `#[repr(C)]`, otherwise the results may be inconsistent.
|
||||||
|
///
|
||||||
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
||||||
unsafe fn write_host_value<T: Endian>(&mut self, value: T) -> io::Result<()>;
|
unsafe fn write_host_value<T: Endian>(&mut self, value: T) -> io::Result<()>;
|
||||||
|
|
||||||
@ -108,6 +113,11 @@ pub trait WriteExt {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This should only used for types with a defined storage representation, usually
|
||||||
|
/// `#[repr(C)]`, otherwise the results may be inconsistent.
|
||||||
|
///
|
||||||
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
||||||
unsafe fn write_le_value<T: Endian>(&mut self, value: T) -> io::Result<()>;
|
unsafe fn write_le_value<T: Endian>(&mut self, value: T) -> io::Result<()>;
|
||||||
|
|
||||||
@ -146,6 +156,11 @@ pub trait WriteExt {
|
|||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This should only used for types with a defined storage representation, usually
|
||||||
|
/// `#[repr(C)]`, otherwise the results may be inconsistent.
|
||||||
|
///
|
||||||
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
/// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html
|
||||||
unsafe fn write_be_value<T: Endian>(&mut self, value: T) -> io::Result<()>;
|
unsafe fn write_be_value<T: Endian>(&mut self, value: T) -> io::Result<()>;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,11 @@ unsafe impl<T> Send for Mmap<T> where T: Send {}
|
|||||||
unsafe impl<T> Sync for Mmap<T> where T: Sync {}
|
unsafe impl<T> Sync for Mmap<T> where T: Sync {}
|
||||||
|
|
||||||
impl<T> Mmap<T> {
|
impl<T> Mmap<T> {
|
||||||
|
/// Map a file into memory.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// `fd` must refer to a valid file descriptor.
|
||||||
pub unsafe fn map_fd(
|
pub unsafe fn map_fd(
|
||||||
fd: RawFd,
|
fd: RawFd,
|
||||||
ofs: u64,
|
ofs: u64,
|
||||||
@ -25,6 +30,8 @@ impl<T> Mmap<T> {
|
|||||||
flags: mman::MapFlags,
|
flags: mman::MapFlags,
|
||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
let byte_len = count * mem::size_of::<T>();
|
let byte_len = count * mem::size_of::<T>();
|
||||||
|
// libc::size_t vs usize
|
||||||
|
#[allow(clippy::useless_conversion)]
|
||||||
let data = mman::mmap(
|
let data = mman::mmap(
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
libc::size_t::try_from(byte_len).map_err(io_err_other)?,
|
libc::size_t::try_from(byte_len).map_err(io_err_other)?,
|
||||||
|
@ -119,7 +119,7 @@ pub mod string_as_base64 {
|
|||||||
use base64;
|
use base64;
|
||||||
use serde::{Deserialize, Deserializer, Serializer};
|
use serde::{Deserialize, Deserializer, Serializer};
|
||||||
|
|
||||||
pub fn serialize<S>(data: &String, serializer: S) -> Result<S::Ok, S::Error>
|
pub fn serialize<S>(data: &str, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ pub fn localtime(epoch: i64) -> Result<libc::tm, Error> {
|
|||||||
let mut result = new_libc_tm();
|
let mut result = new_libc_tm();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if libc::localtime_r(&epoch, &mut result) == std::ptr::null_mut() {
|
if libc::localtime_r(&epoch, &mut result).is_null() {
|
||||||
bail!("libc::localtime failed for '{}'", epoch);
|
bail!("libc::localtime failed for '{}'", epoch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ pub fn gmtime(epoch: i64) -> Result<libc::tm, Error> {
|
|||||||
let mut result = new_libc_tm();
|
let mut result = new_libc_tm();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if libc::gmtime_r(&epoch, &mut result) == std::ptr::null_mut() {
|
if libc::gmtime_r(&epoch, &mut result).is_null() {
|
||||||
bail!("libc::gmtime failed for '{}'", epoch);
|
bail!("libc::gmtime failed for '{}'", epoch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,12 @@ pub use byte_vec::*;
|
|||||||
/// v.set_len(len);
|
/// v.set_len(len);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// It's generally not unsafe to use this method, but the contents are uninitialized, and since
|
||||||
|
/// this does not return a `MaybeUninit` type to track the initialization state, this is simply
|
||||||
|
/// marked as unsafe for good measure.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn uninitialized(len: usize) -> Vec<u8> {
|
pub unsafe fn uninitialized(len: usize) -> Vec<u8> {
|
||||||
let mut out = Vec::with_capacity(len);
|
let mut out = Vec::with_capacity(len);
|
||||||
|
@ -64,6 +64,12 @@ pub trait ByteVecExt {
|
|||||||
/// file.append_to_vec(&mut buffer, 1024)?;
|
/// file.append_to_vec(&mut buffer, 1024)?;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// When increasing the size, the new contents are uninitialized and have nothing to do with
|
||||||
|
/// the previously contained content. Since we cannot track this state through the type system,
|
||||||
|
/// this method is marked as an unsafe API for good measure.
|
||||||
|
///
|
||||||
/// [`ReadExt`]: crate::io::ReadExt
|
/// [`ReadExt`]: crate::io::ReadExt
|
||||||
unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8];
|
unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8];
|
||||||
|
|
||||||
@ -77,6 +83,12 @@ pub trait ByteVecExt {
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// When increasing the size, the new contents are uninitialized and have nothing to do with
|
||||||
|
/// the previously contained content. Since we cannot track this state through the type system,
|
||||||
|
/// this method is marked as an unsafe API for good measure.
|
||||||
unsafe fn resize_uninitialized(&mut self, total: usize);
|
unsafe fn resize_uninitialized(&mut self, total: usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user