Skip to content

Commit 5a345b3

Browse files
committed
Auto merge of #119446 - Nilstrieb:bitflags2.0-hell, r=compiler-errors
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. r? compiler
2 parents a2541e8 + ffafcd8 commit 5a345b3

File tree

32 files changed

+132
-139
lines changed

32 files changed

+132
-139
lines changed

Cargo.lock

+16-16
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
285285

286286
[[package]]
287287
name = "bitflags"
288-
version = "2.4.0"
288+
version = "2.4.1"
289289
source = "registry+https://github.com/rust-lang/crates.io-index"
290-
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
290+
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
291291

292292
[[package]]
293293
name = "block-buffer"
@@ -3370,7 +3370,7 @@ dependencies = [
33703370
name = "rustc_abi"
33713371
version = "0.0.0"
33723372
dependencies = [
3373-
"bitflags 1.3.2",
3373+
"bitflags 2.4.1",
33743374
"rand",
33753375
"rand_xoshiro",
33763376
"rustc_data_structures",
@@ -3401,7 +3401,7 @@ dependencies = [
34013401
name = "rustc_ast"
34023402
version = "0.0.0"
34033403
dependencies = [
3404-
"bitflags 1.3.2",
3404+
"bitflags 2.4.1",
34053405
"memchr",
34063406
"rustc_data_structures",
34073407
"rustc_index",
@@ -3552,7 +3552,7 @@ dependencies = [
35523552
name = "rustc_codegen_llvm"
35533553
version = "0.0.0"
35543554
dependencies = [
3555-
"bitflags 1.3.2",
3555+
"bitflags 2.4.1",
35563556
"itertools",
35573557
"libc",
35583558
"measureme",
@@ -3587,7 +3587,7 @@ name = "rustc_codegen_ssa"
35873587
version = "0.0.0"
35883588
dependencies = [
35893589
"ar_archive_writer",
3590-
"bitflags 1.3.2",
3590+
"bitflags 2.4.1",
35913591
"cc",
35923592
"itertools",
35933593
"jobserver",
@@ -3654,7 +3654,7 @@ name = "rustc_data_structures"
36543654
version = "0.0.0"
36553655
dependencies = [
36563656
"arrayvec",
3657-
"bitflags 1.3.2",
3657+
"bitflags 2.4.1",
36583658
"elsa",
36593659
"ena",
36603660
"indexmap",
@@ -4121,7 +4121,7 @@ dependencies = [
41214121
name = "rustc_metadata"
41224122
version = "0.0.0"
41234123
dependencies = [
4124-
"bitflags 1.3.2",
4124+
"bitflags 2.4.1",
41254125
"libloading 0.7.4",
41264126
"odht",
41274127
"rustc_ast",
@@ -4151,7 +4151,7 @@ dependencies = [
41514151
name = "rustc_middle"
41524152
version = "0.0.0"
41534153
dependencies = [
4154-
"bitflags 1.3.2",
4154+
"bitflags 2.4.1",
41554155
"derive_more",
41564156
"either",
41574157
"field-offset",
@@ -4286,7 +4286,7 @@ dependencies = [
42864286
name = "rustc_parse"
42874287
version = "0.0.0"
42884288
dependencies = [
4289-
"bitflags 1.3.2",
4289+
"bitflags 2.4.1",
42904290
"rustc_ast",
42914291
"rustc_ast_pretty",
42924292
"rustc_data_structures",
@@ -4424,7 +4424,7 @@ dependencies = [
44244424
name = "rustc_resolve"
44254425
version = "0.0.0"
44264426
dependencies = [
4427-
"bitflags 1.3.2",
4427+
"bitflags 2.4.1",
44284428
"pulldown-cmark",
44294429
"rustc_arena",
44304430
"rustc_ast",
@@ -4463,7 +4463,7 @@ dependencies = [
44634463
name = "rustc_session"
44644464
version = "0.0.0"
44654465
dependencies = [
4466-
"bitflags 1.3.2",
4466+
"bitflags 2.4.1",
44674467
"getopts",
44684468
"libc",
44694469
"rustc_ast",
@@ -4521,7 +4521,7 @@ dependencies = [
45214521
name = "rustc_symbol_mangling"
45224522
version = "0.0.0"
45234523
dependencies = [
4524-
"bitflags 1.3.2",
4524+
"bitflags 2.4.1",
45254525
"punycode",
45264526
"rustc-demangle",
45274527
"rustc_data_structures",
@@ -4539,7 +4539,7 @@ dependencies = [
45394539
name = "rustc_target"
45404540
version = "0.0.0"
45414541
dependencies = [
4542-
"bitflags 1.3.2",
4542+
"bitflags 2.4.1",
45434543
"object",
45444544
"rustc_abi",
45454545
"rustc_data_structures",
@@ -4638,7 +4638,7 @@ dependencies = [
46384638
name = "rustc_type_ir"
46394639
version = "0.0.0"
46404640
dependencies = [
4641-
"bitflags 1.3.2",
4641+
"bitflags 2.4.1",
46424642
"derivative",
46434643
"rustc_data_structures",
46444644
"rustc_index",
@@ -4768,7 +4768,7 @@ version = "0.38.19"
47684768
source = "registry+https://github.com/rust-lang/crates.io-index"
47694769
checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed"
47704770
dependencies = [
4771-
"bitflags 2.4.0",
4771+
"bitflags 2.4.1",
47724772
"errno",
47734773
"libc",
47744774
"linux-raw-sys",

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)]

0 commit comments

Comments
 (0)