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

check-cfg tests are prone to merge conflicts #135995

Closed
jyn514 opened this issue Jan 24, 2025 · 4 comments · Fixed by #136016
Closed

check-cfg tests are prone to merge conflicts #135995

jyn514 opened this issue Jan 24, 2025 · 4 comments · Fixed by #136016
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-testsuite Area: The testsuite used to check the correctness of rustc F-check-cfg --check-cfg T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Jan 24, 2025

Right now, the tests in tests/ui/check-cfg/ contain every built-in config known to the compiler, like so:

= 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`

this means they have to be updated each time a new builtin cfg is added, which is annoying, prone to merge conflicts, and distracts from what the test is actually doing. Also, it's just not a very good diagnostic? If you name a check-cfg something the compiler doesn't know, an exhaustive list of things it does know is probably not the thing you want.

I suggest one or more of the following:

@rustbot label A-testsuite A-diagnostics F-check-cfg

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. A-diagnostics Area: Messages for errors, warnings, and lints A-testsuite Area: The testsuite used to check the correctness of rustc F-check-cfg --check-cfg labels Jan 24, 2025
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 24, 2025
@jieyouxu
Copy link
Member

cc @Urgau do you have any preferences for this?

@Urgau
Copy link
Member

Urgau commented Jan 24, 2025

I prefer if we normalize the output, it's irrelevant for the test.

I had a few sparse minutes and did it my-self in #136016.

@Urgau Urgau removed the C-bug Category: This is a bug. label Jan 24, 2025
@Urgau
Copy link
Member

Urgau commented Jan 24, 2025

Also, it's just not a very good diagnostic? If you name a check-cfg something the compiler doesn't know, an exhaustive list of things it does know is probably not the thing you want.

When I ported some code base as part the stabilization effort, having that list was helpful for the custom cfgs.

It should also be noted that the list is only printed once (always the first warning) as to reduce the visual impact.

@Urgau
Copy link
Member

Urgau commented Jan 25, 2025

Add a limit for the number of cfgs we will suggest at once

Btw, we already have a limit, it's currently 35.

const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35;

@bors bors closed this as completed in dbe911a Jan 26, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue 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
A-diagnostics Area: Messages for errors, warnings, and lints A-testsuite Area: The testsuite used to check the correctness of rustc F-check-cfg --check-cfg T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants