Skip to content

-Zallow-features=... on CLI is not included in CARGO_ENCODED_RUSTFLAGS #17065

@mkeeter

Description

@mkeeter

Problem

When passing -Zallow-features=... as a command-line flag, it is not included in CARGO_ENCODED_RUSTFLAGS. This means that build scripts which look at the encoded flags can't detect when nightly features are limited.

(This is the same type of issue as #12437, but for command-line flags instead of profile-rustflags)

Steps

I noticed this in anyhow, which reads CARGO_ENCODED_RUSTFLAGS when compiling a test program to check for nightly support.

$ cargo init anyhow-test && cd anyhow-test
$ cargo add anyhow
$ cargo check +nightly -Zallow-features=

The test program compiles successfully (because -Zallow-features= isn't propagated), so anyhow enables its nightly features, then immediately faceplants when it tries to build itself

(I initially opened anyhow#450, but agree with the author that this is a Cargo issue).

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.95.0 (f2d3ce0bd 2026-03-21)
release: 1.95.0
commit-hash: f2d3ce0bd7f24a49f8f72d9000448f8838c4e850
commit-date: 2026-03-21
host: aarch64-apple-darwin
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.7.1 (sys:0.4.83+curl-8.15.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Mac OS 26.5.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsA-rustflagsArea: rustflagsA-unstableArea: nightly unstable supportC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions