Skip to content

Commit c9d1105

Browse files
bors[bot]Jonas Schievink
and
Jonas Schievink
authored
Merge #11927
11927: internal: Use bitflags for `FnFlags` r=jonas-schievink a=jonas-schievink Previously we didn't do this because it didn't pull its weight, but now we actually do some bitops bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 82fa6ad + c71c304 commit c9d1105

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir_def/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rust-version = "1.57"
1010
doctest = false
1111

1212
[dependencies]
13+
bitflags = "1.3.2"
1314
cov-mark = "2.0.0-pre.1"
1415
dashmap = { version = "5.2.0", features = ["raw-api"] }
1516
lock_api = "0.4.6"

crates/hir_def/src/data.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ impl FunctionData {
5454

5555
let mut flags = func.flags;
5656
if is_varargs {
57-
flags.bits |= FnFlags::IS_VARARGS;
57+
flags |= FnFlags::IS_VARARGS;
5858
}
59-
if flags.bits & FnFlags::HAS_SELF_PARAM != 0 {
59+
if flags.contains(FnFlags::HAS_SELF_PARAM) {
6060
// If there's a self param in the syntax, but it is cfg'd out, remove the flag.
6161
let is_cfgd_out = match func.params.clone().next() {
6262
Some(param) => {
@@ -69,7 +69,7 @@ impl FunctionData {
6969
};
7070
if is_cfgd_out {
7171
cov_mark::hit!(cfgd_out_self_param);
72-
flags.bits &= !FnFlags::HAS_SELF_PARAM;
72+
flags.remove(FnFlags::HAS_SELF_PARAM);
7373
}
7474
}
7575

@@ -101,33 +101,33 @@ impl FunctionData {
101101
}
102102

103103
pub fn has_body(&self) -> bool {
104-
self.flags.bits & FnFlags::HAS_BODY != 0
104+
self.flags.contains(FnFlags::HAS_BODY)
105105
}
106106

107107
/// True if the first param is `self`. This is relevant to decide whether this
108108
/// can be called as a method.
109109
pub fn has_self_param(&self) -> bool {
110-
self.flags.bits & FnFlags::HAS_SELF_PARAM != 0
110+
self.flags.contains(FnFlags::HAS_SELF_PARAM)
111111
}
112112

113113
pub fn is_default(&self) -> bool {
114-
self.flags.bits & FnFlags::IS_DEFAULT != 0
114+
self.flags.contains(FnFlags::IS_DEFAULT)
115115
}
116116

117117
pub fn is_const(&self) -> bool {
118-
self.flags.bits & FnFlags::IS_CONST != 0
118+
self.flags.contains(FnFlags::IS_CONST)
119119
}
120120

121121
pub fn is_async(&self) -> bool {
122-
self.flags.bits & FnFlags::IS_ASYNC != 0
122+
self.flags.contains(FnFlags::IS_ASYNC)
123123
}
124124

125125
pub fn is_unsafe(&self) -> bool {
126-
self.flags.bits & FnFlags::IS_UNSAFE != 0
126+
self.flags.contains(FnFlags::IS_UNSAFE)
127127
}
128128

129129
pub fn is_varargs(&self) -> bool {
130-
self.flags.bits & FnFlags::IS_VARARGS != 0
130+
self.flags.contains(FnFlags::IS_VARARGS)
131131
}
132132
}
133133

crates/hir_def/src/item_tree.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,17 @@ pub enum Param {
601601
Varargs,
602602
}
603603

604-
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
605-
pub(crate) struct FnFlags {
606-
pub(crate) bits: u8,
607-
}
608-
impl FnFlags {
609-
pub(crate) const HAS_SELF_PARAM: u8 = 1 << 0;
610-
pub(crate) const HAS_BODY: u8 = 1 << 1;
611-
pub(crate) const IS_DEFAULT: u8 = 1 << 2;
612-
pub(crate) const IS_CONST: u8 = 1 << 3;
613-
pub(crate) const IS_ASYNC: u8 = 1 << 4;
614-
pub(crate) const IS_UNSAFE: u8 = 1 << 5;
615-
pub(crate) const IS_VARARGS: u8 = 1 << 7;
604+
bitflags::bitflags! {
605+
#[derive(Default)]
606+
pub(crate) struct FnFlags: u8 {
607+
const HAS_SELF_PARAM = 1 << 0;
608+
const HAS_BODY = 1 << 1;
609+
const IS_DEFAULT = 1 << 2;
610+
const IS_CONST = 1 << 3;
611+
const IS_ASYNC = 1 << 4;
612+
const IS_UNSAFE = 1 << 5;
613+
const IS_VARARGS = 1 << 6;
614+
}
616615
}
617616

618617
#[derive(Debug, Clone, Eq, PartialEq)]

crates/hir_def/src/item_tree/lower.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,22 +337,22 @@ impl<'a> Ctx<'a> {
337337

338338
let mut flags = FnFlags::default();
339339
if func.body().is_some() {
340-
flags.bits |= FnFlags::HAS_BODY;
340+
flags |= FnFlags::HAS_BODY;
341341
}
342342
if has_self_param {
343-
flags.bits |= FnFlags::HAS_SELF_PARAM;
343+
flags |= FnFlags::HAS_SELF_PARAM;
344344
}
345345
if func.default_token().is_some() {
346-
flags.bits |= FnFlags::IS_DEFAULT;
346+
flags |= FnFlags::IS_DEFAULT;
347347
}
348348
if func.const_token().is_some() {
349-
flags.bits |= FnFlags::IS_CONST;
349+
flags |= FnFlags::IS_CONST;
350350
}
351351
if func.async_token().is_some() {
352-
flags.bits |= FnFlags::IS_ASYNC;
352+
flags |= FnFlags::IS_ASYNC;
353353
}
354354
if func.unsafe_token().is_some() {
355-
flags.bits |= FnFlags::IS_UNSAFE;
355+
flags |= FnFlags::IS_UNSAFE;
356356
}
357357

358358
let mut res = Function {
@@ -559,7 +559,7 @@ impl<'a> Ctx<'a> {
559559
let func = &mut self.data().functions[func_id.index];
560560
if is_intrinsic_fn_unsafe(&func.name) {
561561
// FIXME: this breaks in macros
562-
func.flags.bits |= FnFlags::IS_UNSAFE;
562+
func.flags |= FnFlags::IS_UNSAFE;
563563
}
564564
func_id.into()
565565
}

0 commit comments

Comments
 (0)