Moving value out of function by dereferencing a reference [duplicate]
问题 This question already has answers here : Why is it legal to borrow a temporary? (3 answers) Why can I return a reference to a local literal but not a variable? (1 answer) Cannot move out of borrowed content / cannot move out of behind a shared reference (1 answer) Closed last month . Given this code: struct SimpleFoo {} fn create_simplefoo() -> SimpleFoo { let foo: &SimpleFoo = &SimpleFoo {}; *foo } pub fn main() { let foo = create_simplefoo(); } I get error[E0507]: cannot move out of `*foo`