rust-lang / rust-lang/rust-clippy

manual_map false positive, disregards ownership rules on Option types

Open
#10,178 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

Clippy suggests replacing match on Option with map without regard to ownership rules.

Lint Name

manual_map

Reproducer

Consider this code:

let mut vector = vec![1, 2, 3];
let first = match vector.get(0) {
    Some(_) => Some(vector.swap_remove(0)),
    None => None
};

Clippy will suggest replacing match with map:

let mut vector = vec![1, 2, 3];
let first = vector.get(0).map(|_| vector.swap_remove(0));

Which does not compile.

Version
rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-pc-windows-msvc
release: 1.66.0
LLVM version: 15.0.2
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the manual_map lint entry point and reproduce the Option example from the issue. Trace how the suggested map closure is checked against ownership, and consider the work complete when the lint no longer emits a suggestion that fails to compile for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.