Skip to content

RUSTFLAGS in [env] section in .cargo/config.toml is silently ignored #16977

@orlp

Description

@orlp

Create a new project (cargo new foo), edit .cargo/config.toml and add:

[env]
RUSTFLAGS = "-C opt-level=illegal"

I expected to see this happen:

  • Either a correct passing of the RUSTFLAGS leading to an error:
    error: optimization level needs to be between 0-3, s or z (instead was `illegal`)
    
  • Or alternatively a warning that RUSTFLAGS is ignored in the [env] section, and that it must be passed with the rustflags option in either [build] or [target].

Instead, this happened:

  • Build silently succeeds, ignoring the set RUSTFLAGS entirely.

Meta

rustc --version --verbose:

rustc 1.94.0-nightly (7b5cde737 2025-12-27)
binary: rustc
commit-hash: 7b5cde7370b82fecf700071dda98c3fbc7d41fae
commit-date: 2025-12-27
host: aarch64-apple-darwin
release: 1.94.0-nightly
LLVM version: 21.1.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-documenting-cargo-itselfArea: Cargo's documentationC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    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