Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ wasm-bindgen-futures = "0.4"
[workspace]
members = ["crates/eggshell-ui-shadcn", "crates/eggshell-ui-extras", "xtask"]

# clippy.toml's disallowed macros and methods are denied in library code by
# each library's crate attributes; tests, examples and benches may use them.
[workspace.lints.clippy]
disallowed_macros = "allow"
disallowed_methods = "allow"

[lints]
workspace = true

# `cargo xtask fuzz`: the sessions run about six times faster than in dev, and
# the workspace rebuilds in seconds where release takes minutes.
[profile.fuzz]
Expand Down
22 changes: 22 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
max-fn-params-bools = 1

disallowed-macros = [
{ path = "std::assert", reason = "a failed assertion panics: report misuse with `report`, or an invariant as `Problem::Internal`, and fall back" },
{ path = "std::assert_eq", reason = "a failed assertion panics: report misuse with `report`, or an invariant as `Problem::Internal`, and fall back" },
{ path = "std::assert_ne", reason = "a failed assertion panics: report misuse with `report`, or an invariant as `Problem::Internal`, and fall back" },
{ path = "std::debug_assert", reason = "a failed assertion panics in debug builds: report misuse with `report`, or an invariant as `Problem::Internal`, and fall back" },
{ path = "std::debug_assert_eq", reason = "a failed assertion panics in debug builds: report misuse with `report`, or an invariant as `Problem::Internal`, and fall back" },
{ path = "std::debug_assert_ne", reason = "a failed assertion panics in debug builds: report misuse with `report`, or an invariant as `Problem::Internal`, and fall back" },
]
disallowed-methods = [
{ path = "f32::clamp", reason = "panics on reversed or NaN bounds: use `finite::clamp`" },
{ path = "f64::clamp", reason = "panics on reversed or NaN bounds: use `finite::clamp`" },
{ path = "core::cmp::Ord::clamp", reason = "panics on reversed bounds: use `finite::clamp`" },
{ path = "core::time::Duration::from_secs_f32", reason = "panics on a negative, NaN or overflowing value: use `Duration::try_from_secs_f32`" },
{ path = "core::time::Duration::from_secs_f64", reason = "panics on a negative, NaN or overflowing value: use `Duration::try_from_secs_f64`" },
{ path = "core::time::Duration::mul_f32", reason = "panics on a negative, NaN or overflowing result: use `Duration::try_from_secs_f32` on the product" },
{ path = "core::time::Duration::mul_f64", reason = "panics on a negative, NaN or overflowing result: use `Duration::try_from_secs_f64` on the product" },
{ path = "core::time::Duration::div_f32", reason = "panics on a negative, NaN or overflowing result: use `Duration::try_from_secs_f32` on the quotient" },
{ path = "core::time::Duration::div_f64", reason = "panics on a negative, NaN or overflowing result: use `Duration::try_from_secs_f64` on the quotient" },
{ path = "std::sync::Mutex::lock", reason = "use `sync::lock`, which takes the guard back from a poisoned lock" },
]
3 changes: 3 additions & 0 deletions crates/eggshell-ui-extras/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ pulldown-cmark = { version = "0.13.6", default-features = false, optional = true

[package.metadata.docs.rs]
all-features = true

[lints]
workspace = true
20 changes: 20 additions & 0 deletions crates/eggshell-ui-extras/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
#![cfg_attr(
not(test),
deny(
clippy::panic,
clippy::unwrap_used,
clippy::expect_used,
clippy::unreachable,
clippy::todo,
clippy::unimplemented,
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::get_unwrap,
clippy::string_slice,
clippy::indexing_slicing,
clippy::unchecked_time_subtraction,
clippy::disallowed_macros,
clippy::disallowed_methods,
clippy::fn_params_excessive_bools
)
)]
//! TODO(prose)

#[cfg(feature = "markdown")]
Expand Down
3 changes: 3 additions & 0 deletions crates/eggshell-ui-shadcn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ extras = ["dep:eggshell-ui-extras", "eggshell-ui-extras/markdown"]
eggshell-ui = { path = "../..", version = "0.1.0" }
egui = "0.37"
eggshell-ui-extras = { path = "../eggshell-ui-extras", version = "0.1.0", optional = true }

[lints]
workspace = true
20 changes: 20 additions & 0 deletions crates/eggshell-ui-shadcn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#![deny(missing_docs)]
#![cfg_attr(
not(test),
deny(
clippy::panic,
clippy::unwrap_used,
clippy::expect_used,
clippy::unreachable,
clippy::todo,
clippy::unimplemented,
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::get_unwrap,
clippy::string_slice,
clippy::indexing_slicing,
clippy::unchecked_time_subtraction,
clippy::disallowed_macros,
clippy::disallowed_methods,
clippy::fn_params_excessive_bools
)
)]
//! The shadcn/ui design system as a [`eggshell_ui::Style`].
//!
//! [`Shadcn`] is a preset: a [`ShadcnStyle`] (which of shadcn's styles, such as
Expand Down
4 changes: 2 additions & 2 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct System;
not(any(target_arch = "wasm32", target_os = "android", target_os = "ios"))
))]
mod system {
use std::sync::{Mutex, OnceLock, PoisonError};
use std::sync::{Mutex, OnceLock};

use egui::{Color32, ColorImage};

Expand All @@ -171,7 +171,7 @@ mod system {
fn with<R>(
f: impl FnOnce(&mut arboard::Clipboard) -> Result<R, arboard::Error>,
) -> Result<R, ClipboardError> {
let mut guard = handle().lock().unwrap_or_else(PoisonError::into_inner);
let mut guard = crate::sync::lock(handle());
let clipboard = guard.as_mut().ok_or(ClipboardError::Unavailable)?;
f(clipboard).map_err(|error| match error {
arboard::Error::ClipboardNotSupported => ClipboardError::Unavailable,
Expand Down
4 changes: 2 additions & 2 deletions src/kept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! own (focus, text-edit memory, the clock) in its context, and diagnostics
//! (the debug overlay, the continuity recorder) are context-wide by design.

use std::sync::{Arc, Mutex, PoisonError};
use std::sync::{Arc, Mutex};

use std::collections::HashMap;

Expand Down Expand Up @@ -73,7 +73,7 @@ pub(crate) struct Handle(Arc<Mutex<Kept>>);

impl Handle {
pub(crate) fn with<R>(&self, f: impl FnOnce(&mut Kept) -> R) -> R {
f(&mut self.0.lock().unwrap_or_else(PoisonError::into_inner))
f(&mut crate::sync::lock(&self.0))
}

/// [`with`](Self::with) what is kept for `viewport`.
Expand Down
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#![deny(missing_docs)]
#![cfg_attr(
not(test),
deny(
clippy::panic,
clippy::unwrap_used,
clippy::expect_used,
clippy::unreachable,
clippy::todo,
clippy::unimplemented,
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::get_unwrap,
clippy::string_slice,
clippy::indexing_slicing,
clippy::unchecked_time_subtraction,
clippy::disallowed_macros,
clippy::disallowed_methods,
clippy::fn_params_excessive_bools
)
)]
//! Eggshell: taffy lays out, egui draws and interacts.
//!
//! The application owns its state; every frame rebuilds the interface from
Expand Down Expand Up @@ -369,6 +389,7 @@ mod sizing;
mod spans;
mod stack;
mod symbols;
mod sync;
pub mod testing;
mod text;
mod tooltip;
Expand Down
6 changes: 5 additions & 1 deletion src/shadow_corners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ impl Corner {
/// How many fan segments make a corner arc whose chords stay well under a
/// physical pixel from the arc.
pub(crate) fn arc_segments(radius: f32, pixels_per_point: f32) -> usize {
((radius * pixels_per_point.max(1.0) * 0.5).ceil() as usize).clamp(4, 32)
crate::finite::clamp(
(radius * pixels_per_point.max(1.0) * 0.5).ceil() as usize,
4,
32,
)
}

/// Triangles covering the region inside `rect`, outside the quarter-circle
Expand Down
14 changes: 14 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Locking that survives a panic on another thread.

use std::sync::{Mutex, MutexGuard, PoisonError};

/// The guard of `mutex`, taken back from the poison a panic while it was held
/// leaves: the data it guards is the library's own state, which every writer
/// leaves consistent between statements.
#[expect(
clippy::disallowed_methods,
reason = "the one place a mutex is locked, recovering from poison"
)]
pub(crate) fn lock<T>(mutex: &Mutex<T>) -> MutexGuard<'_, T> {
mutex.lock().unwrap_or_else(PoisonError::into_inner)
}
4 changes: 1 addition & 3 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,7 @@ struct FakeState {

impl FakeClipboard {
fn state(&self) -> std::sync::MutexGuard<'_, FakeState> {
self.0
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
crate::sync::lock(&self.0)
}

/// Puts `text` on the clipboard, leaving an image there as it is.
Expand Down
6 changes: 3 additions & 3 deletions src/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ impl Tooltips {
Cause::Pointer if self.in_grace(now, timing.grace) => Duration::ZERO,
Cause::Pointer => timing.delay,
};
let waited = now.saturating_sub(since);
if waited >= delay {
let remaining = delay.saturating_sub(now.saturating_sub(since));
if remaining.is_zero() {
self.open(trigger, now);
self.waiting = None;
None
} else {
Some(delay - waited)
Some(remaining)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tw/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ macro_rules! layout_properties {
Opacity,
}

#[expect(clippy::disallowed_macros, reason = "a const assertion fails the build, not a run")]
const _: () = assert!((Property::Opacity as u32) < 64);

impl Layout<'_> {
Expand Down
3 changes: 3 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ duct = "1.1.2"

[target.'cfg(unix)'.dependencies]
libc = "0.2.191"

[lints]
workspace = true
Loading