cargo-nightly
Cargo subcommand that forwards commands to the nightly toolchain, enabling nightly toolchain usage in cargo aliases.
Why it exists
Cargo aliases in .cargo/config.toml cannot directly use +nightly syntax
because cargo aliases can only invoke cargo subcommands, not external
commands or toolchain selectors. This plugin provides a cargo-nightly
subcommand that forwards all arguments to cargo +nightly <args>, making
it possible to use nightly toolchain commands through cargo aliases.
The Problem
If you try to use +nightly directly in a cargo alias:
[]
= "+nightly clippy" # ❌ This doesn't work
You'll get an error:
error: no such command: `+nightly`
help: invoke `cargo` through `rustup` to handle `+toolchain` directives
The Solution
With cargo-nightly installed, you can create aliases like:
[]
= "nightly clippy"
= "nightly clippy"
= "nightly clippy --workspace --all-targets --all-features -- -D warnings"
When you run cargo clippy2, cargo will:
- Look for a
cargo-nightlysubcommand cargo-nightlyforwards tocargo +nightly clippy- The nightly toolchain runs your command
Installation
Using cargo-binstall (Recommended)
First install cargo-binstall if you haven't already:
Then install cargo-nightly:
Using cargo install
Usage
Once installed, you can use it directly:
Or through aliases in .cargo/config.toml:
[]
# Use nightly clippy for comprehensive linting
= "nightly clippy"
= "nightly clippy"
# Comprehensive clippy checks
= "nightly clippy --workspace --all-targets --all-features -- -D warnings"
= "nightly clippy --fix --workspace --all-targets --all-features --allow-dirty --allow-staged"
= "nightly clippy --workspace --all-targets --all-features -- -D warnings -D clippy::pedantic"
# Quick fixes
= "nightly clippy --fix --lib --allow-dirty"
Then use the aliases:
How it works
The cargo-nightly command is a simple wrapper that:
- Takes all arguments after
nightly - Executes
cargo +nightly <args> - Forwards stdin, stdout, and stderr
- Exits with the same exit code
This allows cargo to recognize nightly as a subcommand, which can then be
used in aliases.
License
Creative Commons Attribution-ShareAlike 4.0 International License - see LICENSE file for details.