Use two version in the rust-toolchain

In the rust-toolchain file, how do I set up a default Rust version and also specify a custom nightly version with a specific date? In my configuration, I use unstable features for formatting, but I want to use stable for building.

There is a better way to configure it outside of the rust-toolchain

1 Like

Is this not what you want?
The Toolchain File

It seems that it is not easy to do at present, but you can design two toml files at the same time, one is the default and the other is nightly, and use a command wrapper to switch which toml file to use before cargo is executed.

Is this not what you want?

nop sorry!

At this point it is better make a script that call cargo +.... fmt --all

Can using the toolchain toml file overriding trick solve your problem?

.
├── Cargo.lock
├── Cargo.toml
├── rust-toolchain.toml
└── src
    ├── main.rs
    └── rust-toolchain.toml

I think that is your best option at the moment, as there is no way to configure the toolchain for specific Cargo commands only, other than the toolchain override +<toolchain> as the first argument of the command (which is actually handled by rustup and not Cargo).

When you just need to format locally, there is also this trick.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.