Skip to content

Commit 2cb6969

Browse files
committed
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.
1 parent d59f06f commit 2cb6969

File tree

29 files changed

+107
-114
lines changed

29 files changed

+107
-114
lines changed

compiler/rustc_abi/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
rand = { version = "0.8.4", default-features = false, optional = true }
1010
rand_xoshiro = { version = "0.6.0", optional = true }
1111
rustc_data_structures = { path = "../rustc_data_structures", optional = true }

compiler/rustc_abi/src/lib.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ pub use layout::LayoutCalculator;
2929
/// instead of implementing everything in `rustc_middle`.
3030
pub trait HashStableContext {}
3131

32+
#[derive(Clone, Copy, PartialEq, Eq, Default)]
33+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))]
34+
pub struct ReprFlags(u8);
35+
3236
bitflags! {
33-
#[derive(Default)]
34-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))]
35-
pub struct ReprFlags: u8 {
37+
impl ReprFlags: u8 {
3638
const IS_C = 1 << 0;
3739
const IS_SIMD = 1 << 1;
3840
const IS_TRANSPARENT = 1 << 2;
@@ -42,11 +44,12 @@ bitflags! {
4244
// the seed stored in `ReprOptions.layout_seed`
4345
const RANDOMIZE_LAYOUT = 1 << 4;
4446
// Any of these flags being set prevent field reordering optimisation.
45-
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits
46-
| ReprFlags::IS_SIMD.bits
47-
| ReprFlags::IS_LINEAR.bits;
47+
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits()
48+
| ReprFlags::IS_SIMD.bits()
49+
| ReprFlags::IS_LINEAR.bits();
4850
}
4951
}
52+
rustc_data_structures::external_bitflags_debug! { ReprFlags }
5053

5154
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5255
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))]

compiler/rustc_ast/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
memchr = "2.5.0"
1010
rustc_data_structures = { path = "../rustc_data_structures" }
1111
rustc_index = { path = "../rustc_index" }

compiler/rustc_ast/src/ast.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2171,9 +2171,10 @@ pub enum InlineAsmRegOrRegClass {
21712171
RegClass(Symbol),
21722172
}
21732173

2174+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
2175+
pub struct InlineAsmOptions(u16);
21742176
bitflags::bitflags! {
2175-
#[derive(Encodable, Decodable, HashStable_Generic)]
2176-
pub struct InlineAsmOptions: u16 {
2177+
impl InlineAsmOptions: u16 {
21772178
const PURE = 1 << 0;
21782179
const NOMEM = 1 << 1;
21792180
const READONLY = 1 << 2;
@@ -2186,6 +2187,12 @@ bitflags::bitflags! {
21862187
}
21872188
}
21882189

2190+
impl std::fmt::Debug for InlineAsmOptions {
2191+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2192+
bitflags::parser::to_writer(self, f)
2193+
}
2194+
}
2195+
21892196
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
21902197
pub enum InlineAsmTemplatePiece {
21912198
String(String),

compiler/rustc_codegen_llvm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test = false
88

99
[dependencies]
1010
# tidy-alphabetical-start
11-
bitflags = "1.0"
11+
bitflags = "2.4.1"
1212
itertools = "0.11"
1313
libc = "0.2"
1414
measureme = "10.0.0"

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ pub mod debuginfo {
722722
// These values **must** match with LLVMRustDIFlags!!
723723
bitflags! {
724724
#[repr(transparent)]
725-
#[derive(Default)]
725+
#[derive(Clone, Copy, Default)]
726726
pub struct DIFlags: u32 {
727727
const FlagZero = 0;
728728
const FlagPrivate = 1;
@@ -751,7 +751,7 @@ pub mod debuginfo {
751751
// These values **must** match with LLVMRustDISPFlags!!
752752
bitflags! {
753753
#[repr(transparent)]
754-
#[derive(Default)]
754+
#[derive(Clone, Copy, Default)]
755755
pub struct DISPFlags: u32 {
756756
const SPFlagZero = 0;
757757
const SPFlagVirtual = 1;

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
ar_archive_writer = "0.1.5"
9-
bitflags = "1.2.1"
9+
bitflags = "2.4.1"
1010
cc = "1.0.69"
1111
itertools = "0.11"
1212
jobserver = "0.1.27"

compiler/rustc_codegen_ssa/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub enum ModuleKind {
110110
}
111111

112112
bitflags::bitflags! {
113+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
113114
pub struct MemFlags: u8 {
114115
const VOLATILE = 1 << 0;
115116
const NONTEMPORAL = 1 << 1;

compiler/rustc_data_structures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
arrayvec = { version = "0.7", default-features = false }
9-
bitflags = "1.2.1"
9+
bitflags = "2.4.1"
1010
elsa = "=1.7.1"
1111
ena = "0.14.2"
1212
indexmap = { version = "2.0.0" }

compiler/rustc_data_structures/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,14 @@ pub fn make_display(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl
150150
// See comments in src/librustc_middle/lib.rs
151151
#[doc(hidden)]
152152
pub fn __noop_fix_for_27438() {}
153+
154+
#[macro_export]
155+
macro_rules! external_bitflags_debug {
156+
($Name:ident) => {
157+
impl ::std::fmt::Debug for $Name {
158+
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
159+
::bitflags::parser::to_writer(self, f)
160+
}
161+
}
162+
};
163+
}

compiler/rustc_data_structures/src/profiling.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ use parking_lot::RwLock;
101101
use smallvec::SmallVec;
102102

103103
bitflags::bitflags! {
104+
#[derive(Clone, Copy)]
104105
struct EventFilter: u16 {
105106
const GENERIC_ACTIVITIES = 1 << 0;
106107
const QUERY_PROVIDERS = 1 << 1;
@@ -114,14 +115,14 @@ bitflags::bitflags! {
114115
const INCR_RESULT_HASHING = 1 << 8;
115116
const ARTIFACT_SIZES = 1 << 9;
116117

117-
const DEFAULT = Self::GENERIC_ACTIVITIES.bits |
118-
Self::QUERY_PROVIDERS.bits |
119-
Self::QUERY_BLOCKED.bits |
120-
Self::INCR_CACHE_LOADS.bits |
121-
Self::INCR_RESULT_HASHING.bits |
122-
Self::ARTIFACT_SIZES.bits;
118+
const DEFAULT = Self::GENERIC_ACTIVITIES.bits() |
119+
Self::QUERY_PROVIDERS.bits() |
120+
Self::QUERY_BLOCKED.bits() |
121+
Self::INCR_CACHE_LOADS.bits() |
122+
Self::INCR_RESULT_HASHING.bits() |
123+
Self::ARTIFACT_SIZES.bits();
123124

124-
const ARGS = Self::QUERY_KEYS.bits | Self::FUNCTION_ARGS.bits;
125+
const ARGS = Self::QUERY_KEYS.bits() | Self::FUNCTION_ARGS.bits();
125126
}
126127
}
127128

compiler/rustc_metadata/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
libloading = "0.7.1"
1010
odht = { version = "0.3.1", features = ["nightly"] }
1111
rustc_ast = { path = "../rustc_ast" }

compiler/rustc_middle/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
derive_more = "0.99.17"
1010
either = "1.5.0"
1111
field-offset = "0.3.5"

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ pub struct CodegenFnAttrs {
4545
pub alignment: Option<u32>,
4646
}
4747

48+
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
49+
pub struct CodegenFnAttrFlags(u32);
4850
bitflags! {
49-
#[derive(TyEncodable, TyDecodable, HashStable)]
50-
pub struct CodegenFnAttrFlags: u32 {
51+
impl CodegenFnAttrFlags: u32 {
5152
/// `#[cold]`: a hint to LLVM that this function, when called, is never on
5253
/// the hot path.
5354
const COLD = 1 << 0;
@@ -104,6 +105,7 @@ bitflags! {
104105
const NO_BUILTINS = 1 << 20;
105106
}
106107
}
108+
rustc_data_structures::external_bitflags_debug! { CodegenFnAttrFlags }
107109

108110
impl CodegenFnAttrs {
109111
pub const EMPTY: &'static Self = &Self::new();

compiler/rustc_middle/src/ty/adt.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ use std::str;
2424

2525
use super::{Destructor, FieldDef, GenericPredicates, Ty, TyCtxt, VariantDef, VariantDiscr};
2626

27+
#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
28+
pub struct AdtFlags(u16);
2729
bitflags! {
28-
#[derive(HashStable, TyEncodable, TyDecodable)]
29-
pub struct AdtFlags: u16 {
30+
impl AdtFlags: u16 {
3031
const NO_ADT_FLAGS = 0;
3132
/// Indicates whether the ADT is an enum.
3233
const IS_ENUM = 1 << 0;
@@ -51,6 +52,7 @@ bitflags! {
5152
const IS_UNSAFE_CELL = 1 << 9;
5253
}
5354
}
55+
rustc_data_structures::external_bitflags_debug! { AdtFlags }
5456

5557
/// The definition of a user-defined type, e.g., a `struct`, `enum`, or `union`.
5658
///

compiler/rustc_middle/src/ty/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1771,9 +1771,10 @@ pub struct Destructor {
17711771
pub constness: hir::Constness,
17721772
}
17731773

1774+
#[derive(Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
1775+
pub struct VariantFlags(u8);
17741776
bitflags! {
1775-
#[derive(HashStable, TyEncodable, TyDecodable)]
1776-
pub struct VariantFlags: u8 {
1777+
impl VariantFlags: u8 {
17771778
const NO_VARIANT_FLAGS = 0;
17781779
/// Indicates whether the field list of this variant is `#[non_exhaustive]`.
17791780
const IS_FIELD_LIST_NON_EXHAUSTIVE = 1 << 0;
@@ -1782,6 +1783,7 @@ bitflags! {
17821783
const IS_RECOVERED = 1 << 1;
17831784
}
17841785
}
1786+
rustc_data_structures::external_bitflags_debug! { VariantFlags }
17851787

17861788
/// Definition of a variant -- a struct's fields or an enum variant.
17871789
#[derive(Debug, HashStable, TyEncodable, TyDecodable)]

compiler/rustc_parse/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.0"
8+
bitflags = "2.4.1"
99
rustc_ast = { path = "../rustc_ast" }
1010
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1111
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_parse/src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use crate::errors::{
4646
};
4747

4848
bitflags::bitflags! {
49+
#[derive(Clone, Copy)]
4950
struct Restrictions: u8 {
5051
const STMT_EXPR = 1 << 0;
5152
const NO_STRUCT_LITERAL = 1 << 1;

compiler/rustc_resolve/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
pulldown-cmark = { version = "0.9.3", default-features = false }
1010
rustc_arena = { path = "../rustc_arena" }
1111
rustc_ast = { path = "../rustc_ast" }

compiler/rustc_resolve/src/ident.rs

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
377377
ignore_binding: Option<NameBinding<'a>>,
378378
) -> Result<NameBinding<'a>, Determinacy> {
379379
bitflags::bitflags! {
380+
#[derive(Clone, Copy)]
380381
struct Flags: u8 {
381382
const MACRO_RULES = 1 << 0;
382383
const MODULE = 1 << 1;

compiler/rustc_session/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
getopts = "0.2"
1010
rustc_ast = { path = "../rustc_ast" }
1111
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_session/src/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ impl OutputFilenames {
10211021

10221022
bitflags::bitflags! {
10231023
/// Scopes used to determined if it need to apply to --remap-path-prefix
1024+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
10241025
pub struct RemapPathScopeComponents: u8 {
10251026
/// Apply remappings to the expansion of std::file!() macro
10261027
const MACRO = 1 << 0;
@@ -1041,7 +1042,7 @@ bitflags::bitflags! {
10411042
/// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This
10421043
/// ensures all paths in compiled executables or libraries are remapped
10431044
/// but not elsewhere.
1044-
const OBJECT = Self::MACRO.bits | Self::UNSPLIT_DEBUGINFO.bits | Self::SPLIT_DEBUGINFO_PATH.bits;
1045+
const OBJECT = Self::MACRO.bits() | Self::UNSPLIT_DEBUGINFO.bits() | Self::SPLIT_DEBUGINFO_PATH.bits();
10451046
}
10461047
}
10471048

compiler/rustc_symbol_mangling/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
punycode = "0.4.0"
1010
rustc-demangle = "0.1.21"
1111
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_symbol_mangling/src/typeid.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use twox_hash::XxHash64;
1111

1212
bitflags! {
1313
/// Options for typeid_for_fnabi and typeid_for_fnsig.
14+
#[derive(Clone, Copy, Debug)]
1415
pub struct TypeIdOptions: u32 {
1516
const GENERALIZE_POINTERS = 1;
1617
const GENERALIZE_REPR_C = 2;

compiler/rustc_target/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
bitflags = "1.2.1"
8+
bitflags = "2.4.1"
99
rustc_abi = { path = "../rustc_abi" }
1010
rustc_data_structures = { path = "../rustc_data_structures" }
1111
rustc_feature = { path = "../rustc_feature" }

compiler/rustc_target/src/abi/call/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ pub use attr_impl::ArgAttribute;
9393
#[allow(unused)]
9494
mod attr_impl {
9595
// The subset of llvm::Attribute needed for arguments, packed into a bitfield.
96+
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, HashStable_Generic)]
97+
pub struct ArgAttribute(u8);
9698
bitflags::bitflags! {
97-
#[derive(Default, HashStable_Generic)]
98-
pub struct ArgAttribute: u8 {
99+
impl ArgAttribute: u8 {
99100
const NoAlias = 1 << 1;
100101
const NoCapture = 1 << 2;
101102
const NonNull = 1 << 3;
@@ -104,6 +105,7 @@ mod attr_impl {
104105
const NoUndef = 1 << 6;
105106
}
106107
}
108+
rustc_data_structures::external_bitflags_debug! { ArgAttribute }
107109
}
108110

109111
/// Sometimes an ABI requires small integers to be extended to a full or partial register. This enum

0 commit comments

Comments
 (0)