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
The compiler currently rejects the code above, because the as &mut Trait cast counts as moving the &mut MovingType reference:
moved_mutable_ref_trait_cast.rs:16:6: 16:7 error: use of moved value: `x`
moved_mutable_ref_trait_cast.rs:16 b(x);
^
moved_mutable_ref_trait_cast.rs:13:10: 13:11 note: `x` moved here because it has type `&mut MovingType`, which is non-copyable (perhaps you meant to use clone()?)
moved_mutable_ref_trait_cast.rs:13 c(x as &mut Trait);
^
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /build/rust-git/src/rust/src/libsyntax/diagnostic.rs:102
task '<main>' failed at 'explicit failure', /build/rust-git/src/rust/src/librustc/lib.rs:440
However, if you introduce indirection by having the cast be performed by a wrapper that takes &mut MovingType, then the program compiles.
This can be demonstrated by swapping the the commented and uncommented lines in the code block.
As far as I can see, this is a bug, as either the compiler should allow both or forbid both.
The text was updated successfully, but these errors were encountered:
The compiler currently rejects the code above, because the
as &mut Trait
cast counts as moving the&mut MovingType
reference:However, if you introduce indirection by having the cast be performed by a wrapper that takes
&mut MovingType
, then the program compiles.This can be demonstrated by swapping the the commented and uncommented lines in the code block.
As far as I can see, this is a bug, as either the compiler should allow both or forbid both.
The text was updated successfully, but these errors were encountered: