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
structRefed;implDropforRefed{fndrop(&mutself){println!("Dropping!");}}structRef<'a>(&'a mutVal,Refed);/*impl<'a> Drop for Ref<'a> { fn drop(&mut self) { println!("Dropping!"); }}*/#[derive(Debug)]structVal;implVal{fnreference(&mutself) -> Ref{Ref(self,Refed)}}fnmain(){letmut v = Val;println!("First reference");let r1 = v.reference();println!("Second reference");let r2 = v.reference();println!("Done");//println!("{:?}", r1.0);}
It looks like two mutable references to the same object are in scope at the same time.
The behaviour is "fixed" when I uncomment the Drop implementation for Ref. Accessing the first reference after the second is in scope seems to be impossible as well (uncomment println).
However the behaviour feels a little bit whacky, is this really intentional?
I'm currently writing a safe wrapper around memory mapped files and was using a struct similar to the Ref above in order to statically prevent having multiple mappings for the same file in scope at the same time.
I wanted to make sure, that only one such mapping can exist at the same time (because memory needs to be flushed which happens in the drop() of the mapping before another mapping can be created) but it seems like Rust's type system does not prevent this.
The text was updated successfully, but these errors were encountered:
Hi there! This isn't a bug. Since we try to keep the issue tracker solely for bugs, I'm going to close it, but if you'd like to discuss it more, please make a post to users.rust-lang.org. Thank you!
It looks like two mutable references to the same object are in scope at the same time.
The behaviour is "fixed" when I uncomment the Drop implementation for Ref. Accessing the first reference after the second is in scope seems to be impossible as well (uncomment println).
However the behaviour feels a little bit whacky, is this really intentional?
I'm currently writing a safe wrapper around memory mapped files and was using a struct similar to the Ref above in order to statically prevent having multiple mappings for the same file in scope at the same time.
I wanted to make sure, that only one such mapping can exist at the same time (because memory needs to be flushed which happens in the drop() of the mapping before another mapping can be created) but it seems like Rust's type system does not prevent this.
The text was updated successfully, but these errors were encountered: