提交 7b2fd81f 编写于 作者: C Catherine Flores

Add test for `&mut`

上级 beb57f07
......@@ -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)`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册