]> git.lizzy.rs Git - rust.git/blob - src/test/ui/destructuring-assignment/warn-unused-duplication.rs
Auto merge of #106349 - LeSeulArtichaut:dyn-star-tracking-issue, r=jackh726
[rust.git] / src / test / ui / destructuring-assignment / warn-unused-duplication.rs
1 // run-pass
2
3 #![warn(unused_assignments)]
4
5 fn main() {
6     let mut a;
7     // Assignment occurs left-to-right.
8     // However, we emit warnings when this happens, so it is clear that this is happening.
9     (a, a) = (0, 1); //~ WARN value assigned to `a` is never read
10     assert_eq!(a, 1);
11
12     // We can't always tell when a variable is being assigned to twice, which is why we don't try
13     // to emit an error, which would be fallible.
14     let mut x = 1;
15     (*foo(&mut x), *foo(&mut x)) = (5, 6);
16     assert_eq!(x, 6);
17 }
18
19 fn foo<'a>(x: &'a mut u32) -> &'a mut u32 {
20     x
21 }