rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`assertions_on_result_states`: add a config option to also lint asserts with a custom message

Open s5dsn-eqee opened this issue 1 month ago • 1 comments

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.

s5dsn-eqee avatar Oct 24 '26 14:10 s5dsn-eqee

@rustbot claim

Bimal-ray99 avatar Oct 27 '26 16:10 Bimal-ray99