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

Parser error with question mark operator #48

Open
blochberger opened this issue Dec 12, 2016 · 1 comment
Open

Parser error with question mark operator #48

blochberger opened this issue Dec 12, 2016 · 1 comment

Comments

@blochberger
Copy link

A source file containing a question mark ? operator leads to a parsing error and therefore to an invalid build, e.g. re-writing the example from Macro std::try works fine:

use std::io;
use std::fs::File;
use std::io::prelude::*;

enum MyError {
    FileWriteError
}

impl From<io::Error> for MyError {
    fn from(e: io::Error) -> MyError {
        MyError::FileWriteError
    }
}

fn write_to_file_using_try() -> Result<(), MyError> {
    let mut file = try!(File::create("my_best_friends.txt"));
    try!(file.write_all(b"This is a list of my best friends."));
    println!("I wrote to the file");
    Ok(())
}

But adding the following function leads to a build error if cheddar is active for the build.

fn write_to_file_using_qm() -> Result<(), MyError> {
    let mut file = File::create("my_best_friends.txt")?;
    file.write_all(b"This is a list of my best friends.")?;
    println!("I wrote to the file");
    Ok(())
}

The error is the following:

cargo build
   Compiling tmp v0.1.0 (file://~/tmp)
error: failed to run custom build command for `tmp v0.1.0 (file://~/tmp)`
process didn't exit successfully: `~/tmp/target/debug/build/tmp-61d2999a3a4c1c18/build-script-build` (exit code: 101)
--- stderr
src/lib.rs:25:55: 25:56 error: expected one of `.`, `;`, or an operator, found `?`
src/lib.rs:25     let mut file = File::create("my_best_friends.txt")?;
                                                                    ^
thread 'main' panicked at 'Box<Any>', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/syntex_syntax-0.24.0/src/parse/mod.rs:79
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@felberj
Copy link

felberj commented Sep 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants