-
Notifications
You must be signed in to change notification settings - Fork 23
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
Probe rustc channel #33
Conversation
@cuviper Just a friendly ping. Did you have any thoughts or feedback on this? |
I think I would rather avoid the channel stuff, especially since there are knobs like If we just support probing features with an actual
I don't think that should be conditional at all -- just do as asked and let further use fail when that feature isn't actually supported. |
Wow, TIL about
I completely agree with you on this one. Taking a second look, I don't know if What if this was simplified to literally just be:
This would drop any need to parse let mut ac = autocfg::new();
ac.set_feature("step_trait");
ac.emit_has_trait("core::iter::Step");
ac.unset_feature("step_trait");
// Other probes that don't require the feature. Do you think this would be sufficient? |
You can also Bikeshedding the name -- is |
Changing the names is fine with me. You're right, I think I went with Since this PR includes quite a bit of stuff that isn't going to be included, it seemed easier to open another PR. Hope you don't mind, I'm closing this in favor of #35. |
This PR introduces the ability to probe for the current channel (stable, beta, nightly, dev). It is a solution for issue #28 and also addresses some functionality requested in issue #24.
Firstly, this PR introduces a
Channel
enum, stored inAutoCfg
, denoting which channel is being used.PartialOrd
andOrd
are also defined on this enum, where ordering is defined by available features. In other words, a channel is defined to be "less than" another channel if it contains a subset of available features. So, the channels would be ordered likeStable < Beta < Nightly < Dev
.Secondly, there are seven methods added to
AutoCfg
. They are:rustc_channel()
- Accessor method to the currentChannel
. I was on the fence about exposing this, since the currentVersion
is not actually exposed directly, but I thought it could be useful for users to be able to directlymatch
against it. I'm open to any thoughts on this :)probe_rustc_channel()
- To test whether the currentChannel
supports the providedChannel
. For example,ac.probe_rustc_channel(Stable)
will always be true, butac.probe_rustc_channel(Nightly)
will only be true onnightly
anddev
channels.emit_rustc_channel()
- Same concept as above, but emits acfg
if the probe is true.probe_feature()
- To test whether a feature can be set. Will always return false if not on nightly or dev.emit_feature_cfg()
- Emits acfg
if the feature is available.set_feature()
- Sets a feature to be allowed before each subsequent probe. Basically the same idea as what is being done withno_std
in Add getterno_std()
and setterset_no_std(bool)
#27. This doesn't do anything on stable/beta channels, which is good as it allows probes to succeed still if running on a later rustc version where the desired feature may have already been stabilized.unset_feature()
- Removes a feature that has been set. I'm not sure how useful this will be, as I don't know what benefit could be provided by adding a feature and then later removing it, but it was really easy to add on.This seemed like the best API for interacting with nightly features. If the API addition is too large, it might make sense to just expose
set_feature()
andunset_feature()
, since the real end-goal is for users to be able to probe the functionality provided by the feature, but it seemed like there is some interest in users probing the features, or even the channel itself, directly. I'm definitely up for discussion on this.