mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
9bd4e5469e
Boxes are a bit magic in that they need to use `*` to get an owned value
out of the box. They implement `Deref` but that only returns a
reference. This means an easy way to convert an `Option<Box<T>>` to an
`<Option<T>` is:
```
box_option.map(|b| *b)
```
However, since b36bb0a6
the `map_clone` lint is detecting this as an
attempt to copy the box. Fix by excluding boxes completely from the
deref part of this lint.
Fixes #3274
20 lines
829 B
Rust
20 lines
829 B
Rust
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
|
|
#![feature(tool_lints)]
|
|
#![warn(clippy::all, clippy::pedantic)]
|
|
#![allow(clippy::missing_docs_in_private_items)]
|
|
|
|
fn main() {
|
|
let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
|
|
let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect();
|
|
let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect();
|
|
let _: Option<u64> = Some(Box::new(16)).map(|b| *b);
|
|
}
|