Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUSTFLAGS is easy to misspell as RUST_FLAGS #6406

Closed
huonw opened this issue Dec 9, 2018 · 2 comments · Fixed by #6694
Closed

RUSTFLAGS is easy to misspell as RUST_FLAGS #6406

huonw opened this issue Dec 9, 2018 · 2 comments · Fixed by #6694
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy

Comments

@huonw
Copy link
Member

huonw commented Dec 9, 2018

Problem

I can never remember if it's RUSTFLAGS or RUST_FLAGS, and writing the latter silently does nothing. This is made worse because essentially every other environment variable cargo understands or declares uses _s: https://doc.rust-lang.org/cargo/reference/environment-variables.html

(This also applies to RUSTDOCFLAGS vs. the incorrect RUSTDOC_FLAGS.)

Steps

  1. Be forgetful and write RUST_FLAGS instead of RUSTFLAGS
  2. Run RUST_FLAGS=some-arg cargo build
  3. Don't notice (and/or be surprised) that some-arg didn't take effect (for that specific example, the build "should" fail but doesn't).

Possible Solution(s)

Cargo could check for a RUST_FLAGS environment variable and emit a warning (or note) that RUSTFLAGS was meant.

Notes

Output of cargo version: cargo 1.31.0 (339d9f9 2018-11-16)

@alexcrichton alexcrichton added A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Dec 10, 2018
@dwijnand dwijnand added the E-easy Experience: Easy label Dec 18, 2018
@pmespresso
Copy link

Hey! What about just changing it to RUSTFLAGS so that it's consistent with the rest of the environment variables?

@Ygg01
Copy link

Ygg01 commented Jan 15, 2019

@yjkimjunior Wouldn't that break all existing implementations? Huonw's suggestion makes me think it will add an alternative spelling for RUST_FLAGS.
@huonw Should this be a specific solution or is a more generic solution be needed? I.e. print warning for all env. variables at some Levenshtein distance.

bors added a commit that referenced this issue Mar 7, 2019
Emit warning on misspelled environment variables

This PR makes Cargo emit a warning when `RUST_FLAGS` or `RUSTDOC_FLAGS` environment variables are used instead of `RUSTFLAGS` or `RUSTDOCFLAGS`.

```shell
$ RUST_FLAGS=foo ./target/debug/cargo build
warning: Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?
```

Fixes #6406
@bors bors closed this as completed in #6694 Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants