[rust-dev] should fail to compile or not?

Igor Karablin karablin at gmail.com
Tue Jan 21 14:18:36 PST 2014


I'm learning rust and trying to understand why rust allows me to compile
this piece of code. When Drop impl is uncommented - rustc complains about
'use of moved value', which is ok i think. My question is - why it compiles
code when Drop is not implemented for Inner struct? If its behaves as
intended - where i can read about this difference?

struct Inner;
impl Inner {
    fn innerFn(&mut self) {
        println!("Inner::innerFn"); // just for tracing

struct Outer {
    i: Inner

// uncomment it, and we get error: use of moved value: `inner`
impl Drop for Inner {
    fn drop(&mut self) {
        println!("Inner::drop"); // just for tracing

fn main() {
    let mut inner = Inner;
    let mut outer = Outer { i: inner }; // inner is moved into outer.i ?
    inner.innerFn();                    // why then i can call its method?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140122/91b1b516/attachment.html>

More information about the Rust-dev mailing list