Skip to content

question_mark suggested fix results in use of moved value error #15635

@Jouwee

Description

@Jouwee

Summary

When the question_mark lint is fixed using cargo clippy --fix and there's a drop command right after it, it generates a compiler error.

Reproducer

Warning in question:

warning: this block may be rewritten with the `?` operator
 --> src/main.rs:7:5
  |
7 | /     if let Err(reason) = result {
8 | |         return Err(reason);
9 | |     }
  | |_____^ help: replace it with: `result?;`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
  = note: `#[warn(clippy::question_mark)]` on by default

Code before fix:

    let result = do_something_else();
    if let Err(reason) = result {
        return Err(reason);
    }
    drop(result);

Code after fix:

    let result = do_something_else();
    result?;
    drop(result);

Error:

error[E0382]: use of moved value: `result`
   --> src/main.rs:8:10
    |
6   |     let result = do_something_else();
    |         ------ move occurs because `result` has type `Result<(), String>`, which does not implement the `Copy` trait
7   |     result?;
    |     ------- `result` moved due to this method call
8   |     drop(result);
    |          ^^^^^^ value used here after move

Version

rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.7

Additional Labels

README.md

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions