Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange compilation failure #22722

Closed
bozaro opened this issue Feb 23, 2015 · 4 comments
Closed

Strange compilation failure #22722

bozaro opened this issue Feb 23, 2015 · 4 comments
Labels
A-type-system Area: Type system

Comments

@bozaro
Copy link

bozaro commented Feb 23, 2015

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
@dcampbell24
Copy link
Contributor

This looks like a duplication of #22252.

@dcampbell24
Copy link
Contributor

Also, #21114.

@dcampbell24
Copy link
Contributor

I also just started seeing a similar issue, so not sure what recently changed to make this affect more code.

// ...
fn main() {
    let args: Args = Docopt::new(USAGE)
                            .and_then(|d| d.decode())
                            .unwrap_or_else(|e| e.exit());

    if args.flag_version {
        println!("{}", VERSION);
        return
    }

    match server::start(&args.flag_listen) {
        Ok(_) => println!("listening on {} ...", &args.flag_listen),
        Err(err) => panic!("failed to start hearts server: {}", err),
    }
}

fails without a semi-colon at the end.

src/main.rs:47:26: 47:42 error: `args.flag_listen` does not live long enough
src/main.rs:47     match server::start(&args.flag_listen) {
                                        ^~~~~~~~~~~~~~~~
src/main.rs:38:11: 51:2 note: reference must be valid for the destruction scope surrounding block at 38:10...
src/main.rs:38 fn main() {
src/main.rs:39     let docopt = Docopt::new(USAGE).unwrap();
src/main.rs:40     let args: Args = docopt.decode().unwrap();
src/main.rs:41 
src/main.rs:42     if args.flag_version {
src/main.rs:43         println!("{}", VERSION);
               ...
src/main.rs:40:46: 51:2 note: ...but borrowed value is only valid for the block suffix following statement 1 at 40:45
src/main.rs:40     let args: Args = docopt.decode().unwrap();
src/main.rs:41 
src/main.rs:42     if args.flag_version {
src/main.rs:43         println!("{}", VERSION);
src/main.rs:44         return
src/main.rs:45     }
               ...

@steveklabnik steveklabnik added the A-type-system Area: Type system label Feb 25, 2015
@huonw
Copy link
Member

huonw commented Jan 8, 2016

Closing as a dupe of #22252; thanks for filing!

@huonw huonw closed this as completed Jan 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

4 participants