Update to bitflags 2 in the compiler

This involves lots of breaking changes. There are two big changes that
force changes. The first is that the bitflag types now don't
automatically implement normal derive traits, so we need to derive them
manually.

Additionally, bitflags now have a hidden inner type by default, which
breaks our custom derives. The bitflags docs recommend using the impl
form in these cases, which I did.
This commit is contained in:
Nilstrieb 2023-12-30 17:09:02 +01:00
parent d59f06fc64
commit ffafcd8819
32 changed files with 132 additions and 139 deletions

View file

@ -45,9 +45,10 @@ pub struct CodegenFnAttrs {
pub alignment: Option<u32>,
}
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
pub struct CodegenFnAttrFlags(u32);
bitflags! {
#[derive(TyEncodable, TyDecodable, HashStable)]
pub struct CodegenFnAttrFlags: u32 {
impl CodegenFnAttrFlags: u32 {
/// `#[cold]`: a hint to LLVM that this function, when called, is never on
/// the hot path.
const COLD = 1 << 0;
@ -104,6 +105,7 @@ bitflags! {
const NO_BUILTINS = 1 << 20;
}
}
rustc_data_structures::external_bitflags_debug! { CodegenFnAttrFlags }
impl CodegenFnAttrs {
pub const EMPTY: &'static Self = &Self::new();

View file

@ -24,9 +24,10 @@ use std::str;
use super::{Destructor, FieldDef, GenericPredicates, Ty, TyCtxt, VariantDef, VariantDiscr};
#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
pub struct AdtFlags(u16);
bitflags! {
#[derive(HashStable, TyEncodable, TyDecodable)]
pub struct AdtFlags: u16 {
impl AdtFlags: u16 {
const NO_ADT_FLAGS = 0;
/// Indicates whether the ADT is an enum.
const IS_ENUM = 1 << 0;
@ -51,6 +52,7 @@ bitflags! {
const IS_UNSAFE_CELL = 1 << 9;
}
}
rustc_data_structures::external_bitflags_debug! { AdtFlags }
/// The definition of a user-defined type, e.g., a `struct`, `enum`, or `union`.
///

View file

@ -1771,9 +1771,10 @@ pub struct Destructor {
pub constness: hir::Constness,
}
#[derive(Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
pub struct VariantFlags(u8);
bitflags! {
#[derive(HashStable, TyEncodable, TyDecodable)]
pub struct VariantFlags: u8 {
impl VariantFlags: u8 {
const NO_VARIANT_FLAGS = 0;
/// Indicates whether the field list of this variant is `#[non_exhaustive]`.
const IS_FIELD_LIST_NON_EXHAUSTIVE = 1 << 0;
@ -1782,6 +1783,7 @@ bitflags! {
const IS_RECOVERED = 1 << 1;
}
}
rustc_data_structures::external_bitflags_debug! { VariantFlags }
/// Definition of a variant -- a struct's fields or an enum variant.
#[derive(Debug, HashStable, TyEncodable, TyDecodable)]