dtolnay / dtolnay/no-panic

Best practices around verification

Open
#8 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.2k
Forks
20
PR merge metrics
No merged PRs in 30d

Description

In the readme it notes:

>Panic detection happens at link time across the entire dependency graph, so any Cargo commands that do not invoke a linker will not trigger panic detection. This includes cargo build of library crates and cargo check of binary and library crates.

This can be frustrating when developing a library as running the linker is not part of normal work flow.

I've found a good way to ensure this does not get overlooked. A good way to do this is rather than annotating the actual code, creating a wrapper function that is annotated with:
```
#[inline(never)]
#[no_panic]
#[cfg(test)]
```
And then have a test that calls it passing whatever parameters are needed. The inline(never) should prevent any constants from the test from getting inlined, which might not cover the panicking code path. The build will then fail any time `cargo test` is run.

It might be good to show an example working this way using a test rather than a main() because it is easy to not end up running the linker when developing a library.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.