Skip to content

cargo clippy --fix fails fixing redundant_pattern_matching #7921

@Yuri6037

Description

@Yuri6037

I tried this code:

pub trait OptionExtension<T>
{
    fn get_or_insert_with_err<TError, F: FnOnce() -> Result<T, TError>>(
        &mut self,
        f: F
    ) -> Result<&mut T, TError>;
}

impl<T> OptionExtension<T> for Option<T>
{
    fn get_or_insert_with_err<TError, F: FnOnce() -> Result<T, TError>>(
        &mut self,
        f: F
    ) -> Result<&mut T, TError>
    {
        if let None = *self {
            *self = Some(f()?);
        }

        match self {
            Some(v) => Ok(v),
            // SAFETY: a `None` variant for `self` would have been replaced by a `Some`
            // variant in the code above.
            None => unsafe { std::hint::unreachable_unchecked() }
        }
    }
}

I expected to see this happen: Clippy fixing this redundant_pattern_matching

Instead, this happened: I got a bug report from clippy:

warning: failed to automatically apply fixes suggested by rustc to crate `testafs`

after fixes were automatically applied the compiler reported errors within these files:

  * src/lib.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see 
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0614]: type `bool` cannot be dereferenced
  --> src/lib.rs:16:12
   |
16 |         if *self.is_none() {
   |            ^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0614`.
Original diagnostics will follow.

Meta

Rust version (rustc -Vv):

rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-unknown-linux-gnu
release: 1.56.0
LLVM version: 13.0.0

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions