# Can we do something about RUSTFLAGS != RUSTDOCFLAGS?

**URL:** <https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513>\
**Category:** cargo\
**Created:** [September 8, 2024, 3:59pm UTC](https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513 "2024-09-08T15:59:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [September 8, 2024, 3:59pm UTC](https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513/1 "2024-09-08T15:59:44Z")

</div>

Numerous times I forgot that `RUSTFLAGS` != `RUSTDOCFLAGS` and got bit by it. I've also seen other people with the same problem. Annoyingly, in addition to wasting my time, today I've also wasted some of Ralf's time reporting "a bug in miri" and I'd be surprised if I'm the only one who have done such thing. These two variables being different is a footgun also because `cargo test` runs both so we need to set both variables.

Can we do something like print a warning if `RUSTFLAGS` is set but not `RUSTDOCFLAGS` _and_ doc tests are being compiled? That'd already help a lot, I think.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [September 8, 2024, 4:53pm UTC](https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513/2 "2024-09-08T16:53:55Z")

</div>

IMHO `RUSTFLAGS` should be eliminated as much as possible:

> <https://github.com/rust-lang/cargo/issues/12739>
>
> RUSTFLAGS is a low level mechanism
> \- Harder for users to discover features
> \- H…arder for cargo to reason about like in #5931
> 
> This is meant to track RUSTFLAGS that should have a cargo-native way of being exposed. This won't always be one-to-one mappings
> 
> \- \[x\] \`--allow\`, \`--deny\`, \`--warn\`
> - Use case: package-level control over warnings
> - #12115
> \- \[\] \`--allow\`, \`--deny\`, \`--warn\`
> - Interactively denying/allowing warnings
> - #8424
> \- \[\] \`--target-cpu=native\`
> - #2535
> \- \[\] \`--cfg\`
> - https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618
> \- \[\] \`-Cinstrument-coverage\`
> - #13040
> 
> See also
> \- https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Reasons.20people.20use.20RUSTFLAGS
> \- https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Per-user.20build.20caches

---

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [September 8, 2024, 5:26pm UTC](https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513/3 "2024-09-08T17:26:40Z")

</div>

That's also a good perspective but it needs addressing the reasons why people use `RUSTFLAGS` in the first place (there are multiple of them) - exposing the configuration by `cargo` itself.

---

<div class="post-metadata">

**Author:** ![decathorpe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/decathorpe/32/12334_2.png) [@decathorpe](https://internals.rust-lang.org/u/decathorpe)\
**Post date:** [September 13, 2024, 4:05pm UTC](https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513/4 "2024-09-13T16:05:53Z")

</div>

Improving the handling of RUSTFLAGS and RUSTDOCFLAGS would be much appreciated (even if it only ends up making them consistent but rarely used) ...

see also [--cap-lints=warn are "ignored" in RUSTDOCFLAGS · Issue #67533 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/issues/67533) for a bug that has haunted us when doing Rust packaging in Fedora Linux for years

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [March 7, 2026, 4:06pm UTC](https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513/5 "2026-03-07T16:06:02Z")

</div>

Closed on March 7, 2026, 4:06pm UTC

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
