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

Add future-incompat warning against keywords in cfgs and add raw-idents #14671

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Oct 11, 2024

What does this PR try to resolve?

This PR tries to address this thread #14649 (comment) in #14649 regarding cfg(true)/cfg(false) (and keywords more generally) which are wrongly accepted1 as ident.

To address this, this PR does two things:

  1. it introduce a future-incompatibility warning against those (wrongly) accepted keywords as ident
  2. it add parsing for raw-idents (r#true) add suggest-it in the warning

How should we test and review this PR?

This PR should be reviewed commit-by-commit.
Tests are included in preliminary commits.

Additional information

I added a new struct for representing Idents which is rawness aware.
Which implied updating cargo-platform to 0.2.0 due to the API changes.

r? @epage

Footnotes

  1. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ccfb9c894dbf14e791c8ae7e4798efd0

@rustbot rustbot added A-build-scripts Area: build.rs scripts A-cfg-expr Area: Platform cfg expressions A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 11, 2024
@Urgau Urgau force-pushed the cfg-keyword-and-raw-idents branch 5 times, most recently from aa8bb59 to 0569db6 Compare October 11, 2024 13:42
tests/testsuite/cfg.rs Outdated Show resolved Hide resolved
tests/testsuite/cfg.rs Outdated Show resolved Hide resolved
@epage epage added the T-cargo Team: Cargo label Nov 1, 2024
@epage
Copy link
Contributor

epage commented Nov 1, 2024

@rfcbot fcp merge

This PR adds a future-incompat warning for the use of true and false values in a cfg within Cargo. This is to make room supporting RFC3695 (see #14649) which we verbally confirmed approval for (see rust-lang/rfcs#3695 (comment))

The main focus of this FCP is insta-stabilizing support for raw identifiers (e.g. r#true) in cfgs in Cargo. The future-incompat warning (this PR) and support for true / false (#14649) is implemented in a way that mirrors rustc where true and false are considered keywords and to reference the identifers with those names you need to use raw identifiers.

@rfcbot
Copy link
Collaborator

rfcbot commented Nov 1, 2024

Team member @epage has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Nov 1, 2024
@ehuss
Copy link
Contributor

ehuss commented Nov 2, 2024

I'm not quite sure I understand the wording of the error message. Saying cfg(true) is deprecated and will become a hard error in a future doesn't seem correct, since when rust-lang/rust#131204 is stabilized, it will become a supported feature (and thus not deprecated, and will intentionally be supported), right?

Would it be possible to change the wording to be something more like:

warning: the meaning of cfg(true) may change in the future
Cargo used to erroneously allow cfg(true) and cfg(false), but both forms were interpreted as false unless manually overridden with --cfg. In the future these will be built-in defines that will have the corresponding true/false value. It is recommended to avoid using these values until they are properly supported. See rust-lang/rust#131204 for more information.

@Urgau
Copy link
Member Author

Urgau commented Nov 2, 2024

[..] it will become a supported feature (and thus not deprecated, and will intentionally be supported), right?

Yes, cfg(true) and cfg(false) will have the right semantic after #14649 is stabilized.

Changed the wording as suggest.

@rfcbot rfcbot added final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels Nov 15, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Nov 15, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-cfg-expr Area: Platform cfg expressions A-manifest Area: Cargo.toml issues disposition-merge FCP with intent to merge final-comment-period FCP — a period for last comments before action is taken S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo
Projects
Status: FCP merge
Development

Successfully merging this pull request may close these issues.

5 participants