Skip to content

Moved value is still accessible #24069

Closed
Closed
@mdinger

Description

@mdinger

This looks like a bug to me. No one responded on IRC so I'm uncertain though:

#[derive(Debug)]
struct S {
    val: Option<Box<S>>,
}

fn main() {
    let mut a = S { val: None };
    let _ = S { val: Some(Box::new(a)) };

    // `a` was just moved. I can still assign to it though.
    // kinda seems like a bug.
    a.val = None;

    // assignment works but println fails because of move. kinda weird.
    //println!("{:?}", a.val);
}

playpen

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions