aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/data.rs18
-rw-r--r--crates/hir_def/src/item_tree.rs29
-rw-r--r--crates/hir_def/src/item_tree/lower.rs18
3 files changed, 33 insertions, 32 deletions
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs
index b409fb45c..135a6698e 100644
--- a/crates/hir_def/src/data.rs
+++ b/crates/hir_def/src/data.rs
@@ -50,7 +50,7 @@ impl FunctionData {
50 50
51 let mut flags = func.flags; 51 let mut flags = func.flags;
52 if is_varargs { 52 if is_varargs {
53 flags |= FnFlags::IS_VARARGS; 53 flags.bits |= FnFlags::IS_VARARGS;
54 } 54 }
55 55
56 Arc::new(FunctionData { 56 Arc::new(FunctionData {
@@ -71,37 +71,37 @@ impl FunctionData {
71 } 71 }
72 72
73 pub fn has_body(&self) -> bool { 73 pub fn has_body(&self) -> bool {
74 self.flags.contains(FnFlags::HAS_BODY) 74 self.flags.bits & FnFlags::HAS_BODY != 0
75 } 75 }
76 76
77 /// True if the first param is `self`. This is relevant to decide whether this 77 /// True if the first param is `self`. This is relevant to decide whether this
78 /// can be called as a method. 78 /// can be called as a method.
79 pub fn has_self_param(&self) -> bool { 79 pub fn has_self_param(&self) -> bool {
80 self.flags.contains(FnFlags::HAS_SELF_PARAM) 80 self.flags.bits & FnFlags::HAS_SELF_PARAM != 0
81 } 81 }
82 82
83 pub fn is_default(&self) -> bool { 83 pub fn is_default(&self) -> bool {
84 self.flags.contains(FnFlags::IS_DEFAULT) 84 self.flags.bits & FnFlags::IS_DEFAULT != 0
85 } 85 }
86 86
87 pub fn is_const(&self) -> bool { 87 pub fn is_const(&self) -> bool {
88 self.flags.contains(FnFlags::IS_CONST) 88 self.flags.bits & FnFlags::IS_CONST != 0
89 } 89 }
90 90
91 pub fn is_async(&self) -> bool { 91 pub fn is_async(&self) -> bool {
92 self.flags.contains(FnFlags::IS_ASYNC) 92 self.flags.bits & FnFlags::IS_ASYNC != 0
93 } 93 }
94 94
95 pub fn is_unsafe(&self) -> bool { 95 pub fn is_unsafe(&self) -> bool {
96 self.flags.contains(FnFlags::IS_UNSAFE) 96 self.flags.bits & FnFlags::IS_UNSAFE != 0
97 } 97 }
98 98
99 pub fn is_in_extern_block(&self) -> bool { 99 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
101 } 101 }
102 102
103 pub fn is_varargs(&self) -> bool { 103 pub fn is_varargs(&self) -> bool {
104 self.flags.contains(FnFlags::IS_VARARGS) 104 self.flags.bits & FnFlags::IS_VARARGS != 0
105 } 105 }
106} 106}
107 107
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index c6d700977..739906778 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -569,20 +569,21 @@ pub enum Param {
569 Varargs, 569 Varargs,
570} 570}
571 571
572bitflags::bitflags! { 572#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
573 /// NOTE: Shared with `FunctionData` 573pub(crate) struct FnFlags {
574 pub(crate) struct FnFlags: u8 { 574 pub(crate) bits: u8,
575 const HAS_SELF_PARAM = 1 << 0; 575}
576 const HAS_BODY = 1 << 1; 576impl FnFlags {
577 const IS_DEFAULT = 1 << 2; 577 pub(crate) const HAS_SELF_PARAM: u8 = 1 << 0;
578 const IS_CONST = 1 << 3; 578 pub(crate) const HAS_BODY: u8 = 1 << 1;
579 const IS_ASYNC = 1 << 4; 579 pub(crate) const IS_DEFAULT: u8 = 1 << 2;
580 const IS_UNSAFE = 1 << 5; 580 pub(crate) const IS_CONST: u8 = 1 << 3;
581 /// Whether the function is located in an `extern` block (*not* whether it is an 581 pub(crate) const IS_ASYNC: u8 = 1 << 4;
582 /// `extern "abi" fn`). 582 pub(crate) const IS_UNSAFE: u8 = 1 << 5;
583 const IS_IN_EXTERN_BLOCK = 1 << 6; 583 /// Whether the function is located in an `extern` block (*not* whether it is an
584 const IS_VARARGS = 1 << 7; 584 /// `extern "abi" fn`).
585 } 585 pub(crate) const IS_IN_EXTERN_BLOCK: u8 = 1 << 6;
586 pub(crate) const IS_VARARGS: u8 = 1 << 7;
586} 587}
587 588
588#[derive(Debug, Clone, Eq, PartialEq)] 589#[derive(Debug, Clone, Eq, PartialEq)]
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 39e8403b0..ab7ad8310 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -411,24 +411,24 @@ impl Ctx {
411 411
412 let ast_id = self.source_ast_id_map.ast_id(func); 412 let ast_id = self.source_ast_id_map.ast_id(func);
413 413
414 let mut flags = FnFlags::empty(); 414 let mut flags = FnFlags::default();
415 if func.body().is_some() { 415 if func.body().is_some() {
416 flags |= FnFlags::HAS_BODY; 416 flags.bits |= FnFlags::HAS_BODY;
417 } 417 }
418 if has_self_param { 418 if has_self_param {
419 flags |= FnFlags::HAS_SELF_PARAM; 419 flags.bits |= FnFlags::HAS_SELF_PARAM;
420 } 420 }
421 if func.default_token().is_some() { 421 if func.default_token().is_some() {
422 flags |= FnFlags::IS_DEFAULT; 422 flags.bits |= FnFlags::IS_DEFAULT;
423 } 423 }
424 if func.const_token().is_some() { 424 if func.const_token().is_some() {
425 flags |= FnFlags::IS_CONST; 425 flags.bits |= FnFlags::IS_CONST;
426 } 426 }
427 if func.async_token().is_some() { 427 if func.async_token().is_some() {
428 flags |= FnFlags::IS_ASYNC; 428 flags.bits |= FnFlags::IS_ASYNC;
429 } 429 }
430 if func.unsafe_token().is_some() { 430 if func.unsafe_token().is_some() {
431 flags |= FnFlags::IS_UNSAFE; 431 flags.bits |= FnFlags::IS_UNSAFE;
432 } 432 }
433 433
434 let mut res = Function { 434 let mut res = Function {
@@ -653,9 +653,9 @@ impl Ctx {
653 let func_id = self.lower_function(&ast)?; 653 let func_id = self.lower_function(&ast)?;
654 let func = &mut self.data().functions[func_id.index]; 654 let func = &mut self.data().functions[func_id.index];
655 if is_intrinsic_fn_unsafe(&func.name) { 655 if is_intrinsic_fn_unsafe(&func.name) {
656 func.flags |= FnFlags::IS_UNSAFE; 656 func.flags.bits |= FnFlags::IS_UNSAFE;
657 } 657 }
658 func.flags |= FnFlags::IS_IN_EXTERN_BLOCK; 658 func.flags.bits |= FnFlags::IS_IN_EXTERN_BLOCK;
659 func_id.into() 659 func_id.into()
660 } 660 }
661 ast::ExternItem::Static(ast) => { 661 ast::ExternItem::Static(ast) => {