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

Merged
merged 6 commits into from
Nov 26, 2024

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.

@Urgau Urgau force-pushed the cfg-keyword-and-raw-idents branch 2 times, most recently from 0121d31 to 363c9b7 Compare November 10, 2024 14:16
@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. 🔔

@rfcbot rfcbot added to-announce and removed final-comment-period FCP — a period for last comments before action is taken labels Nov 25, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Nov 25, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Urgau !

@epage epage added this pull request to the merge queue Nov 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 25, 2024
@epage epage added this pull request to the merge queue Nov 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 26, 2024
@weihanglo
Copy link
Member

---- test_proc_macro stdout ----
running `/home/runner/work/cargo/cargo/target/debug/cargo test --lib -Zbuild-std -Zpublic-dependency`
thread 'test_proc_macro' panicked at tests/build-std/main.rs:391:10:

---- expected: tests/build-std/main.rs:385:27
++++ actual:   stderr
        1 + [BLOCKING] waiting for file lock on package cache
        2 + [BLOCKING] waiting for file lock on package cache
   1    3 | [COMPILING] foo v0.0.0 ([ROOT]/foo)
   2    4 | [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
   3    5 | [RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH])

Hmm… build-std seems to clobber each others after #14850. Let me check how to fix it.

@weihanglo
Copy link
Member

Got a PR up: #14861

@weihanglo
Copy link
Member

Re-queuing as #14861 has been merged.

@weihanglo weihanglo added this pull request to the merge queue Nov 26, 2024
Merged via the queue into rust-lang:master with commit 10c255a Nov 26, 2024
22 checks passed
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 finished-final-comment-period FCP complete S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo to-announce
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants