rust-clippy
rust-clippy copied to clipboard
`assertions_on_result_states`: add a config option to also lint asserts with a custom message
Description
assertions_on_result_states only fires when the assert has no custom message:
assert!(parse(sql).is_err()); // linted
assert!(parse(sql).is_err(), "{sql} should not parse"); // not linted
Projects that enable this restriction lint usually want every is_ok()/is_err()
assertion to inspect the value, e.g. to assert on the exact error. Today adding any
message silently opts out, so the lint can't enforce that.
Proposal
A clippy.toml option, defaulting to the current behaviour:
# default: true
allow-assertions-on-result-states-with-message = false
When set to false, the lint also fires on asserts with a message. Suggestion:
- string literal message →
.expect_err("msg")/.expect("msg")(machine-applicable) - formatted message → lint without an automatic fix
I'm happy to implement this if it makes sense.
@rustbot claim