Feature gate boolean lit support in cfg predicates
This commit is contained in:
parent
c99f29b29f
commit
62ef411631
8 changed files with 116 additions and 2 deletions
|
@ -18,7 +18,7 @@ use rustc_session::parse::feature_err;
|
|||
use rustc_session::{RustcVersion, Session};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::hygiene::Transparency;
|
||||
use rustc_span::symbol::{Symbol, sym};
|
||||
use rustc_span::symbol::{Symbol, kw, sym};
|
||||
|
||||
use crate::fluent_generated;
|
||||
use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
|
||||
|
@ -603,7 +603,23 @@ pub fn eval_condition(
|
|||
|
||||
let cfg = match cfg {
|
||||
ast::NestedMetaItem::MetaItem(meta_item) => meta_item,
|
||||
ast::NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => return *b,
|
||||
ast::NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
|
||||
if let Some(features) = features {
|
||||
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
|
||||
// and `true`, and we want to keep the former working without feature gate
|
||||
gate_cfg(
|
||||
&((
|
||||
if *b { kw::True } else { kw::False },
|
||||
sym::cfg_boolean_literals,
|
||||
|features: &Features| features.cfg_boolean_literals,
|
||||
)),
|
||||
cfg.span(),
|
||||
sess,
|
||||
features,
|
||||
);
|
||||
}
|
||||
return *b;
|
||||
}
|
||||
_ => {
|
||||
dcx.emit_err(session_diagnostics::UnsupportedLiteral {
|
||||
span: cfg.span(),
|
||||
|
|
|
@ -371,6 +371,8 @@ declare_features! (
|
|||
(unstable, async_for_loop, "1.77.0", Some(118898)),
|
||||
/// Allows using C-variadics.
|
||||
(unstable, c_variadic, "1.34.0", Some(44930)),
|
||||
/// Allows the use of `#[cfg(<true/false>)]`.
|
||||
(unstable, cfg_boolean_literals, "CURRENT_RUSTC_VERSION", Some(131204)),
|
||||
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
|
||||
(unstable, cfg_overflow_checks, "1.71.0", Some(111466)),
|
||||
/// Provides the relocation model information as cfg entry
|
||||
|
|
|
@ -543,6 +543,7 @@ symbols! {
|
|||
cfg_accessible,
|
||||
cfg_attr,
|
||||
cfg_attr_multi,
|
||||
cfg_boolean_literals,
|
||||
cfg_doctest,
|
||||
cfg_eval,
|
||||
cfg_fmt_debug,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue