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 2 times, most recently from 89428c0 to a02fbf2 Compare October 11, 2024 12:04
@Urgau Urgau force-pushed the cfg-keyword-and-raw-idents branch 2 times, most recently from 0087199 to aa8bb59 Compare October 11, 2024 13:35
@@ -550,9 +550,26 @@ fn cfg_keywords() {

p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: `cfg(async)` is deprecated as `async` is a keyword and not an identifier and should not have have been accepted in this position.
Copy link
Contributor

Choose a reason for hiding this comment

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

Rustc makes this conditioned on the edition

Compare
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3e7b39ec2db740f36b54d9fd0e93eaaa
with
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=8e0ec47ce0d8c34e642dbcdc5abf622c

We can make this dependent on the edition for Cargo.toml but not .cargo/config.toml. We'll need to figure out how we want to handle this

Copy link
Contributor

Choose a reason for hiding this comment

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

One solution is to make this only relevant for true / false which is what I had scoped my comments to in #14649 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed that to (and forgot to mentioned it, my bad). Idk how Cargo should handle edition keywords.

However I don't think we should only do it for true/false, the other ones are wrong (even if some are not only wrong in some peculiar way), it would inconsistent to allow some and warn on the others.

My stance on the PR is to consider then independently of their "edition"-ness, which could be reversed by excluding any edition keyword until we figure out how to handle them (which would only remove a few of them and keep the vast majority).

Copy link
Contributor

Choose a reason for hiding this comment

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

The conversation on this was specifically scoped to "we shouldn't break people now for true / false"

If nothing else, expanding the scope beyond that will mire this in decisions that need to be made vs a simple sign off.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not in a rush.

I think it would be better to handle all of them in one go, but if you specifically only want to handle true/false I can separate the others keywords and do a follow up PR with them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer it if we split these conversations up.

tests/testsuite/cfg.rs Outdated Show resolved Hide resolved
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants