Rust "the option Z is only accepted on the nightly" in CI
You used a nightly-only compiler flag (-Z ...) or an unstable #![feature(...)] while building on stable Rust. Those are gated to the nightly channel and stable rustc rejects them outright.
What this error means
The build fails with the option Z is only accepted on the nightly compiler or #![feature] may not be used on the stable release channel. The same code compiles on nightly but not on the stable CI toolchain.
error: the option `Z` is only accepted on the nightly compiler
help: consider switching to a nightly toolchain: `rustup default nightly`
note: selecting a toolchain with `+toolchain` arguments ...Common causes
Nightly-only flag on stable
A -Z flag (often in RUSTFLAGS, .cargo/config.toml, or a build script) is unstable and only works on nightly. Stable rustc refuses it.
Unstable feature gate on stable
A #![feature(...)] attribute enables an unstable language/library feature. Those are nightly-only and error on the stable channel.
How to fix it
Use nightly where the feature requires it
If the unstable feature is essential, build that job on nightly.
rustup toolchain install nightly
cargo +nightly buildOr remove the unstable dependency
- Find the
-Zflag (checkRUSTFLAGSand.cargo/config.toml) and drop it if not needed. - Replace
#![feature(...)]with a stable alternative where one exists. - Pin the job to nightly only when there is genuinely no stable path.
How to prevent it
- Keep CI on stable and isolate any nightly-only job explicitly.
- Avoid
-Zflags and#![feature]gates unless you commit to nightly. - Document which jobs require nightly and why.