Skip to content

False positive question_mark lint #2841

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

Activity

  1. oli-obk commented on Jun 13, 2018

    @oli-obk
    Contributor

    Huh, yea, it should be suggesting create_date.and(finish_date).

  2. added
    C-bugCategory: Clippy is not doing the correct thing
    A-lintArea: New lints
    on Jun 13, 2018
  3. sanpii commented on Jun 13, 2018

    @sanpii
    Author

    Huh, yea, it should be suggesting create_date.and(finish_date).

    That’s it, thank you!

  4. self-assigned this
    on Nov 8, 2018
  5. removed their assignment
    on Dec 7, 2018
  6. added a commit that references this issue on Dec 12, 2018
  7. phansch commented on Dec 13, 2018

    @phansch
    Contributor

    This was fixed in #3535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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