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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 11 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)