|
|
|
|
|
by evrimoztamur
403 days ago
|
|
Talking about unwrapping: I’ve been using a rather aggressive list of clippy lints to prevent myself from getting panics, which are particularly deadly in real-time applications (like video games). unwrap/expect_used already got me 90% of the way out, but looking at the number of as conversions in my codebase, I think I have around 300+ numerical conversions (which can and do fail!) [lints.clippy]
all = "deny"
unwrap_used = "deny"
expect_used = "deny"
panic = "deny"
indexing_slicing = "deny"
unhandled_errors = "deny"
unreachable = "deny"
undocumented_unsafe_blocks = "deny"
unwrap_in_result = "deny"
ok_expect = "deny"
|
|
We get around it by using conditional compilation and putting the lints in our entrypoints (`main.rs` or `lib.rs`), which is done automatically for any new entrypoint in the codebase via a Make target and some awk magic.
As an example, the following forbids print and dbg statements in release builds (all output should go through logging), allows it with a warning in debug builds, and allows it unconditionally in tests:
AFAIK there isn't currently a way to configure per-profile lints in the top-level Cargo configs. I wish there were.