-
Couldn't load subscription status.
- Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
IMO using assert!(foo().is_err()) is clearer within a test to imply that the assertion is the point of the test rather than foo().unwrap_err().
Lint Name
assertions_on_result_states
Reproducer
I tried this code:
#[test]
fn error() {
struct Foo;
impl stylish::Display for Foo {
fn fmt(&self, _: &mut stylish::Formatter<'_>) -> std::fmt::Result {
Err(std::fmt::Error)
}
}
let mut s = Vec::<u8>::new();
let mut writer = stylish::io::Plain::new(&mut s);
assert!(stylish::writeln!(writer, "{:s}", Foo).is_err());
}error: called `assert!` with `Result::is_err`
Error: --> tests/tests.rs:70:9
|
70 | assert!(stylish::writeln!(writer, "{:s}", Foo).is_err());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `stylish::writeln!(writer, "{:s}", Foo).unwrap_err()`
|
= note: `-D clippy::assertions-on-result-states` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_result_states
I expected to see this happen:
Version
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2022-07-30, rust version 1.64.0-nightly (3924dac7b 2022-07-29)
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have