Closed
Description
It should be possible to match a reference and make the resulting value mutable in one step.
But this doesn't work:
println!("{:?}", { let v = [1, 2, 3]; v.iter().map(|&(mut x)| { x += 1; x }).collect::<Vec<_>>() } );
error: expected one of `,` or `@`, found `)`
--> src/main.rs:2:64
|
2 | println!("{:?}", { let v = [1, 2, 3]; v.iter().map(|&(mut x)| { x += 1; x }).collect::<Vec<_>>() } );
|
https://play.rust-lang.org/?gist=f76143789ed3a6a4fef1d950580f7904&version=stable
It only works like this:
println!("{:?}", { let v = [1, 2, 3]; v.iter().map(|&x| { let mut x = x; x += 1; x }).collect::<Vec<_>>() } );
which is very verbose. It should also be possible with &(mut x)
(or mut &x
).