fornwall / rust-script

Run Rust files and expressions as scripts without any setup or compilation step.
https://rust-script.org
Apache License 2.0
1.21k stars 41 forks source link

Edition #56

Closed LoganDark closed 2 years ago

LoganDark commented 2 years ago

rust-script is trying to execute my file as 2018 edition which is wrong. I can't find any documentation on getting it to use 2021 edition and this does not work:

/// ```cargo
/// edition = '2021'
/// ```
masklinn commented 2 years ago

The cargo block must be a section of a complete manifest. edition is a subkey of package, not a top-level key, so you need

//! ```cargo
//! [package]
//! edition = '2021'
//! ```

e.g.

//! ```cargo
//! [package]
//! edition = '2021'
//! ```

fn main() {
    let mut a = (1, 2);
    let mut f = || {
        a.0 += 1;
        a.0
    };
    println!("{} {}", a.1, f())
}

works fine, and absolutely can not compile without edition 2021 (because it uses disjoint closure capture).

LoganDark commented 2 years ago

Huh, thanks!