-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
fn main() {
let tuple = (Some(String::new()), String::new());
let x = match tuple.0 {
Some(x) => Some((x, tuple.1)),
None => None,
};
println!("{:?}", x);
}
$ cargo clippy
warning: manual implementation of `Option::map`
--> src/main.rs:4:13
|
4 | let x = match tuple.0 {
| _____________^
5 | | Some(x) => Some((x, tuple.1)),
6 | | None => None,
7 | | };
| |_____^ help: try this: `tuple.0.map(|x| (x, tuple.1))`
|
= note: `#[warn(clippy::manual_map)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_map
Applying the suggestion made by clippy makes the code not compile:
error[E0382]: use of partially moved value: `tuple`
--> src/main.rs:4:25
|
4 | let x = tuple.0.map(|x| (x, tuple.1));
| ----^^^--------------
| | | |
| | | use occurs due to use in closure
| | value used here after partial move
| `tuple.0` partially moved due to this method call
|
note: this function takes ownership of the receiver `self`, which moves `tuple.0`
--> /home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:485:38
|
485 | pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
| ^^^^
= note: partial move occurs because `tuple.0` has type `Option<String>`, which does not implement the `Copy` trait
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have