Skip to content

Conversation

pongad
Copy link
Contributor

@pongad pongad commented Apr 9, 2014

Fixes #11926

bors added a commit that referenced this pull request Apr 10, 2014
@bors bors closed this Apr 10, 2014
@bors bors merged commit a00be50 into rust-lang:master Apr 10, 2014
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 3, 2024
…, r=xFrednet

Simplify negative `Option::{is_some_and,is_none_or}`

Closes rust-lang#13436.

Improved based on the existing lint `nonminimal_bool`, since there is already handling of similar methods `Option::{is_some,is_none}` and `Result::{is_ok,is_err}`, and there is a lot of reusable code.

When `is_some_and` or `is_none_or` have a negation, we invert it into another method by removing the Not sign and inverting the expression in the closure.

For the case where the closure block has statements, currently no simplification is implemented. (Should we do it?)

```rust
// Currently will not simplify this
_ = !opt.is_some_and(|x| {
    let complex_block = 100;
    x == complex_block
});
```

changelog: [`nonminimal_bool`]: Simplify negative `Option::{is_some_and,is_none_or}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

emit intrinsic declarations lazily
2 participants