Created
December 3, 2025 14:04
-
-
Save OrelSokolov/f28c3a6530407202059ebb1fd985988c to your computer and use it in GitHub Desktop.
Deny any panic methods in crate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //! NoPanic - Complete set of rules to forbid panics and dangerous constructs | |
| //! | |
| //! This file contains crate-level attributes to forbid compilation | |
| //! with methods that can cause panics or unsafe operations. | |
| //! | |
| //! Include at the beginning of main.rs via: include!("nopanic.rs"); | |
| // ============================================================================ | |
| // FORBID PANIC METHODS (deny - compilation error) | |
| // ============================================================================ | |
| // Forbid unwrap() - main cause of panics | |
| #![deny(clippy::unwrap_used)] | |
| // Forbid expect() - unwrap with message | |
| #![deny(clippy::expect_used)] | |
| // Forbid direct panic!() calls | |
| #![deny(clippy::panic)] | |
| // Forbid unreachable!() | |
| #![deny(clippy::unreachable)] | |
| // Forbid todo!() and unimplemented!() | |
| #![deny(clippy::todo)] | |
| #![deny(clippy::unimplemented)] | |
| // ============================================================================ | |
| // FORBID UNSAFE OPERATIONS (deny) | |
| // ============================================================================ | |
| // Forbid unsafe array/slice indexing without checks | |
| #![deny(clippy::indexing_slicing)] | |
| // Forbid unsafe arithmetic without overflow checks | |
| #![deny(clippy::integer_arithmetic)] | |
| // Forbid unsafe type casts | |
| #![deny(clippy::cast_possible_truncation)] | |
| #![deny(clippy::cast_possible_wrap)] | |
| #![deny(clippy::cast_sign_loss)] | |
| #![deny(clippy::cast_lossless)] | |
| // Forbid unsafe pointer operations | |
| #![deny(clippy::as_ptr_cast_mut)] | |
| #![deny(clippy::ptr_as_ptr)] | |
| // ============================================================================ | |
| // FORBID DANGEROUS PATTERNS (deny) | |
| // ============================================================================ | |
| // Forbid unwrap in tests (even in tests it's better to handle errors) | |
| #![deny(clippy::unwrap_in_result)] | |
| // Forbid expect in tests | |
| #![deny(clippy::expect_in_result)] | |
| // Forbid unwrap on Option | |
| #![deny(clippy::option_unwrap_used)] | |
| // Forbid expect on Option | |
| #![deny(clippy::option_expect_used)] | |
| // Forbid unwrap on Result | |
| #![deny(clippy::result_unwrap_used)] | |
| // Forbid expect on Result | |
| #![deny(clippy::result_expect_used)] | |
| // Forbid unwrap_err | |
| #![deny(clippy::unwrap_err_used)] | |
| // Forbid expect_err | |
| #![deny(clippy::expect_err_used)] | |
| // ============================================================================ | |
| // WARNINGS ABOUT PROBLEMATIC PATTERNS (warn) | |
| // ============================================================================ | |
| // Warn about missing panic documentation | |
| #![warn(clippy::missing_panics_doc)] | |
| // Warn about missing error documentation | |
| #![warn(clippy::missing_errors_doc)] | |
| // Warn about empty catch blocks | |
| #![warn(clippy::empty_catch)] | |
| // Warn about unused Result | |
| #![warn(clippy::unused_result)] | |
| // Warn about unused Option | |
| #![warn(clippy::unused_option)] | |
| // Warn about potentially infinite loops | |
| #![warn(clippy::infinite_iter)] | |
| // Warn about unsafe memory operations | |
| #![warn(clippy::unsafe_removed_from_name)] | |
| // Warn about unsafe casts | |
| #![warn(clippy::cast_ptr_alignment)] | |
| // Warn about precision loss in casts | |
| #![warn(clippy::cast_precision_loss)] | |
| // Warn about overflow in casts | |
| #![warn(clippy::cast_overflow)] | |
| // ============================================================================ | |
| // ADDITIONAL SAFETY RULES (warn) | |
| // ============================================================================ | |
| // Warn about potentially problematic comparisons | |
| #![warn(clippy::comparison_chain)] | |
| // Warn about unsafe float operations | |
| #![warn(clippy::float_arithmetic)] | |
| // Warn about unsafe float comparisons | |
| #![warn(clippy::float_cmp)] | |
| // Warn about unsafe float comparisons (const) | |
| #![warn(clippy::float_cmp_const)] | |
| // Warn about unsafe pointer operations | |
| #![warn(clippy::fn_to_numeric_cast)] | |
| #![warn(clippy::fn_to_numeric_cast_with_truncation)] | |
| // Warn about unsafe memory operations | |
| #![warn(clippy::mem_forget)] | |
| #![warn(clippy::forget_ref)] | |
| #![warn(clippy::forget_copy)] | |
| // Warn about unsafe raw pointer operations | |
| #![warn(clippy::not_unsafe_ptr_arg_deref)] | |
| // ============================================================================ | |
| // CODE QUALITY RULES (warn) | |
| // ============================================================================ | |
| // Warn about unused variables | |
| #![warn(clippy::unused_variables)] | |
| // Warn about unused imports | |
| #![warn(clippy::unused_imports)] | |
| // Warn about dead code | |
| #![warn(clippy::dead_code)] | |
| // Warn about unused attributes | |
| #![warn(clippy::unused_attributes)] | |
| // Warn about unused mutable variables | |
| #![warn(clippy::unused_mut)] | |
| // Warn about unused associated type bounds | |
| #![warn(clippy::unused_associated_type_bounds)] | |
| // ============================================================================ | |
| // PERFORMANCE RULES (warn) | |
| // ============================================================================ | |
| // Warn about inefficient operations | |
| #![warn(clippy::inefficient_to_string)] | |
| // Warn about inefficient copies | |
| #![warn(clippy::large_enum_variant)] | |
| // Warn about inefficient comparisons | |
| #![warn(clippy::comparison_to_empty)] | |
| // ============================================================================ | |
| // STYLE AND READABILITY RULES (warn) | |
| // ============================================================================ | |
| // Warn about complex expressions | |
| #![warn(clippy::cognitive_complexity)] | |
| // Warn about too large functions | |
| #![warn(clippy::too_many_lines)] | |
| // Warn about too many parameters | |
| #![warn(clippy::too_many_arguments)] | |
| // Warn about too much nesting | |
| #![warn(clippy::too_many_nested_blocks)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment