Skip to content

Commit 7b2fd81

Browse files
committed
Add test for &mut
1 parent beb57f0 commit 7b2fd81

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

tests/ui/filter_map_bool_then.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ fn main() {
3333
// Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
3434
// and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
3535
// we can lint this and still get the same input type.
36+
// See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
3637
let v = vec![NonCopy, NonCopy];
3738
v.clone().iter().filter(|&i| (i == &NonCopy)).map(|i| i);
3839
// Do not lint
3940
let v = vec![NonCopy, NonCopy];
4041
v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i));
42+
// `&mut` is `!Copy`.
43+
let v = vec![NonCopy, NonCopy];
44+
v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i));
4145
external! {
4246
let v = vec![1, 2, 3, 4, 5, 6];
4347
v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));

tests/ui/filter_map_bool_then.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ fn main() {
3333
// Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
3434
// and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
3535
// we can lint this and still get the same input type.
36+
// See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
3637
let v = vec![NonCopy, NonCopy];
3738
v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
3839
// Do not lint
3940
let v = vec![NonCopy, NonCopy];
4041
v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i));
42+
// `&mut` is `!Copy`.
43+
let v = vec![NonCopy, NonCopy];
44+
v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i));
4145
external! {
4246
let v = vec![1, 2, 3, 4, 5, 6];
4347
v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));

tests/ui/filter_map_bool_then.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1));
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)`
3232

3333
error: usage of `bool::then` in `filter_map`
34-
--> $DIR/filter_map_bool_then.rs:37:22
34+
--> $DIR/filter_map_bool_then.rs:38:22
3535
|
3636
LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)`

0 commit comments

Comments
 (0)