Rollup merge of #138767 - clubby789:check-cfg-bool, r=Urgau

Allow boolean literals in `check-cfg`

https://github.com/rust-lang/rust/pull/138632#issuecomment-2738114495
This makes it consistent with `--cfg`

We could alternatively add a forward-compatible lint against `--cfg true/false`
r? `@Urgau`
This commit is contained in:
Matthias Krüger 2025-04-03 21:18:30 +02:00 committed by GitHub
commit 9d733eca06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 24 deletions

View file

@ -570,6 +570,14 @@ impl MetaItemInner {
}
}
/// Returns the bool if `self` is a boolean `MetaItemInner::Literal`.
pub fn boolean_literal(&self) -> Option<bool> {
match self {
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => Some(*b),
_ => None,
}
}
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem` or if it's
/// `MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
pub fn meta_item_or_bool(&self) -> Option<&MetaItemInner> {