Comments (12)
I don't think this alone is worth a release, given that it would introduce a transition period where crates would be using both for a while. If we have other features motivating a major release then we could include this as well.
But personally, I would love to see this included in the standard library instead. If people are going to go through a transition, let's have them go through a transition to the version in the standard library.
from cfg-if.
My gut reaction is that you shouldn't allow something like this because quirks like that that you aren't expecting could lead to bugs. This would be an opportunity to accidentally forget the if
of the statement which would be a logic error in ( I think ) every instance.
I mean, imagine if rustc
let us have else
's without if
's.
If it is a big pain to fix from an implementation perspective, though, then I think that documenting the quirk would be reasonable enough.
from cfg-if.
This is fixed on the current master, appears to be changed in 3499136
Any hope this gets released? The commit is one year old.
I'd happily take this. I'm using cfg_if
quite heavily for architectural dependencies and I've already had a confusing bug whose root cause was a missing if
due to some copy-paste error. There's no use case for allowing this syntax, I'd prefer it to be rejected.
from cfg-if.
I think this is just a mistake of the macro! It's not an intended use case but I don't really think it's that big of an issue to either document or prohibit. It seems like sort of a weird quirk at best?
from cfg-if.
I agree with @alexcrichton. But I would add that I think an else
clause by itself is kinda cute.
from cfg-if.
I don’t think there’s no use case. I can imagine realistic code depending on this behaviour. Something along these lines:
use cfg_if::cfg_if;
// Several different implementations of a thing
#[derive(Debug)] struct Windows;
#[derive(Debug)] struct Unix;
#[derive(Debug)] struct Fallback;
macro_rules! demo {
($($x:ident => $y:expr),*) => {{
cfg_if! {
$(
if #[cfg($x)] {
$y
}
)else*
else {
Fallback
}
}
}}
}
fn main() {
println!("{:?}", demo!());
println!("{:?}", demo!(unix => Unix, windows => Windows));
}
That single-character change of *
to +
is a breaking change; although I doubt that anyone is depending on it, I reckon it should either be reverted, or the next release called 2.0.0.
(It’s pure coincidence that I’m commenting less than a day after you: I just happen to be starting doing detailed code review of crates starting with this one today.)
from cfg-if.
Yes, this is technically a breaking change, so semver requires that release be 2.0.0. That's fine by me, I'd just like to see this released, it's frozen on master which is simply a waste :)
from cfg-if.
@rust-lang/crate-maintainers Any thoughts on this? I think releasing it as 2.0.0 makes some sense but also concerned that would affect a lot of crates. The decision here seems important.
from cfg-if.
That sounds great, thank you!
Then I'm going to do the following if no one raises any objections in a few days:
- revert
else+
toelse*
in this crate - submit a PR as a proposal to include it in the stdlib
from cfg-if.
@JohnTitor There's already an internal copy in the stdlib; I put it there. The PR would just need to propose stabilizing it.
(Also, you might add a comment next to the version number in Cargo.toml
saying if this ever needs bumping to a new major version then we should fix this.)
from cfg-if.
If we're considering moving this to the standard library (which I wholly support!) then we should perhaps consider whether to introduce language-level syntax for this considering how widely used cfg_if
is. However this discussion is starting to be off-topic for this issue.
Regarding the issue itself, I agree that we should not do a 2.0.0 release just for this.
from cfg-if.
Any progress on moving this to the standard library?
from cfg-if.
Related Issues (20)
- Strange compilation error on CI with backtrace-rs crate due to cfg-if HOT 6
- #[allow(clippy::assertions_on_constants)] does not work on older versions of Rust HOT 1
- rustfmt-formattable syntax? HOT 2
- Forbid unsafe code HOT 2
- cargo build failed permission denied HOT 1
- `%` anywhere in project path causes "error: could not compile `cfg-if`" HOT 4
- Allow in expression position HOT 5
- failed build release aarch64-apple-ios HOT 11
- found crate `cfg_if` compiled by an incompatible version of rustc HOT 1
- Failed to build under win64 HOT 3
- use of undeclared crate or module `cfg_if` on Appveyor HOT 1
- Leftover Travis CI reference
- A crate to parametrize compile-time conditionals? HOT 3
- unexpected behavior inside struct, for feature-gated arguments
- Set minimal permissions to github workflow
- Hash pin main.yml dependencies.
- Automated releases
- "A" should be "an" in the project description HOT 1
- Merge cfg-if into std? HOT 2
- error: could not compile `cfg-if` (lib) due to 1 previous error for mipsel-unknown-linux-musl HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cfg-if.