Skip to content

Fix for assertions_on_result_states incorrectly changes return type #9450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
glittershark opened this issue Sep 9, 2022 · 1 comment · Fixed by #9453
Closed

Fix for assertions_on_result_states incorrectly changes return type #9450

glittershark opened this issue Sep 9, 2022 · 1 comment · Fixed by #9453
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@glittershark
Copy link

Summary

assert!(res.is_err()) always returns (), but res.unwrap_err() returns the err type itself - this can cause auto-fixed code to fail to compile if there's a missing semicolon at the end of a test, for example.

Reproducer

I tried this code:

#[test]
fn my_test() {
    let res: Result<i32, i32> = Ok(1);
    assert!(res.is_err())
}

I expected to see this happen:

#[test]
fn my_test() {
    let res: Result<i32, i32> = Ok(1);
    res.unwrap_err();
}

Instead, this happened:

#[test]
fn my_test() {
    let res: Result<i32, i32> = Ok(1);
    res.unwrap_err()
}

causing a type error

Version

❯ rustc -Vv
rustc 1.64.0-nightly (fe3342816 2022-08-01)
binary: rustc
commit-hash: fe3342816a282949f014caa05ea2e669ff9d3d3c
commit-date: 2022-08-01
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

Additional Labels

@rustbot label +I-suggestion-causes-err

@glittershark glittershark added the C-bug Category: Clippy is not doing the correct thing label Sep 9, 2022
@glittershark
Copy link
Author

@rustbot label +I-suggestion-causes-error

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Sep 9, 2022
@bors bors closed this as completed in da8afc9 Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
2 participants