rust/compiler/rustc_lint/src
bors c58a5da7d4 Auto merge of #119930 - Urgau:check-cfg-empty-values-means-empty, r=petrochenkov
Add way to express that no values are expected with check-cfg

This PR adds way to express no-values (no values expected) with `--check-cfg` by making empty `values()` no longer mean `values(none())` (internal: `&[None]`) and now be an empty list (internal: `&[]`).

### Context

Currently `--check-cfg` has a way to express that _any value is expected_ with `values(any())`, but has no way to do the inverse and say that _no value is expected_.

This would be particularly useful for build systems that control a config name and it's values as they could always declare a config name as expected and if in the current state they have values pass them and if not pass an empty list.

To give a more concrete example, Cargo `--check-cfg` currently needs to generate:
 - `--check-cfg=cfg(feature, values(...))` for the case with declared features
 - and `--check-cfg=cfg()` for the case without any features declared

This means that when there are no features declared, users will get an `unexpected config name` but from the point of view of Cargo the config name `feature` is expected, it's just that for now there aren't any values for it.

See [Cargo `check_cfg_args` function](92395d9010/src/cargo/core/compiler/mod.rs (L1263-L1281)) for more details.

### De-specializing *empty* `values()`

To solve this issue I propose that we "de-specialize" empty `values()` to no longer mean `values(none())` but to actually mean empty set/list. This is one of the last source of confusion for my-self and others with the `--check-cfg` syntax.

> The confusing part here is that an empty `values()` currently means the same as `values(none())`, i.e. an expected list of values with the _none_ variant (as in `#[cfg(name)]` where the value is none) instead of meaning an empty set.

Before the new `cfg()` syntax, defining the _none_ variant was only possible under certain circumstances, so in https://github.com/rust-lang/rust/pull/111068 I decided to make `values()` to mean the _none_ variant, but it is no longer necessary since https://github.com/rust-lang/rust/pull/119473 which introduced the `none()` syntax.

A simplified representation of the proposed "de-specialization" would be:

| Syntax                                  | List/set of expected values |
|-----------------------------------------|-----------------------------|
| `cfg(name)`/`cfg(name, values(none()))` | `&[None]`                   |
| `cfg(name, values())`                   | `&[]`                       |

Note that I have my-self made the mistake of using an empty `values()` as meaning empty set, see https://github.com/rust-lang/cargo/pull/13011.

`@rustbot` label +F-check-cfg
r? `@petrochenkov`
cc `@epage`
2024-01-17 14:01:05 +00:00
..
context Add way to express no-values with check-cfg 2024-01-13 17:19:46 +01:00
nonstandard_style
array_into_iter.rs make the reason: field mandatory for @future_incompatible lints 2023-09-22 08:59:32 +02:00
async_fn_in_trait.rs Don't ICE when encountering unresolved regions in fully_resolve 2023-10-18 20:39:29 +00:00
builtin.rs Add check for ui_testing via promoting parameters from ParseSess to Session 2024-01-13 12:11:13 -05:00
context.rs check rust lints when an unknown lint is detected 2024-01-12 18:50:36 +08:00
deref_into_dyn_supertrait.rs Rework supertrait lint once again 2023-11-22 21:51:39 +00:00
drop_forget_useless.rs Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
early.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
enum_intrinsics_non_enums.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
errors.rs Rename some Diagnostic setters. 2024-01-03 19:40:20 +11:00
expect.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
for_loops_over_fallibles.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
foreign_modules.rs Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives. 2024-01-04 13:32:42 +01:00
hidden_unicode_codepoints.rs migrate: hidden_unicode_codepoints.rs 2023-01-09 17:07:25 -05:00
internal.rs rustc_span: Optimize syntax context comparisons 2024-01-06 01:25:20 +03:00
invalid_from_utf8.rs Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
late.rs rustc: hir().local_def_id_to_hir_id() -> tcx.local_def_id_to_hir_id() cleanup 2023-11-26 12:41:21 +03:00
let_underscore.rs Fix 2 variable binding issues in let_underscore 2024-01-08 16:50:14 +08:00
levels.rs Add check for ui_testing via promoting parameters from ParseSess to Session 2024-01-13 12:11:13 -05:00
lib.rs Make inductive cycles in coherence ambiguous always 2024-01-08 15:03:59 +00:00
lints.rs Add check for ui_testing via promoting parameters from ParseSess to Session 2024-01-13 12:11:13 -05:00
map_unit_fn.rs Fix #109152, fix the scenario that we may can not get span of func 2023-03-15 14:07:39 +08:00
methods.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
multiple_supertrait_upcastable.rs Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
non_ascii_idents.rs Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives. 2024-01-04 13:32:42 +01:00
non_fmt_panic.rs rustc_span: Optimize syntax context comparisons 2024-01-06 01:25:20 +03:00
nonstandard_style.rs Remove #[rustc_host], use internal desugaring 2023-12-05 01:15:21 +00:00
noop_method_call.rs Fix noop_method_call detection for new diagnostic items 2023-09-28 08:22:59 -04:00
opaque_hidden_inferred_bound.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
pass_by_value.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
passes.rs Remove rustc_lint_defs::lint_array 2023-09-28 23:01:25 +02:00
ptr_nulls.rs Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
redundant_semicolon.rs refactor: cleanup 2023-01-09 18:57:02 -05:00
reference_casting.rs Recurse into let bindings if possible in ref casting lint 2023-12-14 17:27:14 +01:00
tests.rs refactor(rustc_lint): inline check_lint_name_cmdline 2023-08-30 17:35:07 +01:00
traits.rs make comments less cryptic 2023-09-06 12:09:29 +03:00
types.rs Simplify some redundant names 2024-01-10 16:29:23 +00:00
unit_bindings.rs Add allow-by-default lint for unit bindings 2023-11-20 11:45:44 +08:00
unused.rs Auto merge of #117321 - chenyukang:yukang-fix-117142, r=petrochenkov 2024-01-12 22:15:55 +00:00