Skip to content

Commit c771200

Browse files
committed
Add #[non_exhaustive] to most public enums
Additionally, utilizes the `clippy::exhaustive_enums` lint to prevent new exhaustive ones from appearing in the public interface. This makes it non-breaking to add new variants to enums that aren't intended to be exhaustively matched on.
1 parent 91e1b77 commit c771200

File tree

13 files changed

+37
-2
lines changed

13 files changed

+37
-2
lines changed

gdnative-async/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//!
77
//! This crate assumes that all user non-Rust code follow the official threading guidelines.
88
9+
#![warn(clippy::exhaustive_enums)]
10+
911
// Workaround for macros that expect the `gdnative` crate.
1012
extern crate gdnative_core as gdnative;
1113

gdnative-core/src/core_types/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::sys;
55
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
66
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
77
#[repr(u32)]
8+
#[non_exhaustive]
89
pub enum GodotError {
910
Failed = sys::godot_error_GODOT_FAILED as u32,
1011
Unavailable = sys::godot_error_GODOT_ERR_UNAVAILABLE as u32,

gdnative-core/src/core_types/geom/rect2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pub struct MarginError(i64);
267267
///
268268
/// [margin]: https://docs.godotengine.org/en/stable/classes/class_%40globalscope.html#enum-globalscope-margin
269269
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
270+
#[non_exhaustive]
270271
pub enum Margin {
271272
Left,
272273
Top,

gdnative-core/src/core_types/string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ pub struct GodotChar(libc::wchar_t);
390390

391391
/// Error indicating that a `GodotChar` cannot be converted to a `char`.
392392
#[derive(Debug)]
393+
#[non_exhaustive]
393394
pub enum GodotCharError {
394395
/// The character cannot be represented as a Unicode code point.
395396
InvalidCodePoint,

gdnative-core/src/core_types/variant.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ macro_rules! decl_variant_type {
8181
) => {
8282
#[repr(u32)]
8383
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
84+
#[non_exhaustive]
8485
pub enum VariantType {
8586
$(
8687
$variant = $c_const as u32,
@@ -99,6 +100,7 @@ macro_rules! decl_variant_type {
99100
/// For `Variant`s containing objects, the original `Variant` is returned unchanged, due to
100101
/// the limitations of statically-determined memory management.
101102
#[repr(u32)]
103+
#[non_exhaustive]
102104
pub enum VariantDispatch {
103105
$(
104106
$variant $( ($inner) )?,
@@ -186,6 +188,7 @@ impl VariantType {
186188
#[allow(clippy::unnecessary_cast)] // False positives: casts necessary for cross-platform
187189
#[repr(u32)]
188190
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
191+
#[non_exhaustive]
189192
pub enum CallError {
190193
InvalidMethod =
191194
sys::godot_variant_call_error_error_GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD as u32,
@@ -236,6 +239,7 @@ impl std::error::Error for CallError {}
236239
#[allow(clippy::unnecessary_cast)] // False positives: casts necessary for cross-platform
237240
#[repr(u32)]
238241
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
242+
#[non_exhaustive]
239243
pub enum VariantOperator {
240244
// Comparison
241245
Equal = sys::godot_variant_operator_GODOT_VARIANT_OP_EQUAL as u32,
@@ -856,6 +860,7 @@ pub trait CoerceFromVariant: Sized + private::Sealed {
856860
}
857861

858862
#[derive(Clone, PartialEq, Eq, Debug)]
863+
#[non_exhaustive]
859864
/// Error type returned by `FromVariant::from_variant`.
860865
pub enum FromVariantError {
861866
/// An unspecified error.
@@ -924,11 +929,13 @@ pub enum FromVariantError {
924929
}
925930

926931
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
932+
#[non_exhaustive]
927933
pub enum VariantEnumRepr {
928934
ExternallyTagged,
929935
}
930936

931937
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
938+
#[non_exhaustive]
932939
pub enum VariantStructRepr {
933940
Unit,
934941
Tuple,

gdnative-core/src/core_types/vector3.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ pub struct Vector3 {
1515
pub z: f32,
1616
}
1717

18-
#[allow(clippy::unnecessary_cast)] // False positives: casts necessary for cross-platform
18+
#[allow(
19+
clippy::unnecessary_cast, // False positives: casts necessary for cross-platform
20+
clippy::exhaustive_enums, // explicitly exhaustive since there can't be more axes for Vector3
21+
)]
1922
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2023
#[repr(u32)]
2124
pub enum Axis {

gdnative-core/src/export/method.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type ScriptMethodFn = unsafe extern "C" fn(
9797
) -> sys::godot_variant;
9898

9999
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
100+
#[non_exhaustive]
100101
pub enum RpcMode {
101102
Disabled,
102103
Remote,
@@ -483,6 +484,7 @@ varargs_into_tuple!(A, B, C, D, E, F, G, H, I, J, K, L);
483484
/// For methods that return this error, see [`Varargs::check_length()`], [`Varargs::get()`] or [`Varargs::get_opt()`].
484485
/// Another context where this type is used is when destructuring `Varargs` into tuples.
485486
#[derive(Debug)]
487+
#[non_exhaustive]
486488
pub enum VarargsError {
487489
/// At least one argument type mismatches.
488490
InvalidArgumentType {

gdnative-core/src/export/property/hint.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ impl EnumHint {
145145

146146
/// Possible hints for integers.
147147
#[derive(Clone, Debug)]
148+
#[non_exhaustive]
148149
pub enum IntHint<T> {
149150
/// Hints that an integer or float property should be within a range.
150151
Range(RangeHint<T>),
@@ -260,6 +261,7 @@ impl ExpEasingHint {
260261

261262
/// Possible hints for floats.
262263
#[derive(Clone, Debug)]
264+
#[non_exhaustive]
263265
pub enum FloatHint<T> {
264266
/// Hints that an integer or float property should be within a range.
265267
Range(RangeHint<T>),
@@ -325,6 +327,7 @@ impl<T> From<ExpEasingHint> for FloatHint<T> {
325327

326328
/// Possible hints for strings.
327329
#[derive(Clone, Debug)]
330+
#[non_exhaustive]
328331
pub enum StringHint {
329332
/// Hints that an integer, float or string property is an enumerated value to pick in a list.
330333
Enum(EnumHint),
@@ -373,6 +376,7 @@ impl StringHint {
373376

374377
/// Possible hints for `Color`.
375378
#[derive(Clone, Debug)]
379+
#[non_exhaustive]
376380
pub enum ColorHint {
377381
/// Hints that a color property should be edited without changing its alpha component.
378382
NoAlpha,

gdnative-core/src/export/user_data.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ pub type DefaultUserData<T> = LocalCellData<T>;
165165

166166
/// Error type indicating that an operation can't fail.
167167
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
168+
#[allow(clippy::exhaustive_enums)] // explicitly uninhabited
168169
pub enum Infallible {}
169170

170171
impl std::fmt::Display for Infallible {
@@ -186,6 +187,7 @@ impl std::fmt::Display for Infallible {
186187
/// As there is no universal way to deal with such situations, behavior of locking wrappers can
187188
/// be customized using this enum.
188189
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
190+
#[non_exhaustive]
189191
pub enum DeadlockPolicy {
190192
/// Block on all locks. Deadlocks are possible.
191193
Allow,
@@ -223,6 +225,7 @@ impl LockOptions for DefaultLockPolicy {
223225

224226
/// Error indicating that a lock wasn't obtained.
225227
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
228+
#[non_exhaustive]
226229
pub enum LockFailed {
227230
Pessimistic,
228231
Timeout(Duration),
@@ -562,6 +565,7 @@ mod local_cell {
562565

563566
/// Error indicating that a borrow has failed.
564567
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
568+
#[non_exhaustive]
565569
pub enum LocalCellError {
566570
DifferentThread {
567571
original: ThreadId,

gdnative-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//!
2020
//! [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
2121
22-
#![deny(clippy::missing_inline_in_public_items)]
22+
#![warn(clippy::missing_inline_in_public_items, clippy::exhaustive_enums)]
2323
#![allow(
2424
clippy::transmute_ptr_to_ptr,
2525
clippy::missing_safety_doc,

0 commit comments

Comments
 (0)