-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 way to express that no values are expected with check-cfg #119930
Add way to express that no values are expected with check-cfg #119930
Conversation
This comment has been minimized.
This comment has been minimized.
35f649e
to
41b69aa
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (c58a5da): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 665.924s -> 664.091s (-0.28%) |
Go back to passing an empty `values()` when no features are declared This PR is basically a revert of #13011, which made the `--check-cfg` invocation be `cfg()` when no features are declared instead of `cfg(feature, values())` since it meant declaring that the config `feature` were to be available in this form: `#[cfg(feature)]`, which is not the case. Thankfully after some brainstorming, I [proposed](rust-lang/rust#119930) changing the behavior of empty `values()` in `rustc` to no longer imply the _none_ value and simply create an empty set of expected values. 😃 For Cargo, always using `cfg(feature, values(...))` means that the config `feature` is always expected, regardless of the number of features. This makes the warning better, as it will now always be `unexpected config value` (instead of `unexpected config name`). 🎉 Fixes #13011 (comment) as well as the concern in the [tracking issue](#10554). r? `@epage`
This PR adds way to express no-values (no values expected) with
--check-cfg
by making emptyvalues()
no longer meanvalues(none())
(internal:&[None]
) and now be an empty list (internal:&[]
).Context
Currently
--check-cfg
has a way to express that any value is expected withvalues(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--check-cfg=cfg()
for the case without any features declaredThis 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 namefeature
is expected, it's just that for now there aren't any values for it.See Cargo
check_cfg_args
function for more details.De-specializing empty
values()
To solve this issue I propose that we "de-specialize" empty
values()
to no longer meanvalues(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.Before the new
cfg()
syntax, defining the none variant was only possible under certain circumstances, so in #111068 I decided to makevalues()
to mean the none variant, but it is no longer necessary since #119473 which introduced thenone()
syntax.A simplified representation of the proposed "de-specialization" would be:
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 rust-lang/cargo#13011.@rustbot label +F-check-cfg
r? @petrochenkov
cc @epage