-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for RFC 2523, #[cfg(version(..))]
#64796
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. |
I hit a bug in Rustc today, where rustc fails to derive This is important for the project I'm working on as it's Mesa, the OpenGL/Vulkan/OpenCL/etc.. implementation for the Linux desktop and we need to be mindful of what Rustc version to support. Edit: Apparently it was |
+1 to this, because you have to take the entire ecosystem and tooling into account and not just the language itself. For example, in rsconf 0.2, I added an api that uses |
Nominating for lang-team discussion. This was marked as blocked on #64797 two years ago but #64797 still has open design questions and does not appear ready for stabilization anytime soon whereas this feature has no open design questions and is fully implemented. Since #64797 does not address some important use cases such as conditionally using compiler or language features and use of @rustbot label +I-nominated |
Not to add to the pressure or anything, but for a feature with the raison d’être being backwards compatibility this one won't be a viable alternative to the |
@mqudsi yes, though if the cfg gets renamed to |
We discussed this in the lang call today. We had a question: What's the situation on stabilizing a minimum version of We understood there were issues with a more general version of the feature, and we understand there are some issues with paths in attributes, but we were unclear on whether stabilizing the most minimal If it is within the realm of possibility, the feeling was generally that we'd prefer to do that, and that such a minimum version would resolve the concern here and allow for the stabilization of On the other hand, if it's not within the realm of short-term possibility for some reason, then people were open to reevaluating the approach here and whether other options might be possible for moving this forward. |
@rustbot labels -I-lang-nominated Going to unnominate this for now, but please renominate when the answer to the question above is available. |
If stabilizing this soon is out of the question and in case renaming the cfg is not desirable, would it be possible to change the error to a future incompatibility warning now. Similar to how cargo switched public/private dependencies to a non-blocking feature gate rust-lang/cargo#13308 |
Quick note on a potentially useful enhancement to this, once we have it: cargo could pass the crate's MSRV (from the |
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. |
This is a tracking issue for
#[cfg(version(..))]
(rust-lang/rfcs#2523).Steps:
Unresolved 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: