mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 14:38:46 +00:00
Add test for &mut
This commit is contained in:
parent
beb57f074e
commit
7b2fd81f43
3 changed files with 9 additions and 1 deletions
|
@ -33,11 +33,15 @@ fn main() {
|
|||
// Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
|
||||
// and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
|
||||
// we can lint this and still get the same input type.
|
||||
// See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
|
||||
let v = vec![NonCopy, NonCopy];
|
||||
v.clone().iter().filter(|&i| (i == &NonCopy)).map(|i| i);
|
||||
// Do not lint
|
||||
let v = vec![NonCopy, NonCopy];
|
||||
v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i));
|
||||
// `&mut` is `!Copy`.
|
||||
let v = vec![NonCopy, NonCopy];
|
||||
v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i));
|
||||
external! {
|
||||
let v = vec![1, 2, 3, 4, 5, 6];
|
||||
v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
|
||||
|
|
|
@ -33,11 +33,15 @@ fn main() {
|
|||
// Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
|
||||
// and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
|
||||
// we can lint this and still get the same input type.
|
||||
// See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
|
||||
let v = vec![NonCopy, NonCopy];
|
||||
v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
|
||||
// Do not lint
|
||||
let v = vec![NonCopy, NonCopy];
|
||||
v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i));
|
||||
// `&mut` is `!Copy`.
|
||||
let v = vec![NonCopy, NonCopy];
|
||||
v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i));
|
||||
external! {
|
||||
let v = vec![1, 2, 3, 4, 5, 6];
|
||||
v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
|
||||
|
|
|
@ -31,7 +31,7 @@ LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1));
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)`
|
||||
|
||||
error: usage of `bool::then` in `filter_map`
|
||||
--> $DIR/filter_map_bool_then.rs:37:22
|
||||
--> $DIR/filter_map_bool_then.rs:38:22
|
||||
|
|
||||
LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)`
|
||||
|
|
Loading…
Add table
Reference in a new issue