Skip to content
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

redundant_pattern_matching suggests the use of non-const fn in const fn #5697

Closed
yvt opened this issue Jun 9, 2020 · 0 comments · Fixed by #5724
Closed

redundant_pattern_matching suggests the use of non-const fn in const fn #5697

yvt opened this issue Jun 9, 2020 · 0 comments · Fixed by #5724
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience.

Comments

@yvt
Copy link

yvt commented Jun 9, 2020

#![feature(const_if_match)]
pub const fn is_some(x: Option<u32>) -> bool {
    if let Some(_) = x { true } else { false } 
}
    Checking playground v0.0.1 (/playground)
warning: redundant pattern matching, consider using `is_some()`
 --> src/lib.rs:3:12
  |
3 |     if let Some(_) = x { true } else { false } 
  |     -------^^^^^^^---- help: try this: `if x.is_some()`
  |
  = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.30s

However, Option::is_some is not const fn in nightly-2020-06-07, so it can't be used in const fn.

Version: 2020-06-07 0262de5

(Playground)

yvt added a commit to r3-os/r3 that referenced this issue Jun 9, 2020
- `len_without_is_empty`
- `declare_interior_mutable_const` (ignored)
- `missing_safety_doc` (ignored)

Unaddressed:
- `redundant_pattern_matching` - This is a bug in clippy:
  <rust-lang/rust-clippy#5697>
@flip1995 flip1995 added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages C-bug Category: Clippy is not doing the correct thing labels Jun 13, 2020
bors added a commit that referenced this issue Jun 17, 2020
redundant_pattern_matching: avoid non-`const fn` calls in const contexts

changelog: Avoid suggesting non-`const fn` calls in const contexts in [`redundant_pattern_matching`]

Fixes #5697
@bors bors closed this as completed in f562117 Jun 23, 2020
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 C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants