Skip to content

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

@yvt

Description

@yvt
#![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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions