Skip to content

Improve invalid cfg predicate error#157613

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
evavh:invalid-predicate-error
Jun 13, 2026
Merged

Improve invalid cfg predicate error#157613
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
evavh:invalid-predicate-error

Conversation

@evavh

@evavh evavh commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

I have improved the error that is emitted when a non-existant cfg attribute is used. I removed the InvalidPredicate diagnostic, which does not provide much information, and used the function expected_specific_argument instead. This provides a nice link to the documentation. I have also blessed and updated the ui tests that broke because of this change.

Before:

error[E0537]: invalid predicate `does_not_exist`
 --> bad_error.rs:2:7
  |
2 | #[cfg(does_not_exist())]
  |       ^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

After:

error[E0539]: malformed `cfg` attribute input
 --> bad_error.rs:2:1
  |
2 | #[cfg(does_not_exist())]
  | ^^^^^^----------------^^
  |       |
  |       valid arguments are `any`, `all`, `not`, `target` or `version`
  |
  = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute>
help: must be of the form
  |
2 - #[cfg(does_not_exist())]
2 + #[cfg(predicate)]
  |

r? @JonathanBrouwer

@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 8, 2026
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JonathanBrouwer (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

span: meta.span(),
predicate: meta.path().to_string(),
}));
let possibilities = &[sym::any, sym::all, sym::not, sym::target, sym::version];

@JonathanBrouwer JonathanBrouwer Jun 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmmm, "version" is an unstable predicate, could you only mention it if the corresponding feature gate is enabled?

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 8, 2026
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

Other than that it seems good, thanks a lot for the improvement!

@rust-log-analyzer

This comment has been minimized.

@evavh
evavh force-pushed the invalid-predicate-error branch from a2009b1 to 91ee8a5 Compare June 12, 2026 10:23
@rustbot

This comment has been minimized.

@evavh

evavh commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

I added the feature check! It seems one of the tests failed last time, I'm not sure why.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 12, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@evavh The change looks good, thanks!
The test that is failing is from the error-code index, you can reproduce this with ./x test error-index.
You need to remove the expected E0537 code from the example in the md.

@evavh
evavh force-pushed the invalid-predicate-error branch from 6216e84 to 851ab7a Compare June 13, 2026 14:20
@rustbot

rustbot commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@JonathanBrouwer JonathanBrouwer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bors r+ rollup
Thanks a lot! <3

View changes since this review

@rust-bors

rust-bors Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 851ab7a has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 13, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 13, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #157201 (Move logic for emitting UNSAFE_CODE for unsafe attributes to attr parsing)
 - #157613 (Improve invalid cfg predicate error)
 - #157838 (rustdoc: Don't strip hidden items in `AliasedNonLocalStripper`)
@rust-bors
rust-bors Bot merged commit d1a2046 into rust-lang:main Jun 13, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants