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
@Urgau Urgau force-pushed the cfg-keyword-and-raw-idents branch from 0569db6 to 7b3512f Compare November 1, 2024 16:26
@Urgau Urgau force-pushed the cfg-keyword-and-raw-idents branch from 7b3512f to dd334dd Compare November 1, 2024 17:39
@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 Urgau force-pushed the cfg-keyword-and-raw-idents branch from dd334dd to ff762d8 Compare November 2, 2024 23:29
@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
@Urgau Urgau force-pushed the cfg-keyword-and-raw-idents branch from 363c9b7 to e2028d4 Compare November 25, 2024 21:02
@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
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 30, 2024
Update cargo

8 commits in 4c39aaff66862cc0da52fe529aa1990bb8bb9a22..3908f64086a3d7b9af8d87b4da2bd100776c3e61
2024-11-25 16:36:17 +0000 to 2024-11-29 17:32:44 +0000
- chore(deps): update msrv (rust-lang/cargo#14867)
- fix(fix): Migrate cargo script manifests across editions (rust-lang/cargo#14864)
- feat(toml): Allow adding/removing from cargo scripts (rust-lang/cargo#14857)
- Add future-incompat warning against keywords in cfgs and add raw-idents (rust-lang/cargo#14671)
- test(build-std): download deps first (rust-lang/cargo#14861)
- test(pgo): ensure PGO works (rust-lang/cargo#14859)
- git-fetch-with-cli: Set `GIT_DIR` for bare repository compatibility (rust-lang/cargo#14860)
- fix(build-std): always link to std when testing proc-macros (rust-lang/cargo#14850)
@rustbot rustbot added this to the 1.85.0 milestone Nov 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2024
Update cargo

17 commits in 4c39aaff66862cc0da52fe529aa1990bb8bb9a22..05f54fdc34310f458033af8a63ce1d699fae8bf6
2024-11-25 16:36:17 +0000 to 2024-12-03 03:14:12 +0000
- test(pgo): only run on nightly (rust-lang/cargo#14887)
- chore: Bump to 0.86.0; update changelog (rust-lang/cargo#14885)
- docs(ref): Finish a sentence on rust-versions (rust-lang/cargo#14884)
- chore(deps): update rust crate cargo_metadata to 0.19.0 (rust-lang/cargo#14878)
- chore(deps): update rust crate gix to 0.68.0 (rust-lang/cargo#14879)
- fix: Remove default registry reference in `info` cmd docs (rust-lang/cargo#14880)
- test(pgo): determine test runnability at compile time (rust-lang/cargo#14874)
- test: `requires` attribute accepts string literals for cmds (rust-lang/cargo#14875)
- chore(deps): update msrv (3 versions) to v1.81 (rust-lang/cargo#14871)
- chore(deps): update msrv (rust-lang/cargo#14867)
- fix(fix): Migrate cargo script manifests across editions (rust-lang/cargo#14864)
- feat(toml): Allow adding/removing from cargo scripts (rust-lang/cargo#14857)
- Add future-incompat warning against keywords in cfgs and add raw-idents (rust-lang/cargo#14671)
- test(build-std): download deps first (rust-lang/cargo#14861)
- test(pgo): ensure PGO works (rust-lang/cargo#14859)
- git-fetch-with-cli: Set `GIT_DIR` for bare repository compatibility (rust-lang/cargo#14860)
- fix(build-std): always link to std when testing proc-macros (rust-lang/cargo#14850)
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Dec 6, 2024
Update cargo

17 commits in 4c39aaff66862cc0da52fe529aa1990bb8bb9a22..05f54fdc34310f458033af8a63ce1d699fae8bf6
2024-11-25 16:36:17 +0000 to 2024-12-03 03:14:12 +0000
- test(pgo): only run on nightly (rust-lang/cargo#14887)
- chore: Bump to 0.86.0; update changelog (rust-lang/cargo#14885)
- docs(ref): Finish a sentence on rust-versions (rust-lang/cargo#14884)
- chore(deps): update rust crate cargo_metadata to 0.19.0 (rust-lang/cargo#14878)
- chore(deps): update rust crate gix to 0.68.0 (rust-lang/cargo#14879)
- fix: Remove default registry reference in `info` cmd docs (rust-lang/cargo#14880)
- test(pgo): determine test runnability at compile time (rust-lang/cargo#14874)
- test: `requires` attribute accepts string literals for cmds (rust-lang/cargo#14875)
- chore(deps): update msrv (3 versions) to v1.81 (rust-lang/cargo#14871)
- chore(deps): update msrv (rust-lang/cargo#14867)
- fix(fix): Migrate cargo script manifests across editions (rust-lang/cargo#14864)
- feat(toml): Allow adding/removing from cargo scripts (rust-lang/cargo#14857)
- Add future-incompat warning against keywords in cfgs and add raw-idents (rust-lang/cargo#14671)
- test(build-std): download deps first (rust-lang/cargo#14861)
- test(pgo): ensure PGO works (rust-lang/cargo#14859)
- git-fetch-with-cli: Set `GIT_DIR` for bare repository compatibility (rust-lang/cargo#14860)
- fix(build-std): always link to std when testing proc-macros (rust-lang/cargo#14850)
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
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants