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

Improve check-cfg expected names diagnostic #136016

Merged
merged 3 commits into from
Jan 26, 2025

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Jan 24, 2025

This PR improves the check-cfg allow-same-level test by normalizing it's output and by adding more context to the test.

It also filters the well known cfgs from the expected names are note, as to reduce the size of the diagnostic. Users can still find the full list on the rustc book, which is reinforced for Cargo users by adding a note in the Cargo check-cfg specific section.

Fixes #135995
r? @jieyouxu

@rustbot rustbot added 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 Jan 24, 2025
@jyn514
Copy link
Member

jyn514 commented Jan 24, 2025

This is not specific to the one test, it applies to nearly all the tests in the check-cfg directory.

@Urgau
Copy link
Member Author

Urgau commented Jan 24, 2025

Many of the other tests have custom (non-builtin) check-cfgs which are reflected in the output. I can take a look at trimming those that never uses it but it will never be zero tests.

@jyn514
Copy link
Member

jyn514 commented Jan 24, 2025

Right. this is why i suggested trimming builtin cfgs in the diagnostics, not during normalization, because they are noisy and i don't think they're actually very helpful.

@Urgau
Copy link
Member Author

Urgau commented Jan 24, 2025

Oh, you mean only trimming the builtins but still showing the custom ones (if there any)?

I though you meant removing the entire line. I kind of like this idea, and if the users wants to see the builtins, aka well known, they can see the full list on the rustc book.

@Urgau Urgau 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 Jan 24, 2025
@Urgau Urgau changed the title Improve check-cfg allow-same-level test Improve check-cfg expected names diagnostic Jan 25, 2025
|
LL | #[cfg(tokio_unstable)]
| ^^^^^^^^^^^^^^
|
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `ub_checks`, `unix`, and `windows`
= help: expected names are: `docsrs`, `feature`, and `test` and 30 more
Copy link
Member Author

Choose a reason for hiding this comment

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

With this PR, Cargo users would now only see those 3 cfgs (which are Cargo defined) instead of the long list.

Comment on lines +4 to +35
LL | #[cfg(list_all_well_known_cfgs)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: expected names are: `clippy`
`debug_assertions`
`doc`
`doctest`
`fmt_debug`
`miri`
`overflow_checks`
`panic`
`proc_macro`
`relocation_model`
`rustfmt`
`sanitize`
`sanitizer_cfi_generalize_pointers`
`sanitizer_cfi_normalize_integers`
`target_abi`
`target_arch`
`target_endian`
`target_env`
`target_family`
`target_feature`
`target_has_atomic`
`target_has_atomic_equal_alignment`
`target_has_atomic_load_store`
`target_os`
`target_pointer_width`
`target_thread_local`
`target_vendor`
`ub_checks`
`unix`, and `windows`
Copy link
Member Author

Choose a reason for hiding this comment

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

For anti-regression and explicit-ness purpose I kept one place with the full list and applied the same trick as in #133710 to reduce merge conflicts.

@@ -14,7 +14,7 @@ warning: unexpected `cfg` condition name: `r#false`
LL | #[cfg(r#false)]
| ^^^^^^^
|
= help: expected names are: `r#async`, `clippy`, `debug_assertions`, `doc`, `doctest`, `edition2015`, `edition2021`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `r#true`, `ub_checks`, `unix`, and `windows`
= help: expected names are: `r#async`, `edition2015`, `edition2021`, and `r#true` and 30 more
Copy link
Member Author

Choose a reason for hiding this comment

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

This double and ... and 30 more is unfortunate (and pre-existing). DiagSymbolList doesn't gives us enough control to says that the list has been truncated by X amount, and even if it did, icu_list doesn't seems to have a way to say that the list has been truncated either.

We could hack it around in check-cfg by adding a fake "X more" in the list. Idk if it's worth it.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is totally fine

@Urgau Urgau 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 Jan 25, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks, I think this should indeed help with merge conflicts quite a lot.

@@ -14,7 +14,7 @@ warning: unexpected `cfg` condition name: `r#false`
LL | #[cfg(r#false)]
| ^^^^^^^
|
= help: expected names are: `r#async`, `clippy`, `debug_assertions`, `doc`, `doctest`, `edition2015`, `edition2021`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `r#true`, `ub_checks`, `unix`, and `windows`
= help: expected names are: `r#async`, `edition2015`, `edition2021`, and `r#true` and 30 more
Copy link
Member

Choose a reason for hiding this comment

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

I think this is totally fine

@jieyouxu
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 25, 2025

📌 Commit 74223e4 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors 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 Jan 25, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#134300 (remove long-deprecated no-op attributes no_start and crate_id)
 - rust-lang#134373 (Improve and expand documentation of pipes)
 - rust-lang#135934 (Include missing item in the 1.81 release notes)
 - rust-lang#136005 (ports last few library files to new intrinsic style)
 - rust-lang#136016 (Improve check-cfg expected names diagnostic)
 - rust-lang#136039 (docs: fix typo in std::pin overview)
 - rust-lang#136056 (Fix typo in const stability error message)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit dbe911a into rust-lang:master Jan 26, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 26, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2025
Rollup merge of rust-lang#136016 - Urgau:check-cfg-allow-test-improv, r=jieyouxu

Improve check-cfg expected names diagnostic

This PR improves the check-cfg `allow-same-level` test by ~~normalizing it's output and by~~ adding more context to the test.

It also filters the well known cfgs from the `expected names are` note, as to reduce the size of the diagnostic. Users can still find the full list on the [rustc book](https://doc.rust-lang.org/nightly/rustc/check-cfg.html#well-known-names-and-values), which is reinforced for Cargo users by adding a note in the Cargo check-cfg specific section.

Fixes rust-lang#135995
r? `@jieyouxu`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

check-cfg tests are prone to merge conflicts
5 participants