Skip to content

regression: unnecessary_lazy_evaluations not triggered on thiserror enum variant #13249

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

Open
birkenfeld opened this issue Aug 10, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@birkenfeld
Copy link
Contributor

Summary

In stable (1.79.0), unnecessary_lazy_evaluations does not trigger when the value of the closure is a constant error variant in an enum that derives thiserror::Error.

  • This was emitting the correct warning on 1.63.0.

Lint Name

unnecessary_lazy_evaluations

Reproducer

I tried this code:

use std::io;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
    #[error("no devices found")]
    NoDevices,
    #[error(transparent)]
    Io(#[from] io::Error),
}

pub struct Master {}

impl Master {
    pub fn get_info(&self) -> Result<bool, Error> {
        let devices = [false];
        let first_device = devices.first().ok_or_else(|| Error::NoDevices)?;
        Ok(*first_device)
    }
}

I expected to see this happen: (from 1.63.0)

warning: unnecessary closure used to substitute value for `Option::None`
  --> src/master.rs:22:28
   |
22 |         let first_device = devices.first().ok_or_else(|| Error::NoDevices)?;
   |                            ^^^^^^^^^^^^^^^^-------------------------------
   |                                            |
   |                                            help: use `ok_or(..)` instead: `ok_or(Error::NoDevices)`
   |
   = note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations

Instead, this happened:
no warning

Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7
@birkenfeld birkenfeld added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Aug 10, 2024
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-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

1 participant