I'm learning Rust and I don't want to create a full project for every single code snippet I want to play with, so I create standalone files and compile them with rustc.
A copy+pasted snippet from The Book was triggering lots of warnings in my machine, but worked fine in Rust Playground. I eventually figured out that the code requires 2021 edition but my local rustc is using 2018 or older.
How is this default edition configured? I know I can pass --edition 2021 or whatever everytime, but I'd rather just default to latest edition (and I like to know how things work).
I'm using Windows 10 for what it's worth.
rustc is generally not intended to be the user-facing frontend... I'd strongly recommend using cargo new foo or whatever to create small new projects. It's really not that much bigger than a single standalone file.
cargo reads the edition from Cargo.toml, and yes, rustc is primarily driven by per-invocation environment variables and arguments.
rustc defaults to the oldest edition, 2015.
Maybe there's some esoteric environment variable that accomplishes the same thing in a persistent way...? But I seriously wouldn't count on it.
Edit: I suppose you could set an alias like alias myrustc="rustc --edition 2024" or whatever. ...uhh though that's the Unix-y syntax for it, idk about windows.
Great, use cargo then.
There's no "just use latest" because that's breaking. It's cargo new that sets a particular edition in the toml and then that's the one that's used.
(The whole point of editions is that you don't just get broken because the toolchain updated, and that's exactly what would happen if there was a --edition=yolo flag.)