Allow &&, ||, and ! in cfg#3796
Conversation
|
I think that a |
|
The problem I see with |
|
That interpretation feels like a stretch to me, but it's also understandable. Perhaps a |
|
Updated the following:
|
The problem here is that
|
|
I read As mentioned above, It isn't even commutative: Using If we do want to make cfg() take something that looks like an expression, we should also change the |
|
Let's look at a real world example: #[cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "freebsd"))]This proposal would allow rewriting that as: #[cfg(target_os = "android" || target_os = "linux" || target_os = "emscripten" || target_os = "freebsd"))]Which looks a bit nicer. But instead of just replacing #[cfg(target_os = "android" | "linux" | "emscripten" | "freebsd")]I don't want to derail this thread with alternative proposals, but I do think that |
How would they not be the same? The RFC, I think, intents for both of these to mean the same thing: the |
|
|
|
Ah. That seems entirely consistent to me, it's I like |
|
My point is that we need tot look at real world examples of code we're trying to simplify. For example, quite often, Large cfg() attributes can be very confusing. But replacing |
|
Rust parses One might argue that I would assume it interprets that as two So even in an attribute, I'd argue that |
|
maybe embrace that they are sets and allow using |
I would go so far as to argue that #[cfg(any(
feature = "foo",
feature = "bar",
feature = "baz",
feature = "quux",
feature = "magic",
test
))]Whereas a similar boolean expression is less regular and longer: something(cfg(
feature == "foo"
|| feature == "bar"
|| feature == "baz"
|| feature == "quux"
|| feature == "magic"
|| test,
));(And there are probably even messier cases to present with On the other hand, supporting |
GitHub really needs a 😢 emoji. To be compatible with this existing syntax, it means all #[cfg((target_os="linux") && (target_arch="x86_64") && (target_env="gnu") && !debug_assertions)] |
Yes the formatting is strange, but I'd argue that the binary operator makes the
|
|
|
|
|
@m-ou-se wrote:
Agreed completely. I don't think it would be ambiguous here to reuse "feature" without adding "has_": |
Technically this change of syntax will conflict with the cfg_version feature but since it is unstable it is fine...? (plus can't use #![feature(cfg_version)]
fn main() {
dbg!(cfg!(version("1.69.0")));
dbg!(cfg!(version("2.0.0")));
dbg!(cfg!(version = "1.69.0"));
dbg!(cfg!(version = "2.0.0"));
}$ rustc +nightly --cfg 'version="2.0.0"' 1.rs
$ ./1
[1.rs:3:2] cfg!(version("1.69.0")) = true
[1.rs:4:2] cfg!(version("2.0.0")) = false
[1.rs:5:2] cfg!(version = "1.69.0") = false
[1.rs:6:2] cfg!(version = "2.0.0") = true |
|
Simple Boolean operations are one thing, but what I’m really hoping for is the ability to compare values, something that’s quite common in C macros, like:
But in Rust, there’s currently no way to express this, which leads to some rather awkward workarounds. Right now, the values in Rust’s
|
|
@jmjoy That would fundamentally change what |
|
There have been proposals for key-value features, and I'd expect such a proposal to talk about how to use them in |
|
It would be nice if this RFC also specified a new |
That's a good point. This document should, I think, discuss the effect of this on macro fragment specifiers and propose solutions, perhaps using our guidance in #3531, if appropriate. @rfcbot concern discuss-effect-on-macro-fragment-specifiers |
|
Sure, things like |
Right now, the only thing they “need to work around” is
Footnotes
|
|
How common are macros that need to handle the internal part of Essentially, my argument is that this scenario is sufficiently uncommon that it is not worth the added language complexity for a rarely used macro fragment specifier. |
I just cited three examples. If you feel that defining an entirely new specifier is too much complexity, one alternative would be to re-use |
I meant in general, everyday code. Defining macros like that is not common, presumably, hence my question. My belief is that manipulating the contents of For what it's worth, |
|
Actually, I realized that |
|
See rust-lang/rust#145060 for previous discussion on
|
Increasingly I am thinking that this is probably the best solution. |
|
@rfcbot resolve discuss-effect-on-macro-fragment-specifiers |
|
|
Regarding precedence, would it be easier to pass the RFC if instead we required |
|
What would be an example of something that would not be accepted under that rule but would be accepted with |
|
I believe they would be identical — that's what I meant in my previous comment. Eliminate the carveout and require parentheses. |
|
That would indeed resolve my concern. |
|
@traviscross I've added a commit removing the precedence carveout while also adding a couple notes. |
|
Thanks. That resolves this concern: @rfcbot resolve uncomfortable-with-precedence-carve-out |
|
Since the proposal has now changed, and as there are no outstanding filed concerns to track, for procedural reasons, I'm going to cancel the proposed FCP. @rfcbot fcp cancel I'm not going to restart immediately, since I personally want to see other work, such as @tmandry's upcoming |
|
@traviscross proposal cancelled. |
|
A year on from when FCP was initially proposed and 8 months out from the most recent comment, what does @rust-lang/lang think of this? There has been time to consider interaction with |
View all comments
About as simple as it gets.
Rendered