Skip to content

try! not usable in main() #12130

Closed
Closed
@jfager

Description

@jfager

try! isn't directly usable in main, because it returns IoResult.

extern mod std;

use std::io::IoResult;

fn something() -> IoResult<bool> {
    Ok(true)
}

fn main() {
    let a = try!(something());
    println!("{}", a);
}

fails with

<std macros>:2:59: 2:65 error: mismatched types: expected `()` but found `std::result::Result<<generic #15>,std::io::IoError>` (expected () but found enum std::result::Result)
<std macros>:2     ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
                                                                     ^~~~~~
<std macros>:1:1: 3:2 note: in expansion of if_ok!
if_ok_main.rs:10:13: 10:33 note: expansion site
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions