These are chat archives for rust-lang/rust

13th
Apr 2017
MicroMike
@mike820324
Apr 13 2017 02:08

Hi, is anyone encounter rustup install/update failed with the nightly toolchain?
The verbose error message looks something like the following

mikejiang@hangogo:~$ rustup -v toolchain install nightly                                                                                                                                                              
verbose: read metadata version: '12'
verbose: installing toolchain 'nightly-x86_64-unknown-linux-gnu'
verbose: toolchain directory: '/home/mikejiang/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu'
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
verbose: creating temp file: /home/mikejiang/.rustup/tmp/ta889tk7246sv9af_file
verbose: downloading file from: 'https://static.rust-lang.org/dist/channel-rust-nightly.toml.sha256'
verbose: downloading with curl
verbose: deleted temp file: /home/mikejiang/.rustup/tmp/ta889tk7246sv9af_file
verbose: no update hash at: '/home/mikejiang/.rustup/update-hashes/nightly-x86_64-unknown-linux-gnu'
verbose: creating temp file: /home/mikejiang/.rustup/tmp/218o0r8pm5a517cz_file.toml
verbose: downloading file from: 'https://static.rust-lang.org/dist/channel-rust-nightly.toml'
verbose: downloading with curl
verbose: checksum passed
verbose: deleted temp file: /home/mikejiang/.rustup/tmp/218o0r8pm5a517cz_file.toml
verbose: removing toolchain directory: '/home/mikejiang/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu'
error: missing key: 'url'

thanks

MicroMike
@mike820324
Apr 13 2017 06:45
Thanks.
Hollin Wilkins
@hollinwilkins
Apr 13 2017 20:41
Hey, if I want to store an RwLockWriteGuard<T> along with an Arc<RwLock<T>> in a struct, like this:
pub struct MyStruct<'a, T: 'a> {
  arc: Arc<RwLock<T>>,
  lock: RwLockWriteGuard<'a, T>
}
Is this possible? The idea being that when an instance of MyStruct is dropped, the lock is dropped as well, and the lock is ensured to point to valid memory because the Arc is in the same struct
Hollin Wilkins
@hollinwilkins
Apr 13 2017 20:50
Oh, I guess it is specifically !Send, maybe this is a crazy thing to do
Ashley Mannix
@KodrAus
Apr 13 2017 22:18
@hollinwilkins So what is it you're trying to do? You should probably try not to hold a lock for any longer than you actually need. You shouldn't need to keep the Arc in the same struct as the lock, because that 'a lifetime needs to be shorter than the RwLock, so it's already guaranteed that if you've got a RwLockWriteGuard<'a, T>, that the RwLock<T> that it came from is still live
Ashley Mannix
@KodrAus
Apr 13 2017 22:24
In fact, these sorts of data structures are difficult to represent in Rust, you can't get a lock on the contents of the Arc, and then pass ownership of that Arc to another structure because it's mutably borrowed to get access to the RwLock to get a write lock. See this playground
So instead of keeping an owned Arc alongside the lock to ensure it's valid, you rely on that 'a lifetime to ensure it's within the lifetime of the Arc
If you want to share some mutable state across threads, I think the easiest way to go is just clone the Arc, get a lock, do your thing and then let it all get cleaned up at the end