Warn on exhaustive exported enums

Enable clippy::exhaustive_enums in every crate so new exported enums
are either #[non_exhaustive] or explicitly allowed as a closed set.
This commit is contained in:
Olivier Goffart
2026-07-28 14:40:19 +00:00
parent 9c7e191407
commit ea5d7b68c0
17 changed files with 46 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ const PIXEL_SIZE: usize = 4;
/// See [`Window::set_cursor()`][crate::window::Window::set_cursor] for more details.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[allow(clippy::exhaustive_enums)]
pub enum Cursor {
Icon(CursorIcon),
Custom(CustomCursor),

View File

@@ -1107,6 +1107,7 @@ pub enum Ime {
/// Describes touch-screen input state.
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum TouchPhase {
/// Initial touch contact or gesture start, for example when one or more fingers touch the
/// screen or touchpad.
@@ -1126,6 +1127,7 @@ pub enum TouchPhase {
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[doc(alias = "Pressure")]
#[allow(clippy::exhaustive_enums)]
pub enum Force {
/// On iOS, the force is calibrated so that the same number corresponds to
/// roughly the same amount of pressure on the screen regardless of the
@@ -1436,6 +1438,7 @@ impl TabletToolAngle {
/// Describes the input state of a key.
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum ElementState {
Pressed,
Released,
@@ -1466,6 +1469,7 @@ impl ElementState {
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
#[allow(clippy::exhaustive_enums)]
pub enum MouseButton {
/// The primary (usually left) button
Left = 0,
@@ -1561,6 +1565,7 @@ impl MouseButton {
/// Describes a button of a tool, e.g. a pen.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[allow(clippy::exhaustive_enums)]
pub enum TabletToolButton {
Contact,
Barrel,

View File

@@ -415,6 +415,7 @@ impl Eq for OwnedDisplayHandle {}
/// [`Wait`]: Self::Wait
/// [`about_to_wait`]: crate::application::ApplicationHandler::about_to_wait
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
#[allow(clippy::exhaustive_enums)]
pub enum ControlFlow {
/// When the current loop iteration finishes, immediately begin a new iteration regardless of
/// whether or not new events are available to process.
@@ -454,6 +455,7 @@ impl ControlFlow {
/// Control when device events are captured.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum DeviceEvents {
/// Report device events regardless of window focus.
Always,

View File

@@ -108,6 +108,7 @@ pub trait EventLoopExtPumpEvents {
/// The return status for `pump_events`
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[allow(clippy::exhaustive_enums)]
pub enum PumpStatus {
/// Continue running external loop.
Continue,

View File

@@ -169,6 +169,7 @@ impl PartialEq<NativeKeyCode> for NativeKey {
/// emit [`PhysicalKey::Unidentified`] with additional data about the key.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum PhysicalKey {
/// A known key code
Code(KeyCode),
@@ -250,6 +251,7 @@ impl PartialEq<PhysicalKey> for NativeKeyCode {
/// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum Key<Str = SmolStr> {
/// A simple (unparameterised) action
Named(NamedKey),
@@ -447,6 +449,7 @@ impl ModifiersState {
/// [^2]: platform-dependent
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum ModifiersKeyState {
/// The particular modifier is active or logically, but not necessarily physically, pressed.
Pressed,

View File

@@ -7,6 +7,12 @@
//!
//! [`winit`]: https://docs.rs/winit
// Every newly exported enum should either be `#[non_exhaustive]`, or carry an `#[allow]` of
// this lint when the set of variants can never grow.
// `clippy::exhaustive_structs` is deliberately not enabled: event structs must stay
// constructible by the backend crates, which `#[non_exhaustive]` would forbid.
#![warn(clippy::exhaustive_enums)]
#[macro_use]
pub mod as_any;
pub mod cursor;

View File

@@ -1544,6 +1544,7 @@ impl rwh_06::HasWindowHandle for dyn Window + '_ {
/// Use this enum with [`Window::set_cursor_grab`] to grab the cursor.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum CursorGrabMode {
/// No grabbing of the cursor is performed.
None,
@@ -1574,6 +1575,7 @@ pub enum CursorGrabMode {
/// Defines the orientation that a window resize will be performed.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum ResizeDirection {
East,
North,
@@ -1604,6 +1606,7 @@ impl From<ResizeDirection> for CursorIcon {
/// The theme variant to use.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum Theme {
/// Use the light variant.
Light,
@@ -1621,6 +1624,7 @@ pub enum Theme {
/// [`Informational`]: Self::Informational
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum UserAttentionType {
/// ## Platform-specific
///
@@ -1656,6 +1660,7 @@ bitflags::bitflags! {
/// - **iOS / Android / Web / Wayland:** Unsupported.
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(clippy::exhaustive_enums)]
pub enum WindowLevel {
/// The window will always be below normal windows.
///