]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs
Rollup merge of #107282 - BoxyUwU:erica_builtin_pointee_impls, r=compiler-errors
[rust.git] / tests / ui / closures / 2229_closure_analysis / diagnostics / liveness_unintentional_copy.rs
1 // edition:2021
2
3 // check-pass
4 #![warn(unused)]
5 #![allow(dead_code)]
6
7 #[derive(Debug)]
8 struct MyStruct {
9     a: i32,
10     b: i32,
11 }
12
13 pub fn unintentional_copy_one() {
14     let mut a = 1;
15     let mut last = MyStruct{ a: 1, b: 1};
16     let mut f = move |s| {
17         // This will not trigger a warning for unused variable
18         // as last.a will be treated as a Non-tracked place
19         last.a = s;
20         a = s;
21         //~^ WARN value assigned to `a` is never read
22         //~| WARN unused variable: `a`
23     };
24     f(2);
25     f(3);
26     f(4);
27 }
28
29 pub fn unintentional_copy_two() {
30     let mut a = 1;
31     let mut sum = MyStruct{ a: 1, b: 0};
32     (1..10).for_each(move |x| {
33         // This will not trigger a warning for unused variable
34         // as sum.b will be treated as a Non-tracked place
35         sum.b += x;
36         a += x; //~ WARN unused variable: `a`
37     });
38 }
39
40 fn main() {
41     unintentional_copy_one();
42     unintentional_copy_two();
43 }