rust-shell-script / rust_cmd_lib

Common rust command-line macros and utilities, to write shell-script like tasks in a clean, natural and rusty way
https://docs.rs/cmd_lib/
Apache License 2.0
1.05k stars 37 forks source link

run_cmd!{} alone with curly braces doesn't compile #40

Closed allmycode closed 3 years ago

allmycode commented 3 years ago

This doesn't compile

fn main() -> std::io::Result<()> {
    run_cmd!{ls}?;
    Ok(())
}

compiles says

error: expected expression, found `?`
 --> src/main.rs:4:17
  |
4 |     run_cmd!{ls}?;
  |                 ^ expected expression

error[E0308]: mismatched types
 --> src/main.rs:4:5
  |
4 |     run_cmd!{ls}?;
  |     ^^^^^^^^^^^^ expected `()`, found enum `Result`
  |
  = note: expected unit type `()`
                  found enum `Result<(), std::io::Error>`

while this compiles fine

fn main() -> std::io::Result<()> {
    run_cmd!(ls)?;
    Ok(())
}

This with curly braces compiles too

fn main() -> std::io::Result<()> {
    let _ = run_cmd!{ls}?;
    Ok(())
}
rust-shell-script commented 3 years ago

This is not something this library can fix. Fortunately, rustc has already merged a recent fix: https://github.com/rust-lang/rust/pull/88690, and you can use it in nightly rust now. So you just need to wait for it to become stable.