-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tracking issue for RFC 2523, #[cfg(version(..))]
#64796
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
Comments
@csmoe Are you working on this? If not I might want to try out this task first since @petrochenkov mentioned that this task is easier than |
@pickfire I didn't have much bandwidth on this, seems you have already made some progress on |
Can anyone please help to write up the mentoring instructions. Based on what I know, this should be similar to #64797 (comment)
I believed step 1 and 2 should be the same. For step 3, based on what I know requires me to modify somewhere around rust/src/libsyntax/attr/builtin.rs Lines 566 to 568 in b56b239
Based on |
Hi, @pickfire. Are you still working on this? |
No, I was stuck working on this and don't know how to proceed. |
Ok, thanks for quick response. I'll take my shot at this. |
@mibac138 Do you want me to publish my progress? |
@pickfire sure, that'd be great! |
@mibac138 Err, no need. You have already done more than me, I don't know how to change the |
Status update: #71314 implemented this RFC with a slightly different syntax - #[cfg(version("1.2.3"))] instead of The reason is that Additionally, the |
Implement RFC 2523, `#[cfg(version(..))]` Hi! This is my first contribution to rust, I hope I didn't miss anything. I tried to implement this feature so that `#[cfg(version(1.44.0))]` works but the parser was printing an error that I wasn't sure how to fix so I just opted for implementing `#[cfg(version("1.44.0"))]` (note the quotes). Tracking issue: rust-lang#64796
The RFC had an unresolved question about how this feature would interact with nightly/beta. Should Currently, the implementation returns true. E.G. for #![feature(cfg_version)]
fn main() {
test();
}
#[cfg(version("1.45.0"))]
fn test() {
println!("Yes")
}
#[cfg(not(version("1.45.0")))]
fn test() {
println!("No")
} IMO, this is a mistake. The main use-case for |
That sounds like good reasoning to me, but I've not been following this RFC that closely. @joshtriplett -- I feel like you were "liaison'ing" for this before we had a term for it, do you have a take? |
Nominating for lang-team meeting to discuss |
Which is most useful, the way it is, AFAICT. Isn't there a way to combine this with cfg test(s) for "train", e.g. beta or nightly and unstable feature gates? |
Code written for the stable compiler should not have to know about beta or nightly. |
I'm not surprised with that as a goal, but I can think of cases where for practical reasons I nead to dev on 1.45 nightly with expectation that it will then work on 1.45 stable. I'm surprised if I'm the only one. |
Be aware that the version field of stability attributes isn't always correct. For example if an item has been moved from libstd to libcore and re-exported in libstd, the libcore version has to retain the version when it was stabilized in libstd as re-exports can't override the version in which it was stabilized. |
I'm unclear when a version cfg will always be false |
@Lokathor With |
@bjorn3 wrote:
Yeah, I realize. We won't necessarily be able to use the existing stability markers for library functions without additional care. |
I think the main time a |
@Lokathor Even in cfg-if, it'd be helpful to get warnings to help you remove unused branches. But yes, we'll have to test and make sure we don't get false positives. |
Regarding the question about what to do with nightly (which came up e.g. here and here), here's some real-world evidence: the fact that existing crates check the rustc version to decide which features they can use means if you are stuck on an old nightly, you may be unable to compile code even if that code's MSRV is older than the nightly you are using (i.e., a stable release from that time would work fine). See here for details. So that would be an argument in favor of treating nightly with an off-by-1. Though it seems the current plan here is to add a |
I’m working on a (so far) nightly-only crate and use cfg(version) to disable feature(…) attributes that are necessary for the crate’s MSRV but may no longer be needed on a later nightly. I generally like the nightly+1 rule, since it errs on the side of robustness. However, the lint for using features that have already been stabilised starts firing as soon as stabilisation occurs on nightly. Whatever nightly version rule cfg(version) ends up going with, the lint should use the same one. If there is a mismatch, e.g. in case cfg(version) does use a nightly+1 rule again, the lint could be split into the current one which would also follow the +1 rule on nightly, and a separate one that would be allow-by-default and fire as soon as a feature is stabilised on nightly but only if the nightly version matches the stabilisation version. |
I've been the primary person who has expressed that we need I'm withdrawing that objection, and I think we should go ahead and ship I still believe it's incredibly important that we have And on the flip side, the sooner we do ship cc @epage @rust-lang/lang |
@rustbot labels -S-blocked +I-lang-radar Given the above, if you are someone who is able and interested in putting together a stabilization PR with a stabilization report for (Have a look at our new draft stabilization report template.) |
@joshtriplett I appreciate the insight from your change in perspective. In particular:
This comparison to browsers puts into perspective for me that Rust using version detection in lieu of feature detection is actually fine, since Rust features are tied to versions unlike browser features which vary wildly across vendors. Also, compile times have been a longstanding pain point of Rust adoption. So reducing the need for build scripts would be another big step along with the great effort that's been made in this area. |
With this unblocked, I realized it would be good to stabilize the rustc and cargo sides at the same time. I've created rust-lang/cargo#15531 to track the Cargo side of this. |
I think a stabilization on the rust side should be pretty straightforward. The one big remaining issue I see is testing. There is only one test right now added by #71314, and it only checks the parsing, not the actual functionality. I suppose we can extend I will file a PR in the coming days. Also needs a stabilization report, but that one should be easy. |
Stabilization PR filed: #141137 I'd like the lang team to decide on whether stabilization should sync up with cargo, or it is better to have support for There is also a limitation in the clippy lint |
I'm unclear on a point: What would be the effect of having it in rustc but not in cargo? Would it be usable on rustc somehow without the cargo support? |
@Lokathor the cargo side is tracked in rust-lang/cargo#15531. It's about supporting it in Cargo.toml, i.e.: [target.'cfg(not(version(1.70.0))`.dependencies]
is-terminal = "0.4.2" The rust side of course will work without cargo. |
This is a tracking issue for
#[cfg(version(..))]
(rust-lang/rfcs#2523).Steps:
#[cfg(version(..))]
#71314Unresolved questions:
What is
cfg(version(...))
relative to in terms of nightly compilers?We could check against what
rustc --version
says, e.g. nightly being1.40.0
, beta being1.39.0
, and stable being1.38.0
. We could also havecfg(version(...))
at most be relative to the beta compiler. See the RFC for a longer discussion.#[cfg(version(..))]
#64796 (comment)Should we also support
version = "..."
so that crates having a MSRV below whenversion(...)
was stabilized can use the flag?Dependency updates cause language changes (src tarballs are vendored without respecting lockfile #79010)
The text was updated successfully, but these errors were encountered: