Skip to content

Commit 674ec04

Browse files
committed
feat(alt): Cover typing/operator overloading
1 parent cab1e93 commit 674ec04

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

text/3857-cfg-version.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,65 @@ so we do not include that information.
533533

534534
## Alternative designs
535535

536+
### `cfg(rust >= "1.95")`
537+
538+
[RFC #3796](https://github.com/rust-lang/rfcs/pull/3796)
539+
will be allowing operators in addition to predicates and it stands to reason that we can extend that
540+
to version comparisons as well.
541+
542+
The expression `rust >= "1.95"` without any other changes would be a string comparison and not a version precedence comparison.
543+
We'd need to add the concept of types to cfg.
544+
We could make check-cfg load-bearing by relying on its type information
545+
or we could add coercion functions to cfg.
546+
547+
So given `--cfg=rust --cfg=rust=version("1.95.0")`, you could do `cfg(rust >= version("1.95"))`.
548+
549+
With typing,
550+
`cfg_values!` (a future possibility) could evaluate to the given type.
551+
So for `--cfg foo=integer("1')`, `cfg_value!(foo)` would be as if you typed `1`.
552+
For versions,
553+
as there is no native Rust type,
554+
we'd likely have it evaluate to a `&'static str`.
555+
556+
[RFC #3796](https://github.com/rust-lang/rfcs/pull/3796)
557+
does not address questions around binary operators,
558+
requiring us to work it out.
559+
For example, are the sides of the operator fully swappable?
560+
If we define all comparisons, would `==` be different than `=`?
561+
How will these operators work in the presence of multiple values or a name-only cfg?
562+
563+
Would we allow implicit coercion so you can skip the `version` inside of `cfg`, like `cfg(rust >= "1.95")`?
564+
I would suggest not because this would make it harder to catch bugs where
565+
- The `--cfg` is not a version but you thought it was
566+
- The `--cfg` should be a version but `version()` was left off
567+
568+
Currently, check-cfg does not apply at all to `--cfg` because it is commonly used with `RUSTFLAGS` which
569+
are applied to all packages and would warn that an unknown `IDENTIFIER` is in use for packages that don't care.
570+
We could still skip checking for unknown `IDENTIFIER`s and instead warn on misuse of `IDENTIFIER`s which would increase the chance of catching a mistake (unless a person duplicated there `--cfg` mistake with `--check-cfg`.
571+
572+
Another is how to handle check-cfg.
573+
The proposed syntax is a binary operator but there is no left-hand side in check-cfg.
574+
Would we accept `cfg(rust, values(>="1.95"))`?
575+
How would we specify types? Would we replace `values` with `versions`?
576+
577+
Adding typing to cfg,
578+
while likely something we'll do one day,
579+
greatly enlarges the scope of this RFC.
580+
This makes it harder to properly evaluate each part,
581+
making it more likely we'll make mistakes.
582+
This further delays the feature as the unstable period is likely to be longer.
583+
We also are not ready to evaluate other use cases for typing to evaluate the impact
584+
and likely won't until we move forward with [global features](https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618)
585+
and `cfg_values!`,
586+
allowing us to cover use cases like embedded using [toml_cfg](https://crates.io/crates/toml-cfg).
587+
588+
If we defer typing, we'll have to allow implicit coercion of values so we can mark `rust` as a version in the future without it being a breaking change.
589+
590+
If we consider typing the correct long term solution but defer it,
591+
we may want to consider the most narrowly scoped solution in the short term,
592+
like `rust_version("1.95")`.
593+
These "big questions" can then have dedicated issues and versions can be built on top of that.
594+
536595
### `version(rust, ">=1.95")`
537596

538597
Instead of having an assumed operator for the predicate,

0 commit comments

Comments
 (0)