Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Oct 30, 2024
1 parent 5a3c468 commit 42b71a5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ pub unsafe fn throw<E>(cause: E) -> ! {
///
/// assert_eq!(res, Err("Oops!"));
/// ```
#[expect(clippy::missing_errors_doc)]
#[expect(
clippy::missing_errors_doc,
reason = "`Err` value is described immediately"
)]
#[inline]
pub unsafe fn catch<R, E>(func: impl FnOnce() -> R) -> Result<R, E> {
// SAFETY:
Expand Down Expand Up @@ -169,7 +172,10 @@ impl<E> InFlightException<E> {
/// // SAFETY: g only ever throws Error
/// println!("{}", unsafe { catch::<_, Error>(|| g()) }.unwrap_err());
/// ```
#[expect(clippy::missing_errors_doc)]
#[expect(
clippy::missing_errors_doc,
reason = "`Err` value is described immediately"
)]
#[inline]
pub unsafe fn intercept<R, E>(func: impl FnOnce() -> R) -> Result<R, (E, InFlightException<E>)> {
// SAFETY: Requirements forwarded.
Expand Down
4 changes: 2 additions & 2 deletions src/backend/itanium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unsafe impl ThrowByPointer for ActiveBackend {
unsafe fn throw(ex: *mut Header) -> ! {
// SAFETY: We provide a valid exception header.
unsafe {
#[expect(clippy::used_underscore_items)]
#[expect(clippy::used_underscore_items, reason = "External API")]
_Unwind_RaiseException(ex);
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ unsafe impl ThrowByPointer for ActiveBackend {
// If project-ffi-unwind changes the rustc behavior, we might have to update this
// code.
unsafe {
#[expect(clippy::used_underscore_items)]
#[expect(clippy::used_underscore_items, reason = "External API")]
_Unwind_RaiseException(ex);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
///
/// The user of this trait is allowed to reuse the header when rethrowing exceptions. In particular,
/// the return value of `intercept` may be used as an argument to `throw`.
#[allow(dead_code)]
#[allow(dead_code, reason = "This is only used by some of the backends")]
pub unsafe trait ThrowByPointer {
/// An exception header.
///
Expand Down
2 changes: 1 addition & 1 deletion src/backend/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ unsafe fn cxx_throw(exception_object: *mut ExceptionHeader, throw_info: *const T
RaiseException(
EH_EXCEPTION_NUMBER,
EH_NONCONTINUABLE,
#[expect(clippy::arithmetic_side_effects)]
#[expect(clippy::arithmetic_side_effects, reason = "This is a constant")]
(core::mem::size_of::<ExceptionRecordParameters>() / core::mem::size_of::<usize>())
.try_into()
.unwrap(),
Expand Down
6 changes: 4 additions & 2 deletions src/heterogeneous_stack/align.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub fn assert_aligned<AlignAs>(n: usize) {
// Clippy thinks % can panic here, but the divisor is never 0 and we're working in unsigned
#[expect(clippy::arithmetic_side_effects)]
#[expect(
clippy::arithmetic_side_effects,
reason = "The divisor is never 0 and we're working in unsigned"
)]
let modulo = n % align_of::<AlignAs>();
assert!(modulo == 0, "Unaligned");
}
Expand Down
10 changes: 8 additions & 2 deletions src/heterogeneous_stack/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ impl<AlignAs> Heap<AlignAs> {
/// # Panics
///
/// Panics if `n` is not a multiple of `align_of::<AlignAs>()` or `n` is 0, or if out of memory.
#[expect(clippy::unused_self)]
#[expect(
clippy::unused_self,
reason = "Using a static method is harder in presence of generic parameters"
)]
pub fn alloc(&self, n: usize) -> *mut u8 {
assert_aligned::<AlignAs>(n);
assert_ne!(n, 0, "Allocating 0 bytes is invalid");
Expand All @@ -43,7 +46,10 @@ impl<AlignAs> Heap<AlignAs> {
/// The caller must ensure that the pointer was produced by a call to [`Heap::alloc`] with the
/// same value of `n`. In addition, references to the deallocated memory must not be used after
/// `dealloc` is called.
#[expect(clippy::unused_self)]
#[expect(
clippy::unused_self,
reason = "Using a static method is harder in presence of generic parameters"
)]
pub unsafe fn dealloc(&self, ptr: *mut u8, n: usize) {
// SAFETY: alloc would fail if the preconditions for this weren't established
let layout = unsafe { Layout::from_size_align_unchecked(n, align_of::<AlignAs>()) };
Expand Down
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(thread_local))]
#![cfg_attr(backend = "itanium", expect(internal_features))]
#![cfg_attr(
any(backend = "itanium", backend = "seh"),
expect(
internal_features,
reason = "Can't do anything about core::intrinsics::catch_unwind yet",
)
)]
#![cfg_attr(backend = "itanium", feature(core_intrinsics))]
#![cfg_attr(backend = "seh", feature(core_intrinsics, fn_ptr_trait))]
#![deny(unsafe_op_in_unsafe_fn)]
#![warn(
clippy::cargo,
clippy::pedantic,
clippy::missing_const_for_fn,
clippy::alloc_instead_of_core,
clippy::allow_attributes_without_reason,
clippy::arithmetic_side_effects,
clippy::as_underscore,
clippy::assertions_on_result_states,
Expand All @@ -102,6 +108,7 @@
clippy::inline_asm_x86_att_syntax,
clippy::mem_forget, // use ManuallyDrop instead
clippy::missing_assert_message,
clippy::missing_const_for_fn,
clippy::missing_inline_in_public_items,
clippy::mixed_read_write_in_expression,
clippy::multiple_unsafe_ops_per_block,
Expand Down Expand Up @@ -131,6 +138,10 @@
clippy::unused_result_ok,
clippy::wildcard_enum_match_arm,
)]
#![allow(
clippy::inline_always,
reason = "I'm not an idiot, this is a result of benchmarking/profiling"
)]

extern crate alloc;

Expand Down
1 change: 0 additions & 1 deletion src/stacked_exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ const fn get_alloc_size<E>() -> usize {
}

/// Push an exception onto the thread-local exception stack.
#[expect(clippy::inline_always)]
#[inline(always)]
pub fn push<E>(cause: E) -> *mut Exception<E> {
// SAFETY: We don't let the stack leak past the call frame.
Expand Down

0 comments on commit 42b71a5

Please sign in to comment.