Skip to content

False positive question_mark lint #2841

@sanpii

Description

@sanpii

Hello,

Clippy said there is a question_mark possible replacement in this code (finish_date and create_date are Option<T>):

finish_date: if create_date.is_none() {
    None
} else {
    finish_date
},

But it’s not possible with the else part or I miss something and an example in documentation could be usefull…

$ cargo +nightly --version                                                                                               
cargo 1.28.0-nightly (e2348c2db 2018-06-07)
$ cargo +nightly clippy --version                                                                                        
0.0.207                                                                                                                                                               
$ cargo +nightly clippy
    Checking todo-txt v1.1.0 (file:///home/sanpi/projects/rust/todo-txt)
warning: this block may be rewritten with the `?` operator
   --> src/parser.rs:161:30
    |
161 |                   finish_date: if create_date.is_none() {
    |  ______________________________^
162 | |                     None
163 | |                 } else {
164 | |                     finish_date
165 | |                 },
    | |_________________^ help: replace_it_with: `create_date?;`
    |
    = note: #[warn(question_mark)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.207/index.html#question_mark                                           

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsC-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