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
fnmain(){let a:&muti32 = &mut0;{let b = a;}let c = a;}
It properly fails to compile, as a is moved into b.
However this one compiles fine:
fnmain(){let a:&muti32 = &mut0;{let b:&muti32 = a;}let c = a;}
Adding a type annotation to b implicitly changed the move of a into a re-borrow. This behavior actually makes sense: if b was annotated &i32, a move would have not been possible, and a re-borrow would have been mandatory.
It is pretty harmless and does not pose any safety issue (actually I think having a "always re-borrow" policy would still be safe), but is still an implicit behavior that is not documented (at least I didn't find any documentation about it).
I'm not planning on significant changes to the book, so I've made a note in the appropriate part of the next-gen repo to make sure we talk about re-borrowing. Thanks!
Consider this snippet of code:
It properly fails to compile, as
a
is moved intob
.However this one compiles fine:
Adding a type annotation to
b
implicitly changed the move ofa
into a re-borrow. This behavior actually makes sense: ifb
was annotated&i32
, a move would have not been possible, and a re-borrow would have been mandatory.It is pretty harmless and does not pose any safety issue (actually I think having a "always re-borrow" policy would still be safe), but is still an implicit behavior that is not documented (at least I didn't find any documentation about it).
(Comes from a SO question: http://stackoverflow.com/q/30535529/2536143 )
The text was updated successfully, but these errors were encountered: