Sean1708 / rusty-cheddar

A Rust crate for automatically generating C header files from Rust source file.
http://sean1708.github.io/rusty-cheddar/
191 stars 25 forks source link

Parser error with question mark operator #48

Open blochberger opened 7 years ago

blochberger commented 7 years ago

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 commented 7 years ago

use https://github.com/mozilla/moz-cheddar