[rust-dev] static mut and owning pointers

2014-01-28 Thread Alexander Stavonin
Hi all! I’m not sure is it an error or static mut variables misunderstanding from my side. The source: struct MyStruct { val: int } static mut global_data: Option~MyStruct = None; fn test_call() { unsafe { match global_data { Some(data) = { println!(We have data

Re: [rust-dev] static mut and owning pointers

2014-01-28 Thread Kevin Ballard
Your code is moving the contents of Option~MyStruct into the match arm. It just so happens that this seems to be zeroing out the original pointer in memory, and that happens to be the same representation that None does for the type Option~MyStruct (since ~ pointers are non-nullable), so the act

Re: [rust-dev] static mut and owning pointers

2014-01-28 Thread François-Xavier Bourlet
damned, my gmail client was not up to date, you've got a better answer already (I got the ref keyword right at least ;)) On Tue, Jan 28, 2014 at 1:00 PM, François-Xavier Bourlet bomb...@gmail.com wrote: match global_data { Some(data) = You should be able to do: Some(ref data)

Re: [rust-dev] static mut and owning pointers

2014-01-28 Thread Niko Matsakis
Probably this should yield an error -- I tend to think we should only permit moves that we cannot enforce from `*` pointers, just to add an extra barrier. Niko On Tue, Jan 28, 2014 at 12:12:23PM -0800, Kevin Ballard wrote: Your code is moving the contents of Option~MyStruct into the match arm.

Re: [rust-dev] static mut and owning pointers

2014-01-28 Thread Alex Crichton
Our discussion in a recent meeting concluded that statics will not be allowed to contain types with destructors, and you also won't be able to move out of static items: https://github.com/mozilla/rust/issues/10577#issuecomment-32294407 On Tue, Jan 28, 2014 at 3:34 PM, Kevin Ballard ke...@sb.org