diff --git a/Cargo.lock b/Cargo.lock index f2120495e43..b8192e333fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -285,9 +285,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block-buffer" @@ -3370,7 +3370,7 @@ dependencies = [ name = "rustc_abi" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "rand", "rand_xoshiro", "rustc_data_structures", @@ -3401,7 +3401,7 @@ dependencies = [ name = "rustc_ast" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "memchr", "rustc_data_structures", "rustc_index", @@ -3552,7 +3552,7 @@ dependencies = [ name = "rustc_codegen_llvm" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "itertools", "libc", "measureme", @@ -3587,7 +3587,7 @@ name = "rustc_codegen_ssa" version = "0.0.0" dependencies = [ "ar_archive_writer", - "bitflags 1.3.2", + "bitflags 2.4.1", "cc", "itertools", "jobserver", @@ -3654,7 +3654,7 @@ name = "rustc_data_structures" version = "0.0.0" dependencies = [ "arrayvec", - "bitflags 1.3.2", + "bitflags 2.4.1", "elsa", "ena", "indexmap", @@ -4121,7 +4121,7 @@ dependencies = [ name = "rustc_metadata" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "libloading 0.7.4", "odht", "rustc_ast", @@ -4151,7 +4151,7 @@ dependencies = [ name = "rustc_middle" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "derive_more", "either", "field-offset", @@ -4286,7 +4286,7 @@ dependencies = [ name = "rustc_parse" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "rustc_ast", "rustc_ast_pretty", "rustc_data_structures", @@ -4424,7 +4424,7 @@ dependencies = [ name = "rustc_resolve" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "pulldown-cmark", "rustc_arena", "rustc_ast", @@ -4463,7 +4463,7 @@ dependencies = [ name = "rustc_session" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "getopts", "libc", "rustc_ast", @@ -4521,7 +4521,7 @@ dependencies = [ name = "rustc_symbol_mangling" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "punycode", "rustc-demangle", "rustc_data_structures", @@ -4539,7 +4539,7 @@ dependencies = [ name = "rustc_target" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "object", "rustc_abi", "rustc_data_structures", @@ -4638,7 +4638,7 @@ dependencies = [ name = "rustc_type_ir" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "derivative", "rustc_data_structures", "rustc_index", @@ -4768,7 +4768,7 @@ version = "0.38.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", diff --git a/compiler/rustc_abi/Cargo.toml b/compiler/rustc_abi/Cargo.toml index e549724b1c0..5031e7a6705 100644 --- a/compiler/rustc_abi/Cargo.toml +++ b/compiler/rustc_abi/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" rand = { version = "0.8.4", default-features = false, optional = true } rand_xoshiro = { version = "0.6.0", optional = true } rustc_data_structures = { path = "../rustc_data_structures", optional = true } diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index eb42803f93e..549927d5898 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -29,10 +29,12 @@ pub use layout::LayoutCalculator; /// instead of implementing everything in `rustc_middle`. pub trait HashStableContext {} +#[derive(Clone, Copy, PartialEq, Eq, Default)] +#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))] +pub struct ReprFlags(u8); + bitflags! { - #[derive(Default)] - #[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))] - pub struct ReprFlags: u8 { + impl ReprFlags: u8 { const IS_C = 1 << 0; const IS_SIMD = 1 << 1; const IS_TRANSPARENT = 1 << 2; @@ -42,11 +44,12 @@ bitflags! { // the seed stored in `ReprOptions.layout_seed` const RANDOMIZE_LAYOUT = 1 << 4; // Any of these flags being set prevent field reordering optimisation. - const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits - | ReprFlags::IS_SIMD.bits - | ReprFlags::IS_LINEAR.bits; + const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits() + | ReprFlags::IS_SIMD.bits() + | ReprFlags::IS_LINEAR.bits(); } } +rustc_data_structures::external_bitflags_debug! { ReprFlags } #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))] diff --git a/compiler/rustc_ast/Cargo.toml b/compiler/rustc_ast/Cargo.toml index 59e3d85589a..937ee4bcd42 100644 --- a/compiler/rustc_ast/Cargo.toml +++ b/compiler/rustc_ast/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" memchr = "2.5.0" rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 9a9c769fd7c..1812cc335a4 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2171,9 +2171,10 @@ pub enum InlineAsmRegOrRegClass { RegClass(Symbol), } +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +pub struct InlineAsmOptions(u16); bitflags::bitflags! { - #[derive(Encodable, Decodable, HashStable_Generic)] - pub struct InlineAsmOptions: u16 { + impl InlineAsmOptions: u16 { const PURE = 1 << 0; const NOMEM = 1 << 1; const READONLY = 1 << 2; @@ -2186,6 +2187,12 @@ bitflags::bitflags! { } } +impl std::fmt::Debug for InlineAsmOptions { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + bitflags::parser::to_writer(self, f) + } +} + #[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic)] pub enum InlineAsmTemplatePiece { String(String), diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 7122c055e7e..c12142e302d 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -8,7 +8,7 @@ test = false [dependencies] # tidy-alphabetical-start -bitflags = "1.0" +bitflags = "2.4.1" itertools = "0.11" libc = "0.2" measureme = "10.0.0" diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 81702baa8c0..aefca6b34f5 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -722,7 +722,7 @@ pub mod debuginfo { // These values **must** match with LLVMRustDIFlags!! bitflags! { #[repr(transparent)] - #[derive(Default)] + #[derive(Clone, Copy, Default)] pub struct DIFlags: u32 { const FlagZero = 0; const FlagPrivate = 1; @@ -751,7 +751,7 @@ pub mod debuginfo { // These values **must** match with LLVMRustDISPFlags!! bitflags! { #[repr(transparent)] - #[derive(Default)] + #[derive(Clone, Copy, Default)] pub struct DISPFlags: u32 { const SPFlagZero = 0; const SPFlagVirtual = 1; diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index 3f2ed257d08..7d2f5bb193a 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start ar_archive_writer = "0.1.5" -bitflags = "1.2.1" +bitflags = "2.4.1" cc = "1.0.69" itertools = "0.11" jobserver = "0.1.27" diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 9b60f0844a0..0d88df63280 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -110,6 +110,7 @@ pub enum ModuleKind { } bitflags::bitflags! { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct MemFlags: u8 { const VOLATILE = 1 << 0; const NONTEMPORAL = 1 << 1; diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index 4732783a12d..23949deaade 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start arrayvec = { version = "0.7", default-features = false } -bitflags = "1.2.1" +bitflags = "2.4.1" elsa = "=1.7.1" ena = "0.14.2" indexmap = { version = "2.0.0" } diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 3ef87684fa5..93b4032c310 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -150,3 +150,14 @@ pub fn make_display(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl // See comments in src/librustc_middle/lib.rs #[doc(hidden)] pub fn __noop_fix_for_27438() {} + +#[macro_export] +macro_rules! external_bitflags_debug { + ($Name:ident) => { + impl ::std::fmt::Debug for $Name { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::bitflags::parser::to_writer(self, f) + } + } + }; +} diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index ef7375a7320..e29d4811980 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -101,6 +101,7 @@ use parking_lot::RwLock; use smallvec::SmallVec; bitflags::bitflags! { + #[derive(Clone, Copy)] struct EventFilter: u16 { const GENERIC_ACTIVITIES = 1 << 0; const QUERY_PROVIDERS = 1 << 1; @@ -114,14 +115,14 @@ bitflags::bitflags! { const INCR_RESULT_HASHING = 1 << 8; const ARTIFACT_SIZES = 1 << 9; - const DEFAULT = Self::GENERIC_ACTIVITIES.bits | - Self::QUERY_PROVIDERS.bits | - Self::QUERY_BLOCKED.bits | - Self::INCR_CACHE_LOADS.bits | - Self::INCR_RESULT_HASHING.bits | - Self::ARTIFACT_SIZES.bits; + const DEFAULT = Self::GENERIC_ACTIVITIES.bits() | + Self::QUERY_PROVIDERS.bits() | + Self::QUERY_BLOCKED.bits() | + Self::INCR_CACHE_LOADS.bits() | + Self::INCR_RESULT_HASHING.bits() | + Self::ARTIFACT_SIZES.bits(); - const ARGS = Self::QUERY_KEYS.bits | Self::FUNCTION_ARGS.bits; + const ARGS = Self::QUERY_KEYS.bits() | Self::FUNCTION_ARGS.bits(); } } diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml index a4012592c09..08cc8173eb0 100644 --- a/compiler/rustc_metadata/Cargo.toml +++ b/compiler/rustc_metadata/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" libloading = "0.7.1" odht = { version = "0.3.1", features = ["nightly"] } rustc_ast = { path = "../rustc_ast" } diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index d356984c1e9..8e6ca645f80 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" derive_more = "0.99.17" either = "1.5.0" field-offset = "0.3.5" diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index f758c1d5e6f..e11c9371118 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -45,9 +45,10 @@ pub struct CodegenFnAttrs { pub alignment: Option, } +#[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(); diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index b95ae5881e2..685c3e87dac 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -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`. /// diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 0653796ec7f..5911f23552e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -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)] diff --git a/compiler/rustc_parse/Cargo.toml b/compiler/rustc_parse/Cargo.toml index 02f9f35f0f5..f5623323168 100644 --- a/compiler/rustc_parse/Cargo.toml +++ b/compiler/rustc_parse/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.0" +bitflags = "2.4.1" rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 19226f37abe..3932d32a6e1 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -46,6 +46,7 @@ use crate::errors::{ }; bitflags::bitflags! { + #[derive(Clone, Copy)] struct Restrictions: u8 { const STMT_EXPR = 1 << 0; const NO_STRUCT_LITERAL = 1 << 1; diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index ff9d6d8739f..a1a353ce057 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" pulldown-cmark = { version = "0.9.3", default-features = false } rustc_arena = { path = "../rustc_arena" } rustc_ast = { path = "../rustc_ast" } diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index e559ca8e7cc..3a31addb109 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -377,6 +377,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ignore_binding: Option>, ) -> Result, Determinacy> { bitflags::bitflags! { + #[derive(Clone, Copy)] struct Flags: u8 { const MACRO_RULES = 1 << 0; const MODULE = 1 << 1; diff --git a/compiler/rustc_session/Cargo.toml b/compiler/rustc_session/Cargo.toml index 1f51dd6c975..ba8f67982f5 100644 --- a/compiler/rustc_session/Cargo.toml +++ b/compiler/rustc_session/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" getopts = "0.2" rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index e1640d7fca9..89508c77639 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1021,6 +1021,7 @@ impl OutputFilenames { bitflags::bitflags! { /// Scopes used to determined if it need to apply to --remap-path-prefix + #[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct RemapPathScopeComponents: u8 { /// Apply remappings to the expansion of std::file!() macro const MACRO = 1 << 0; @@ -1041,7 +1042,7 @@ bitflags::bitflags! { /// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This /// ensures all paths in compiled executables or libraries are remapped /// but not elsewhere. - const OBJECT = Self::MACRO.bits | Self::UNSPLIT_DEBUGINFO.bits | Self::SPLIT_DEBUGINFO_PATH.bits; + const OBJECT = Self::MACRO.bits() | Self::UNSPLIT_DEBUGINFO.bits() | Self::SPLIT_DEBUGINFO_PATH.bits(); } } diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml index ff3f1ad646f..0ce522c9cab 100644 --- a/compiler/rustc_symbol_mangling/Cargo.toml +++ b/compiler/rustc_symbol_mangling/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" punycode = "0.4.0" rustc-demangle = "0.1.21" rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_symbol_mangling/src/typeid.rs b/compiler/rustc_symbol_mangling/src/typeid.rs index cda16e3a3f5..838d9d774b2 100644 --- a/compiler/rustc_symbol_mangling/src/typeid.rs +++ b/compiler/rustc_symbol_mangling/src/typeid.rs @@ -11,6 +11,7 @@ use twox_hash::XxHash64; bitflags! { /// Options for typeid_for_fnabi and typeid_for_fnsig. + #[derive(Clone, Copy, Debug)] pub struct TypeIdOptions: u32 { const GENERALIZE_POINTERS = 1; const GENERALIZE_REPR_C = 2; diff --git a/compiler/rustc_target/Cargo.toml b/compiler/rustc_target/Cargo.toml index 94dfeb12dc9..2cb8ac7e8bf 100644 --- a/compiler/rustc_target/Cargo.toml +++ b/compiler/rustc_target/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" rustc_abi = { path = "../rustc_abi" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_feature = { path = "../rustc_feature" } diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index e9730947389..fafc10e7163 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -93,9 +93,10 @@ pub use attr_impl::ArgAttribute; #[allow(unused)] mod attr_impl { // The subset of llvm::Attribute needed for arguments, packed into a bitfield. + #[derive(Clone, Copy, Default, Hash, PartialEq, Eq, HashStable_Generic)] + pub struct ArgAttribute(u8); bitflags::bitflags! { - #[derive(Default, HashStable_Generic)] - pub struct ArgAttribute: u8 { + impl ArgAttribute: u8 { const NoAlias = 1 << 1; const NoCapture = 1 << 2; const NonNull = 1 << 3; @@ -104,6 +105,7 @@ mod attr_impl { const NoUndef = 1 << 6; } } + rustc_data_structures::external_bitflags_debug! { ArgAttribute } } /// Sometimes an ABI requires small integers to be extended to a full or partial register. This enum diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4789a9be151..9d25388b90f 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -39,7 +39,6 @@ use crate::abi::{Endian, Integer, Size, TargetDataLayout, TargetDataLayoutErrors use crate::json::{Json, ToJson}; use crate::spec::abi::{lookup as lookup_abi, Abi}; use crate::spec::crt_objects::CrtObjects; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_fs_util::try_canonicalize; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::symbol::{kw, sym, Symbol}; @@ -592,7 +591,7 @@ impl LinkSelfContainedDefault { } bitflags::bitflags! { - #[derive(Default)] + #[derive(Clone, Copy, PartialEq, Eq, Default)] /// The `-C link-self-contained` components that can individually be enabled or disabled. pub struct LinkSelfContainedComponents: u8 { /// CRT objects (e.g. on `windows-gnu`, `musl`, `wasi` targets) @@ -609,6 +608,7 @@ bitflags::bitflags! { const MINGW = 1 << 5; } } +rustc_data_structures::external_bitflags_debug! { LinkSelfContainedComponents } impl LinkSelfContainedComponents { /// Parses a single `-Clink-self-contained` well-known component, not a set of flags. @@ -667,19 +667,6 @@ impl LinkSelfContainedComponents { } } -impl IntoIterator for LinkSelfContainedComponents { - type Item = LinkSelfContainedComponents; - type IntoIter = std::vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - LinkSelfContainedComponents::all_components() - .into_iter() - .filter(|&s| self.contains(s)) - .collect::>() - .into_iter() - } -} - impl ToJson for LinkSelfContainedComponents { fn to_json(&self) -> Json { let components: Vec<_> = Self::all_components() @@ -1219,9 +1206,10 @@ impl ToJson for StackProbeType { } } +#[derive(Default, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +pub struct SanitizerSet(u16); bitflags::bitflags! { - #[derive(Default, Encodable, Decodable)] - pub struct SanitizerSet: u16 { + impl SanitizerSet: u16 { const ADDRESS = 1 << 0; const LEAK = 1 << 1; const MEMORY = 1 << 2; @@ -1235,6 +1223,7 @@ bitflags::bitflags! { const SAFESTACK = 1 << 10; } } +rustc_data_structures::external_bitflags_debug! { SanitizerSet } impl SanitizerSet { /// Return sanitizer's name @@ -1274,38 +1263,6 @@ impl fmt::Display for SanitizerSet { } } -impl IntoIterator for SanitizerSet { - type Item = SanitizerSet; - type IntoIter = std::vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - [ - SanitizerSet::ADDRESS, - SanitizerSet::CFI, - SanitizerSet::KCFI, - SanitizerSet::LEAK, - SanitizerSet::MEMORY, - SanitizerSet::MEMTAG, - SanitizerSet::SHADOWCALLSTACK, - SanitizerSet::THREAD, - SanitizerSet::HWADDRESS, - SanitizerSet::KERNELADDRESS, - SanitizerSet::SAFESTACK, - ] - .iter() - .copied() - .filter(|&s| self.contains(s)) - .collect::>() - .into_iter() - } -} - -impl HashStable for SanitizerSet { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.bits().hash_stable(ctx, hasher); - } -} - impl ToJson for SanitizerSet { fn to_json(&self) -> Json { self.into_iter() diff --git a/compiler/rustc_type_ir/Cargo.toml b/compiler/rustc_type_ir/Cargo.toml index 3a08d89cc44..38f0eb82180 100644 --- a/compiler/rustc_type_ir/Cargo.toml +++ b/compiler/rustc_type_ir/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -bitflags = "1.2.1" +bitflags = "2.4.1" derivative = "2.2.0" rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_index = { path = "../rustc_index", default-features = false } diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index af741a0a3a0..bc57d6daf47 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -3,6 +3,7 @@ bitflags! { /// through the type during type construction, so that we can quickly check /// whether the type has various kinds of types in it without recursing /// over the type itself. + #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub struct TypeFlags: u32 { // Does this have parameters? Used to determine whether substitution is // required. @@ -13,9 +14,9 @@ bitflags! { /// Does this have `ConstKind::Param`? const HAS_CT_PARAM = 1 << 2; - const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_RE_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits; + const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits() + | TypeFlags::HAS_RE_PARAM.bits() + | TypeFlags::HAS_CT_PARAM.bits(); /// Does this have `Infer`? const HAS_TY_INFER = 1 << 3; @@ -26,9 +27,9 @@ bitflags! { /// Does this have inference variables? Used to determine whether /// inference is required. - const HAS_INFER = TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_RE_INFER.bits - | TypeFlags::HAS_CT_INFER.bits; + const HAS_INFER = TypeFlags::HAS_TY_INFER.bits() + | TypeFlags::HAS_RE_INFER.bits() + | TypeFlags::HAS_CT_INFER.bits(); /// Does this have `Placeholder`? const HAS_TY_PLACEHOLDER = 1 << 6; @@ -38,9 +39,9 @@ bitflags! { const HAS_CT_PLACEHOLDER = 1 << 8; /// Does this have placeholders? - const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits - | TypeFlags::HAS_RE_PLACEHOLDER.bits - | TypeFlags::HAS_CT_PLACEHOLDER.bits; + const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits() + | TypeFlags::HAS_RE_PLACEHOLDER.bits() + | TypeFlags::HAS_CT_PLACEHOLDER.bits(); /// `true` if there are "names" of regions and so forth /// that are local to a particular fn/inferctxt @@ -48,12 +49,12 @@ bitflags! { /// `true` if there are "names" of types and regions and so forth /// that are local to a particular fn - const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits - | TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_CT_INFER.bits - | TypeFlags::HAS_TY_PLACEHOLDER.bits - | TypeFlags::HAS_CT_PLACEHOLDER.bits + const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits() + | TypeFlags::HAS_CT_PARAM.bits() + | TypeFlags::HAS_TY_INFER.bits() + | TypeFlags::HAS_CT_INFER.bits() + | TypeFlags::HAS_TY_PLACEHOLDER.bits() + | TypeFlags::HAS_CT_PLACEHOLDER.bits() // We consider 'freshened' types and constants // to depend on a particular fn. // The freshening process throws away information, @@ -61,10 +62,10 @@ bitflags! { // cache. Note that there is no 'fresh lifetime' flag - // freshening replaces all lifetimes with `ReErased`, // which is different from how types/const are freshened. - | TypeFlags::HAS_TY_FRESH.bits - | TypeFlags::HAS_CT_FRESH.bits - | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits - | TypeFlags::HAS_RE_ERASED.bits; + | TypeFlags::HAS_TY_FRESH.bits() + | TypeFlags::HAS_CT_FRESH.bits() + | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits() + | TypeFlags::HAS_RE_ERASED.bits(); /// Does this have `Projection`? const HAS_TY_PROJECTION = 1 << 10; @@ -76,10 +77,10 @@ bitflags! { const HAS_CT_PROJECTION = 1 << 13; /// Could this type be normalized further? - const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits - | TypeFlags::HAS_TY_OPAQUE.bits - | TypeFlags::HAS_TY_INHERENT.bits - | TypeFlags::HAS_CT_PROJECTION.bits; + const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits() + | TypeFlags::HAS_TY_OPAQUE.bits() + | TypeFlags::HAS_TY_INHERENT.bits() + | TypeFlags::HAS_CT_PROJECTION.bits(); /// Is an error type/const reachable? const HAS_ERROR = 1 << 14; @@ -96,9 +97,9 @@ bitflags! { const HAS_CT_BOUND = 1 << 18; /// Does this have any bound variables? /// Used to check if a global bound is safe to evaluate. - const HAS_BOUND_VARS = TypeFlags::HAS_RE_BOUND.bits - | TypeFlags::HAS_TY_BOUND.bits - | TypeFlags::HAS_CT_BOUND.bits; + const HAS_BOUND_VARS = TypeFlags::HAS_RE_BOUND.bits() + | TypeFlags::HAS_TY_BOUND.bits() + | TypeFlags::HAS_CT_BOUND.bits(); /// Does this have any `ReErased` regions? const HAS_RE_ERASED = 1 << 19; diff --git a/tests/mir-opt/inline/inline_instruction_set.default.Inline.diff b/tests/mir-opt/inline/inline_instruction_set.default.Inline.diff index 6f8b730b4a0..e38daba27fc 100644 --- a/tests/mir-opt/inline/inline_instruction_set.default.Inline.diff +++ b/tests/mir-opt/inline/inline_instruction_set.default.Inline.diff @@ -35,7 +35,7 @@ StorageDead(_3); StorageLive(_4); - _4 = inline_always_and_using_inline_asm() -> [return: bb4, unwind unreachable]; -+ asm!("/* do nothing */", options((empty))) -> [return: bb3, unwind unreachable]; ++ asm!("/* do nothing */", options()) -> [return: bb3, unwind unreachable]; } - bb4: { diff --git a/tests/ui/thir-print/thir-tree-match.stdout b/tests/ui/thir-print/thir-tree-match.stdout index e752e4a8702..a17592fd252 100644 --- a/tests/ui/thir-print/thir-tree-match.stdout +++ b/tests/ui/thir-print/thir-tree-match.stdout @@ -93,9 +93,9 @@ body: adt_def: AdtDef { did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo) - variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])) }], flags: NO_VARIANT_FLAGS }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], flags: NO_VARIANT_FLAGS }] + variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])) }], flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], flags: }] flags: IS_ENUM - repr: ReprOptions { int: None, align: None, pack: None, flags: (empty), field_shuffle_seed: 3477539199540094892 } + repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 3477539199540094892 } args: [] variant_index: 0 subpatterns: [ @@ -107,9 +107,9 @@ body: adt_def: AdtDef { did: DefId(0:3 ~ thir_tree_match[fcf8]::Bar) - variants: [VariantDef { def_id: DefId(0:4 ~ thir_tree_match[fcf8]::Bar::First), ctor: Some((Const, DefId(0:5 ~ thir_tree_match[fcf8]::Bar::First::{constructor#0}))), name: "First", discr: Relative(0), fields: [], flags: NO_VARIANT_FLAGS }, VariantDef { def_id: DefId(0:6 ~ thir_tree_match[fcf8]::Bar::Second), ctor: Some((Const, DefId(0:7 ~ thir_tree_match[fcf8]::Bar::Second::{constructor#0}))), name: "Second", discr: Relative(1), fields: [], flags: NO_VARIANT_FLAGS }, VariantDef { def_id: DefId(0:8 ~ thir_tree_match[fcf8]::Bar::Third), ctor: Some((Const, DefId(0:9 ~ thir_tree_match[fcf8]::Bar::Third::{constructor#0}))), name: "Third", discr: Relative(2), fields: [], flags: NO_VARIANT_FLAGS }] + variants: [VariantDef { def_id: DefId(0:4 ~ thir_tree_match[fcf8]::Bar::First), ctor: Some((Const, DefId(0:5 ~ thir_tree_match[fcf8]::Bar::First::{constructor#0}))), name: "First", discr: Relative(0), fields: [], flags: }, VariantDef { def_id: DefId(0:6 ~ thir_tree_match[fcf8]::Bar::Second), ctor: Some((Const, DefId(0:7 ~ thir_tree_match[fcf8]::Bar::Second::{constructor#0}))), name: "Second", discr: Relative(1), fields: [], flags: }, VariantDef { def_id: DefId(0:8 ~ thir_tree_match[fcf8]::Bar::Third), ctor: Some((Const, DefId(0:9 ~ thir_tree_match[fcf8]::Bar::Third::{constructor#0}))), name: "Third", discr: Relative(2), fields: [], flags: }] flags: IS_ENUM - repr: ReprOptions { int: None, align: None, pack: None, flags: (empty), field_shuffle_seed: 10333377570083945360 } + repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 10333377570083945360 } args: [] variant_index: 0 subpatterns: [] @@ -155,9 +155,9 @@ body: adt_def: AdtDef { did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo) - variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])) }], flags: NO_VARIANT_FLAGS }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], flags: NO_VARIANT_FLAGS }] + variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])) }], flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], flags: }] flags: IS_ENUM - repr: ReprOptions { int: None, align: None, pack: None, flags: (empty), field_shuffle_seed: 3477539199540094892 } + repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 3477539199540094892 } args: [] variant_index: 0 subpatterns: [ @@ -207,9 +207,9 @@ body: adt_def: AdtDef { did: DefId(0:10 ~ thir_tree_match[fcf8]::Foo) - variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])) }], flags: NO_VARIANT_FLAGS }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], flags: NO_VARIANT_FLAGS }] + variants: [VariantDef { def_id: DefId(0:11 ~ thir_tree_match[fcf8]::Foo::FooOne), ctor: Some((Fn, DefId(0:12 ~ thir_tree_match[fcf8]::Foo::FooOne::{constructor#0}))), name: "FooOne", discr: Relative(0), fields: [FieldDef { did: DefId(0:13 ~ thir_tree_match[fcf8]::Foo::FooOne::0), name: "0", vis: Restricted(DefId(0:0 ~ thir_tree_match[fcf8])) }], flags: }, VariantDef { def_id: DefId(0:14 ~ thir_tree_match[fcf8]::Foo::FooTwo), ctor: Some((Const, DefId(0:15 ~ thir_tree_match[fcf8]::Foo::FooTwo::{constructor#0}))), name: "FooTwo", discr: Relative(1), fields: [], flags: }] flags: IS_ENUM - repr: ReprOptions { int: None, align: None, pack: None, flags: (empty), field_shuffle_seed: 3477539199540094892 } + repr: ReprOptions { int: None, align: None, pack: None, flags: , field_shuffle_seed: 3477539199540094892 } args: [] variant_index: 1 subpatterns: []