-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Labels
A-type-systemArea: Type systemArea: Type system
Description
rustc 1.0.0-nightly (2b01a37 2015-02-21) (built 2015-02-22)
I try to compile file:
use std::sync::{Arc, Mutex};
fn main() {
}
fn compile_ok() -> Result<(), ()> {
let hash_lock = Arc::new(Mutex::new("test".to_string()));
let result = match hash_lock.lock() {
Ok(_) => Ok(()),
Err(_) => Ok(())
};
result
}
fn compile_fail() -> Result<(), ()> {
let hash_lock = Arc::new(Mutex::new("test".to_string()));
match hash_lock.lock() {
Ok(_) => Ok(()),
Err(_) => Ok(())
}
}
And get error:
sample.rs:17:8: 17:17 error: `hash_lock` does not live long enough
sample.rs:17 match hash_lock.lock() {
^~~~~~~~~
sample.rs:15:37: 21:2 note: reference must be valid for the destruction scope surrounding block at 15:36...
sample.rs:15 fn compile_fail() -> Result<(), ()> {
sample.rs:16 let hash_lock = Arc::new(Mutex::new("test".to_string()));
sample.rs:17 match hash_lock.lock() {
sample.rs:18 Ok(_) => Ok(()),
sample.rs:19 Err(_) => Ok(())
sample.rs:20 }
...
sample.rs:16:58: 21:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 16:57
sample.rs:16 let hash_lock = Arc::new(Mutex::new("test".to_string()));
sample.rs:17 match hash_lock.lock() {
sample.rs:18 Ok(_) => Ok(()),
sample.rs:19 Err(_) => Ok(())
sample.rs:20 }
sample.rs:21 }
error: aborting due to previous error
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type system