Skip to content

Commit 0924888

Browse files
bors[bot]matklad
andauthored
Merge #8325
8325: Check if bitflags deps pulls its weight r=jonas-schievink a=matklad Bitflags is generally a good dependency -- it's lightweight, well maintained and embraced by the ecosystem. I wonder, however, do we really need it? Doesn't feel like it adds much to be honest. Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents bc8b278 + d1474ae commit 0924888

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ edition = "2018"
1010
doctest = false
1111

1212
[dependencies]
13-
bitflags = "1.2.1"
1413
cov-mark = { version = "1.1", features = ["thread-local"] }
1514
dashmap = { version = "4.0.2", features = ["raw-api"] }
1615
log = "0.4.8"

crates/hir_def/src/data.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl FunctionData {
5050

5151
let mut flags = func.flags;
5252
if is_varargs {
53-
flags |= FnFlags::IS_VARARGS;
53+
flags.bits |= FnFlags::IS_VARARGS;
5454
}
5555

5656
Arc::new(FunctionData {
@@ -71,37 +71,37 @@ impl FunctionData {
7171
}
7272

7373
pub fn has_body(&self) -> bool {
74-
self.flags.contains(FnFlags::HAS_BODY)
74+
self.flags.bits & FnFlags::HAS_BODY != 0
7575
}
7676

7777
/// True if the first param is `self`. This is relevant to decide whether this
7878
/// can be called as a method.
7979
pub fn has_self_param(&self) -> bool {
80-
self.flags.contains(FnFlags::HAS_SELF_PARAM)
80+
self.flags.bits & FnFlags::HAS_SELF_PARAM != 0
8181
}
8282

8383
pub fn is_default(&self) -> bool {
84-
self.flags.contains(FnFlags::IS_DEFAULT)
84+
self.flags.bits & FnFlags::IS_DEFAULT != 0
8585
}
8686

8787
pub fn is_const(&self) -> bool {
88-
self.flags.contains(FnFlags::IS_CONST)
88+
self.flags.bits & FnFlags::IS_CONST != 0
8989
}
9090

9191
pub fn is_async(&self) -> bool {
92-
self.flags.contains(FnFlags::IS_ASYNC)
92+
self.flags.bits & FnFlags::IS_ASYNC != 0
9393
}
9494

9595
pub fn is_unsafe(&self) -> bool {
96-
self.flags.contains(FnFlags::IS_UNSAFE)
96+
self.flags.bits & FnFlags::IS_UNSAFE != 0
9797
}
9898

9999
pub fn is_in_extern_block(&self) -> bool {
100-
self.flags.contains(FnFlags::IS_IN_EXTERN_BLOCK)
100+
self.flags.bits & FnFlags::IS_IN_EXTERN_BLOCK != 0
101101
}
102102

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

crates/hir_def/src/item_tree.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -569,20 +569,21 @@ pub enum Param {
569569
Varargs,
570570
}
571571

572-
bitflags::bitflags! {
573-
/// NOTE: Shared with `FunctionData`
574-
pub(crate) struct FnFlags: u8 {
575-
const HAS_SELF_PARAM = 1 << 0;
576-
const HAS_BODY = 1 << 1;
577-
const IS_DEFAULT = 1 << 2;
578-
const IS_CONST = 1 << 3;
579-
const IS_ASYNC = 1 << 4;
580-
const IS_UNSAFE = 1 << 5;
581-
/// Whether the function is located in an `extern` block (*not* whether it is an
582-
/// `extern "abi" fn`).
583-
const IS_IN_EXTERN_BLOCK = 1 << 6;
584-
const IS_VARARGS = 1 << 7;
585-
}
572+
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
573+
pub(crate) struct FnFlags {
574+
pub(crate) bits: u8,
575+
}
576+
impl FnFlags {
577+
pub(crate) const HAS_SELF_PARAM: u8 = 1 << 0;
578+
pub(crate) const HAS_BODY: u8 = 1 << 1;
579+
pub(crate) const IS_DEFAULT: u8 = 1 << 2;
580+
pub(crate) const IS_CONST: u8 = 1 << 3;
581+
pub(crate) const IS_ASYNC: u8 = 1 << 4;
582+
pub(crate) const IS_UNSAFE: u8 = 1 << 5;
583+
/// Whether the function is located in an `extern` block (*not* whether it is an
584+
/// `extern "abi" fn`).
585+
pub(crate) const IS_IN_EXTERN_BLOCK: u8 = 1 << 6;
586+
pub(crate) const IS_VARARGS: u8 = 1 << 7;
586587
}
587588

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

crates/hir_def/src/item_tree/lower.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,24 +411,24 @@ impl Ctx {
411411

412412
let ast_id = self.source_ast_id_map.ast_id(func);
413413

414-
let mut flags = FnFlags::empty();
414+
let mut flags = FnFlags::default();
415415
if func.body().is_some() {
416-
flags |= FnFlags::HAS_BODY;
416+
flags.bits |= FnFlags::HAS_BODY;
417417
}
418418
if has_self_param {
419-
flags |= FnFlags::HAS_SELF_PARAM;
419+
flags.bits |= FnFlags::HAS_SELF_PARAM;
420420
}
421421
if func.default_token().is_some() {
422-
flags |= FnFlags::IS_DEFAULT;
422+
flags.bits |= FnFlags::IS_DEFAULT;
423423
}
424424
if func.const_token().is_some() {
425-
flags |= FnFlags::IS_CONST;
425+
flags.bits |= FnFlags::IS_CONST;
426426
}
427427
if func.async_token().is_some() {
428-
flags |= FnFlags::IS_ASYNC;
428+
flags.bits |= FnFlags::IS_ASYNC;
429429
}
430430
if func.unsafe_token().is_some() {
431-
flags |= FnFlags::IS_UNSAFE;
431+
flags.bits |= FnFlags::IS_UNSAFE;
432432
}
433433

434434
let mut res = Function {
@@ -653,9 +653,9 @@ impl Ctx {
653653
let func_id = self.lower_function(&ast)?;
654654
let func = &mut self.data().functions[func_id.index];
655655
if is_intrinsic_fn_unsafe(&func.name) {
656-
func.flags |= FnFlags::IS_UNSAFE;
656+
func.flags.bits |= FnFlags::IS_UNSAFE;
657657
}
658-
func.flags |= FnFlags::IS_IN_EXTERN_BLOCK;
658+
func.flags.bits |= FnFlags::IS_IN_EXTERN_BLOCK;
659659
func_id.into()
660660
}
661661
ast::ExternItem::Static(ast) => {

0 commit comments

Comments
 (0)