Skip to content

fix: Fix invalid signature bitflags #19562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/hir-def/src/expr_store/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub(crate) fn print_struct(
wln!(p, "#[repr(pack({}))]", pack.bytes());
}
}
if flags.contains(StructFlags::IS_FUNDAMENTAL) {
if flags.contains(StructFlags::FUNDAMENTAL) {
wln!(p, "#[fundamental]");
}
w!(p, "struct ");
Expand Down Expand Up @@ -202,16 +202,16 @@ pub(crate) fn print_function(
line_format: LineFormat::Newline,
edition,
};
if flags.contains(FnFlags::HAS_CONST_KW) {
if flags.contains(FnFlags::CONST) {
w!(p, "const ");
}
if flags.contains(FnFlags::HAS_ASYNC_KW) {
if flags.contains(FnFlags::ASYNC) {
w!(p, "async ");
}
if flags.contains(FnFlags::HAS_UNSAFE_KW) {
if flags.contains(FnFlags::UNSAFE) {
w!(p, "unsafe ");
}
if flags.contains(FnFlags::HAS_SAFE_KW) {
if flags.contains(FnFlags::EXPLICIT_SAFE) {
w!(p, "safe ");
}
if let Some(abi) = abi {
Expand Down
136 changes: 68 additions & 68 deletions crates/hir-def/src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ pub struct StructSignature {
bitflags! {
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct StructFlags: u8 {
/// Indicates whether the struct is `PhantomData`.
const IS_PHANTOM_DATA = 1 << 2;
/// Indicates whether the struct has a `#[fundamental]` attribute.
const IS_FUNDAMENTAL = 1 << 3;
/// Indicates whether the struct has a `#[rustc_has_incoherent_inherent_impls]` attribute.
const IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 4;
const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 1;
/// Indicates whether the struct has a `#[fundamental]` attribute.
const FUNDAMENTAL = 1 << 2;
/// Indicates whether the struct is `PhantomData`.
const IS_PHANTOM_DATA = 1 << 3;
/// Indicates whether this struct is `Box`.
const IS_BOX = 1 << 5;
const IS_BOX = 1 << 4;
/// Indicates whether this struct is `ManuallyDrop`.
const IS_MANUALLY_DROP = 1 << 6;
const IS_MANUALLY_DROP = 1 << 5;
/// Indicates whether this struct is `UnsafeCell`.
const IS_UNSAFE_CELL = 1 << 7;
const IS_UNSAFE_CELL = 1 << 6;
}
}

Expand All @@ -73,10 +73,10 @@ impl StructSignature {

let mut flags = StructFlags::empty();
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
flags |= StructFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
}
if attrs.by_key(&sym::fundamental).exists() {
flags |= StructFlags::IS_FUNDAMENTAL;
flags |= StructFlags::FUNDAMENTAL;
}
if let Some(lang) = attrs.lang_item() {
match lang {
Expand Down Expand Up @@ -129,10 +129,10 @@ impl UnionSignature {
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
let mut flags = StructFlags::empty();
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
flags |= StructFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
}
if attrs.by_key(&sym::fundamental).exists() {
flags |= StructFlags::IS_FUNDAMENTAL;
flags |= StructFlags::FUNDAMENTAL;
}

let repr = attrs.repr();
Expand Down Expand Up @@ -162,7 +162,7 @@ impl UnionSignature {
bitflags! {
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct EnumFlags: u8 {
const IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 4;
const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 1;
}
}

Expand All @@ -182,7 +182,7 @@ impl EnumSignature {
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
let mut flags = EnumFlags::empty();
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
flags |= EnumFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
flags |= EnumFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
}

let repr = attrs.repr();
Expand Down Expand Up @@ -219,8 +219,8 @@ impl EnumSignature {
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct ConstFlags: u8 {
const HAS_BODY = 1 << 0;
const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 1;
const HAS_BODY = 1 << 1;
const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 7;
}
}

Expand Down Expand Up @@ -271,12 +271,12 @@ impl ConstSignature {
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct StaticFlags: u8 {
const HAS_BODY = 1 << 0;
const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 1;
const MUTABLE = 1 << 2;
const HAS_UNSAFE = 1 << 3;
const HAS_SAFE = 1 << 4;
const IS_EXTERN = 1 << 5;
const HAS_BODY = 1 << 1;
const MUTABLE = 1 << 3;
const UNSAFE = 1 << 4;
const EXPLICIT_SAFE = 1 << 5;
const EXTERN = 1 << 6;
const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 7;
}
}

Expand All @@ -302,7 +302,7 @@ impl StaticSignature {
}

if matches!(loc.container, ItemContainerId::ExternBlockId(_)) {
flags.insert(StaticFlags::IS_EXTERN);
flags.insert(StaticFlags::EXTERN);
}

let source = loc.source(db);
Expand All @@ -313,10 +313,10 @@ impl StaticSignature {
flags.insert(StaticFlags::MUTABLE);
}
if source.value.unsafe_token().is_some() {
flags.insert(StaticFlags::HAS_UNSAFE);
flags.insert(StaticFlags::UNSAFE);
}
if source.value.safe_token().is_some() {
flags.insert(StaticFlags::HAS_SAFE);
flags.insert(StaticFlags::EXPLICIT_SAFE);
}

let (store, source_map, type_ref) =
Expand All @@ -337,8 +337,8 @@ impl StaticSignature {
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct ImplFlags: u8 {
const IS_NEGATIVE = 1 << 0;
const IS_UNSAFE = 1 << 1;
const NEGATIVE = 1 << 1;
const UNSAFE = 1 << 3;
}
}

Expand All @@ -358,10 +358,10 @@ impl ImplSignature {
let mut flags = ImplFlags::empty();
let src = loc.source(db);
if src.value.unsafe_token().is_some() {
flags.insert(ImplFlags::IS_UNSAFE);
flags.insert(ImplFlags::UNSAFE);
}
if src.value.excl_token().is_some() {
flags.insert(ImplFlags::IS_NEGATIVE);
flags.insert(ImplFlags::NEGATIVE);
}

let (store, source_map, self_ty, target_trait, generic_params) =
Expand All @@ -383,13 +383,13 @@ impl ImplSignature {
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct TraitFlags: u8 {
const IS_AUTO = 1 << 0;
const IS_UNSAFE = 1 << 1;
const IS_FUNDAMENTAL = 1 << 2;
const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 3;
const SKIP_ARRAY_DURING_METHOD_DISPATCH = 1 << 4;
const SKIP_BOXED_SLICE_DURING_METHOD_DISPATCH = 1 << 5;
const RUSTC_PAREN_SUGAR = 1 << 6;
const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 1;
const FUNDAMENTAL = 1 << 2;
const UNSAFE = 1 << 3;
const AUTO = 1 << 4;
const SKIP_ARRAY_DURING_METHOD_DISPATCH = 1 << 5;
const SKIP_BOXED_SLICE_DURING_METHOD_DISPATCH = 1 << 6;
const RUSTC_PAREN_SUGAR = 1 << 7;
}
}

Expand All @@ -410,13 +410,13 @@ impl TraitSignature {
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
let source = loc.source(db);
if source.value.auto_token().is_some() {
flags.insert(TraitFlags::IS_AUTO);
flags.insert(TraitFlags::AUTO);
}
if source.value.unsafe_token().is_some() {
flags.insert(TraitFlags::IS_UNSAFE);
flags.insert(TraitFlags::UNSAFE);
}
if attrs.by_key(&sym::fundamental).exists() {
flags |= TraitFlags::IS_FUNDAMENTAL;
flags |= TraitFlags::FUNDAMENTAL;
}
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
flags |= TraitFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
Expand Down Expand Up @@ -489,21 +489,21 @@ impl TraitAliasSignature {
bitflags! {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct FnFlags: u16 {
const HAS_SELF_PARAM = 1 << 0;
const HAS_BODY = 1 << 1;
const HAS_DEFAULT_KW = 1 << 2;
const HAS_CONST_KW = 1 << 3;
const HAS_ASYNC_KW = 1 << 4;
const HAS_UNSAFE_KW = 1 << 5;
const IS_VARARGS = 1 << 6;
const HAS_SAFE_KW = 1 << 7;
const DEFAULT = 1 << 2;
const CONST = 1 << 3;
const ASYNC = 1 << 4;
const UNSAFE = 1 << 5;
const HAS_VARARGS = 1 << 6;
const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 7;
const HAS_SELF_PARAM = 1 << 8;
/// The `#[target_feature]` attribute is necessary to check safety (with RFC 2396),
/// but keeping it for all functions will consume a lot of memory when there are
/// only very few functions with it. So we only encode its existence here, and lookup
/// it if needed.
const HAS_TARGET_FEATURE = 1 << 8;
const DEPRECATED_SAFE_2024 = 1 << 9;
const RUSTC_ALLOW_INCOHERENT_IMPLS = 1 << 10;
const HAS_TARGET_FEATURE = 1 << 9;
const DEPRECATED_SAFE_2024 = 1 << 10;
const EXPLICIT_SAFE = 1 << 11;
}
}

Expand Down Expand Up @@ -532,7 +532,7 @@ impl FunctionSignature {
let mut flags = FnFlags::empty();
let attrs = item_tree.attrs(db, module.krate, ModItem::from(loc.id.value).into());
if attrs.by_key(&sym::rustc_allow_incoherent_impl).exists() {
flags.insert(FnFlags::RUSTC_ALLOW_INCOHERENT_IMPLS);
flags.insert(FnFlags::RUSTC_ALLOW_INCOHERENT_IMPL);
}

if attrs.by_key(&sym::target_feature).exists() {
Expand All @@ -546,20 +546,20 @@ impl FunctionSignature {
if attrs.by_key(&sym::rustc_deprecated_safe_2024).exists() {
flags.insert(FnFlags::DEPRECATED_SAFE_2024);
} else {
flags.insert(FnFlags::HAS_UNSAFE_KW);
flags.insert(FnFlags::UNSAFE);
}
}
if source.value.async_token().is_some() {
flags.insert(FnFlags::HAS_ASYNC_KW);
flags.insert(FnFlags::ASYNC);
}
if source.value.const_token().is_some() {
flags.insert(FnFlags::HAS_CONST_KW);
flags.insert(FnFlags::CONST);
}
if source.value.default_token().is_some() {
flags.insert(FnFlags::HAS_DEFAULT_KW);
flags.insert(FnFlags::DEFAULT);
}
if source.value.safe_token().is_some() {
flags.insert(FnFlags::HAS_SAFE_KW);
flags.insert(FnFlags::EXPLICIT_SAFE);
}
if source.value.body().is_some() {
flags.insert(FnFlags::HAS_BODY);
Expand All @@ -575,7 +575,7 @@ impl FunctionSignature {
flags.insert(FnFlags::HAS_SELF_PARAM);
}
if variadic {
flags.insert(FnFlags::IS_VARARGS);
flags.insert(FnFlags::HAS_VARARGS);
}
(
Arc::new(FunctionSignature {
Expand Down Expand Up @@ -603,31 +603,31 @@ impl FunctionSignature {
}

pub fn is_default(&self) -> bool {
self.flags.contains(FnFlags::HAS_DEFAULT_KW)
self.flags.contains(FnFlags::DEFAULT)
}

pub fn is_const(&self) -> bool {
self.flags.contains(FnFlags::HAS_CONST_KW)
self.flags.contains(FnFlags::CONST)
}

pub fn is_async(&self) -> bool {
self.flags.contains(FnFlags::HAS_ASYNC_KW)
self.flags.contains(FnFlags::ASYNC)
}

pub fn is_unsafe(&self) -> bool {
self.flags.contains(FnFlags::HAS_UNSAFE_KW)
self.flags.contains(FnFlags::UNSAFE)
}

pub fn is_deprecated_safe_2024(&self) -> bool {
self.flags.contains(FnFlags::DEPRECATED_SAFE_2024)
}

pub fn is_safe(&self) -> bool {
self.flags.contains(FnFlags::HAS_SAFE_KW)
self.flags.contains(FnFlags::EXPLICIT_SAFE)
}

pub fn is_varargs(&self) -> bool {
self.flags.contains(FnFlags::IS_VARARGS)
self.flags.contains(FnFlags::HAS_VARARGS)
}

pub fn has_target_feature(&self) -> bool {
Expand All @@ -637,10 +637,10 @@ impl FunctionSignature {

bitflags! {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct TypeAliasFlags: u16 {
const IS_EXTERN = 1 << 7;
const RUSTC_ALLOW_INCOHERENT_IMPLS = 1 << 8;
const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 9;
pub struct TypeAliasFlags: u8 {
const RUSTC_HAS_INCOHERENT_INHERENT_IMPL = 1 << 1;
const IS_EXTERN = 1 << 6;
const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 7;
}
}

Expand Down Expand Up @@ -669,10 +669,10 @@ impl TypeAliasSignature {
ModItem::from(loc.id.value).into(),
);
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
flags.insert(TypeAliasFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS);
flags.insert(TypeAliasFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPL);
}
if attrs.by_key(&sym::rustc_allow_incoherent_impl).exists() {
flags.insert(TypeAliasFlags::RUSTC_ALLOW_INCOHERENT_IMPLS);
flags.insert(TypeAliasFlags::RUSTC_ALLOW_INCOHERENT_IMPL);
}
if matches!(loc.container, ItemContainerId::ExternBlockId(_)) {
flags.insert(TypeAliasFlags::IS_EXTERN);
Expand Down
11 changes: 4 additions & 7 deletions crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,13 @@ pub(crate) fn trait_datum_query(
let generic_params = generics(db, trait_.into());
let bound_vars = generic_params.bound_vars_subst(db, DebruijnIndex::INNERMOST);
let flags = rust_ir::TraitFlags {
auto: trait_data.flags.contains(TraitFlags::IS_AUTO),
auto: trait_data.flags.contains(TraitFlags::AUTO),
upstream: trait_.lookup(db).container.krate() != krate,
non_enumerable: true,
coinductive: false, // only relevant for Chalk testing
// FIXME: set these flags correctly
marker: false,
fundamental: trait_data.flags.contains(TraitFlags::IS_FUNDAMENTAL),
fundamental: trait_data.flags.contains(TraitFlags::FUNDAMENTAL),
};
let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars);
let associated_ty_ids =
Expand Down Expand Up @@ -761,10 +761,7 @@ pub(crate) fn adt_datum_query(
let (fundamental, phantom_data) = match adt_id {
hir_def::AdtId::StructId(s) => {
let flags = db.struct_signature(s).flags;
(
flags.contains(StructFlags::IS_FUNDAMENTAL),
flags.contains(StructFlags::IS_PHANTOM_DATA),
)
(flags.contains(StructFlags::FUNDAMENTAL), flags.contains(StructFlags::IS_PHANTOM_DATA))
}
// FIXME set fundamental flags correctly
hir_def::AdtId::UnionId(_) => (false, false),
Expand Down Expand Up @@ -851,7 +848,7 @@ fn impl_def_datum(db: &dyn HirDatabase, krate: Crate, impl_id: hir_def::ImplId)
rust_ir::ImplType::External
};
let where_clauses = convert_where_clauses(db, impl_id.into(), &bound_vars);
let negative = impl_data.flags.contains(ImplFlags::IS_NEGATIVE);
let negative = impl_data.flags.contains(ImplFlags::NEGATIVE);
let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive };

let impl_datum_bound = rust_ir::ImplDatumBound { trait_ref, where_clauses };
Expand Down
Loading