Skip to content

#279 WP8: clippy lints that keep panics out of the library crates - #319

Merged
samitbasu merged 3 commits into
mainfrom
wp8-lints
Nov 17, 2026
Merged

samitbasu merged 3 commits into
mainfrom
wp8-lints

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Part of #279. Fixes #289.

What

Each library crate (eggshell-ui, eggshell-ui-shadcn, eggshell-ui-extras) denies these lints in its lib.rs, under #![cfg_attr(not(test), deny(...))]: clippy::panic, unwrap_used, expect_used, unreachable, todo, unimplemented, panic_in_result_fn, unwrap_in_result, get_unwrap, string_slice, indexing_slicing, unchecked_time_subtraction, disallowed_macros, disallowed_methods and fn_params_excessive_bools.

clippy.toml:

  • max-fn-params-bools = 1: one bool parameter is allowed, a second is denied.
  • disallowed-macros: assert!, assert_eq!, assert_ne!, debug_assert!, debug_assert_eq! and debug_assert_ne!. The reason text points to report, or to Problem::Internal.
  • disallowed-methods: f32::clamp, f64::clamp and Ord::clamp (use finite::clamp); the Duration methods from_secs_f32, from_secs_f64, mul_f32, mul_f64, div_f32 and div_f64 (use try_from_secs_*); and Mutex::lock (use sync::lock).

Why a crate attribute and not only [lints]: Cargo's lint table applies to every target and can't exempt cfg(test). Integration tests, examples, benches and doctests are separate crates, so the library's attributes don't reach them. Unit tests are exempt through not(test). The two disallowed_* lints warn by default, so [workspace.lints.clippy] sets them to allow (every member uses lints.workspace = true). Without that, tests using assert! would fail under -D warnings. The library crates deny them again in their attributes.

cargo xtask ci already runs clippy --workspace --all-targets -- -D warnings, and the CI workflow runs cargo xtask ci, so neither needed a change.

Hits fixed (no behaviour change)

  • Mutex::lock (3 sites): the lock().unwrap_or_else(PoisonError::into_inner) pattern moved into one helper, src/sync.rs::lock. It is the only place that carries an #[expect].
  • Ord::clamp(4, 32) in shadow_corners::arc_segments now uses finite::clamp. The result is the same; max().min() would trip manual_clamp.
  • delay - waited in tooltip.rs is now delay.saturating_sub(waited). A zero result is the waited >= delay case it replaces.
  • The const _: () = assert!(…) in tw/merge.rs gets an #[expect(clippy::disallowed_macros)], because it fails the build, never a run.
  • fn_params_excessive_bools: 0 hits.

The #[expect(clippy::panic)] exemptions WP7 put in testing.rs and continuity.rs still compile.

Gate check

In a scratch commit that was not pushed, an added Some(1).unwrap() in src/sync.rs made cargo xtask ci fail its clippy step (exit 1) with clippy::unwrap_used, at the lint level set in src/lib.rs.

Adding a justified exemption

Put #[expect(clippy::<lint>, reason = "…")] on the narrowest item or statement that needs it, never on a module or the crate. Use #[expect], not #[allow]: an exemption that is no longer needed then fails the build.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up

samitbasu and others added 3 commits November 17, 2026 10:39
Each library crate (eggshell-ui, eggshell-ui-shadcn, eggshell-ui-extras)
denies, outside cfg(test), clippy's panic, unwrap_used, expect_used,
unreachable, todo, unimplemented, panic_in_result_fn, unwrap_in_result,
get_unwrap, string_slice, indexing_slicing and unchecked_time_subtraction,
plus disallowed_macros and disallowed_methods. clippy.toml disallows the
assert and debug_assert macros, f32/f64/Ord clamp, the panicking Duration
float constructors and arithmetic, and Mutex::lock. The workspace lints
table allows the two disallowed lints, so tests, examples and benches keep
using assertions; only the library crates' attributes deny them.

The remaining hits, fixed without a behaviour change:
- Mutex::lock goes through one poison-tolerant helper, sync::lock, the
  pattern the three call sites already spelled out.
- arc_segments clamps through finite::clamp (constant bounds, same result).
- The tooltip delay subtracts with saturating_sub; zero remaining is the
  waited >= delay case it replaces.
- The compile-time assertion in tw::merge carries an #[expect]: it fails
  the build, never a run.

Fixes #289

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
clippy::fn_params_excessive_bools (pedantic) is denied in the library
crates with max-fn-params-bools = 1: a sole, self-describing bool is
allowed, a second one is not. No function in the libraries has two.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu

Copy link
Copy Markdown
Owner Author

Gate (my run on 9cf9399 merged with main after #318): cargo xtask ci (with fuzz) exits 0. The diff against main is the 15 intended files only, with no stale reverts (TextFace is intact). Merging (the user authorised merges). This completes #279.

@samitbasu
samitbasu merged commit 69aefbf into main Nov 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#279 WP8: clippy lints in cargo xtask ci that keep panics out

1 participant