From 2b01c86e062542d342d0a074c2fb98adaf517c2e Mon Sep 17 00:00:00 2001 From: MaxXSoft Date: Sat, 30 Nov 2024 11:05:53 +0800 Subject: [PATCH] (src) made Clippy happy --- src/front/span.rs | 1 + src/ir/idman.rs | 6 +++++- src/ir/layout.rs | 24 ++++++++++++------------ src/ir/types.rs | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/front/span.rs b/src/front/span.rs index 20cfbbf..fe86da1 100644 --- a/src/front/span.rs +++ b/src/front/span.rs @@ -111,6 +111,7 @@ impl Span { const TAB_WIDTH: usize = 2; thread_local! { + #[allow(clippy::thread_local_initializer_can_be_made_const)] static STATE: RefCell = RefCell::new(GlobalState { file: FileType::Buffer, err_num: 0, diff --git a/src/ir/idman.rs b/src/ir/idman.rs index 1e542a4..ef7539c 100644 --- a/src/ir/idman.rs +++ b/src/ir/idman.rs @@ -15,7 +15,7 @@ pub(in crate::ir) type ValueId = NonZeroU32; /// memory layout optimization. const GLOBAL_VALUE_ID_STARTS_FROM: ValueId = unsafe { NonZeroU32::new_unchecked(1) }; -/// The value of `ValueId` (local value) should start from 1, +/// The value of `ValueId` (local value) should start from 0x40000000, /// because we want to use `NonZeroU32` to enable some /// memory layout optimization. const LOCAL_VALUE_ID_STARTS_FROM: ValueId = unsafe { NonZeroU32::new_unchecked(0x40000000) }; @@ -42,12 +42,16 @@ const FUNC_ID_STARTS_FROM: FunctionId = unsafe { NonZeroU32::new_unchecked(1) }; thread_local! { /// The next global value ID. + #[allow(clippy::thread_local_initializer_can_be_made_const)] static NEXT_GLOBAL_VALUE_ID: Cell = Cell::new(GLOBAL_VALUE_ID_STARTS_FROM); /// The next local value ID. + #[allow(clippy::thread_local_initializer_can_be_made_const)] static NEXT_LOCAL_VALUE_ID: Cell = Cell::new(LOCAL_VALUE_ID_STARTS_FROM); /// The next basic block ID. + #[allow(clippy::thread_local_initializer_can_be_made_const)] static NEXT_BB_ID: Cell = Cell::new(BB_ID_STARTS_FROM); /// The next function ID. + #[allow(clippy::thread_local_initializer_can_be_made_const)] static NEXT_FUNC_ID: Cell = Cell::new(FUNC_ID_STARTS_FROM); } diff --git a/src/ir/layout.rs b/src/ir/layout.rs index e5a876d..94e770a 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -106,18 +106,18 @@ impl Map for BasicBlockMap { self.map.clear() } - fn get(&self, k: &Q) -> Option<&BasicBlockNode> + fn get(&self, k: &Q) -> Option<&BasicBlockNode> where BasicBlock: Borrow, - Q: Hash + Eq, + Q: ?Sized + Hash + Eq, { self.map.get(k) } - fn get_mut(&mut self, k: &Q) -> Option<&mut BasicBlockNode> + fn get_mut(&mut self, k: &Q) -> Option<&mut BasicBlockNode> where BasicBlock: Borrow, - Q: Hash + Eq, + Q: ?Sized + Hash + Eq, { self.map.get_mut(k) } @@ -135,10 +135,10 @@ impl Map for BasicBlockMap { } } - fn remove_entry(&mut self, k: &Q) -> Option<(BasicBlock, BasicBlockNode)> + fn remove_entry(&mut self, k: &Q) -> Option<(BasicBlock, BasicBlockNode)> where BasicBlock: Borrow, - Q: Hash + Eq, + Q: ?Sized + Hash + Eq, { self.map.remove_entry(k) } @@ -225,18 +225,18 @@ impl Map for InstMap { self.map.clear() } - fn get(&self, k: &Q) -> Option<&InstNode> + fn get(&self, k: &Q) -> Option<&InstNode> where Value: Borrow, - Q: Hash + Eq, + Q: ?Sized + Hash + Eq, { self.map.get(k) } - fn get_mut(&mut self, k: &Q) -> Option<&mut InstNode> + fn get_mut(&mut self, k: &Q) -> Option<&mut InstNode> where Value: Borrow, - Q: Hash + Eq, + Q: ?Sized + Hash + Eq, { self.map.get_mut(k) } @@ -260,10 +260,10 @@ impl Map for InstMap { } } - fn remove_entry(&mut self, k: &Q) -> Option<(Value, InstNode)> + fn remove_entry(&mut self, k: &Q) -> Option<(Value, InstNode)> where Value: Borrow, - Q: Hash + Eq, + Q: ?Sized + Hash + Eq, { let kv = self.map.remove_entry(k); if kv.is_some() { diff --git a/src/ir/types.rs b/src/ir/types.rs index fbbf079..d303605 100644 --- a/src/ir/types.rs +++ b/src/ir/types.rs @@ -61,6 +61,7 @@ impl Type { static POOL: RefCell> = RefCell::new(HashMap::new()); /// Size of pointers. + #[allow(clippy::thread_local_initializer_can_be_made_const)] static PTR_SIZE: Cell = Cell::new(mem::size_of::<*const ()>()); }