You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0382]: borrow of moved value: `b`
--> src/main.rs:7:15
|
3 | let b: &mut i32 = &mut a;
| - move occurs because `b` has type `&mut i32`, which does not implement the `Copy` trait
4 | {
5 | let _c = b;
| - value moved here
6 | }
7 | println!("{b}");
| ^^^ value borrowed here after move
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0382`.
error: could not compile `playground` (bin "playground") due to 1 previous error
I expected either both versions of the code to compile, or neither to compile. Instead, it appears that adding a type annotation for _c causes rust to do an implicit reborrow. I thought that implicit reborrow can't happen on simple assignments like this. And why would a type annotation cause a reborrow anyway?
Meta
This issue occurs on the playground, both at stable (1.76.0), and at nightly (2024-02-22 397937d).
The text was updated successfully, but these errors were encountered:
This code compiles and prints
10
:playground
This code doesn't compile (the only difference is the lack of the type annotation on
_c
):playground
The compile error is:
I expected either both versions of the code to compile, or neither to compile. Instead, it appears that adding a type annotation for
_c
causes rust to do an implicit reborrow. I thought that implicit reborrow can't happen on simple assignments like this. And why would a type annotation cause a reborrow anyway?Meta
This issue occurs on the playground, both at stable (1.76.0), and at nightly (2024-02-22 397937d).
The text was updated successfully, but these errors were encountered: