rustc: target_features: allow for cfg-only stable target_features#155962
rustc: target_features: allow for cfg-only stable target_features#155962romancardenas wants to merge 1 commit intorust-lang:mainfrom
rustc: target_features: allow for cfg-only stable target_features#155962Conversation
|
rustbot has assigned @nikomatsakis. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
|
There was a problem hiding this comment.
Thanks! This is probably the easiest way to do it. It's not super clean since it cannot represent "feature is allowed in cfg but strictly forbidden otherwise", so the entire thing will need a refactor eventually... but I can't ask you to do that now so let's just go with this.
@rustbot author
| reason, | ||
| }); | ||
| } else if stability.requires_nightly().is_some() { | ||
| } else if stability.requires_nightly(true).is_some() { |
There was a problem hiding this comment.
| } else if stability.requires_nightly(true).is_some() { | |
| } else if stability.requires_nightly(/* in_cfg */ false).is_some() { |
This is where we emit warnings for unstable things in -Ctarget-feature. Yes it's pretty hacky to do that as a side-effect of constructing the cfg data... codegen backend initialization is a terrible spaghetti mess and someone decided this was the place to put that check. 🤷 (It's probably here to avoid emitting the warnings multiple times, or something like that.)
| reason, | ||
| }); | ||
| } else if let Some(nightly_feature) = stability.requires_nightly() | ||
| } else if let Some(nightly_feature) = stability.requires_nightly(false) |
There was a problem hiding this comment.
| } else if let Some(nightly_feature) = stability.requires_nightly(false) | |
| } else if let Some(nightly_feature) = stability.requires_nightly(/* in_cfg */ false) |
| if allow_unstable | ||
| || (gate.in_cfg() | ||
| && (sess.is_nightly_build() || gate.requires_nightly().is_none())) | ||
| && (sess.is_nightly_build() || gate.requires_nightly(true).is_none())) |
There was a problem hiding this comment.
| && (sess.is_nightly_build() || gate.requires_nightly(true).is_none())) | |
| && (sess.is_nightly_build() || gate.requires_nightly(/* in_cfg */ true).is_none())) |
| CfgOnlyStable( | ||
| /// This must be a *language* feature, or else rustc will ICE when reporting a missing | ||
| /// feature gate! | ||
| Symbol, |
There was a problem hiding this comment.
CfgOnlyStable(feature_name) will look odd.
Maybe CfgStableToggleUnstable?
|
Reminder, once the PR becomes ready for a review, use |
This PR introduces a new stabilization level for
target_features:CfgOnlyStable. The motivation is allowing the Rust compiler to exposetarget_featuresof targets so users can usecfg(target_feature = "feature")for conditional blocks depending on target features. However,CfgOnlyStablecannot be used for#[target_feature(enable = "feature")], as this is still considered unstable. Accordingly, the compiler will still raise an error if these expressions are used on stable.This PR relates partially to #150257. As discussed, for RISC-V targets, having the
"d","e", and"f"target features exposed will allow baremetal developers to adapt the code depending on the target's properties.r? @RalfJung