diff --git a/crates/libkoopa/src/raw/generator.rs b/crates/libkoopa/src/raw/generator.rs index ee3012d..b6b1633 100644 --- a/crates/libkoopa/src/raw/generator.rs +++ b/crates/libkoopa/src/raw/generator.rs @@ -96,7 +96,7 @@ struct RawSliceIter<'a, T: Pointer> { phantom: PhantomData, } -impl<'a, T, E> RawSliceIter<'a, T> +impl RawSliceIter<'_, T> where T: Pointer + GenerateOnRaw, { @@ -109,7 +109,7 @@ where } } -impl<'a, T: Pointer> Iterator for RawSliceIter<'a, T> { +impl Iterator for RawSliceIter<'_, T> { type Item = T; fn next(&mut self) -> Option { @@ -196,7 +196,7 @@ impl GenerateOnRaw for *const c_char { } } -impl<'rpb> GenerateOnRaw for RawProgram<'rpb> { +impl GenerateOnRaw for RawProgram<'_> { type Entity = (); fn generate(&self, program: &mut Program, info: &mut ProgramInfo) -> Result { diff --git a/src/back/koopa.rs b/src/back/koopa.rs index ab60987..7e0e7f0 100644 --- a/src/back/koopa.rs +++ b/src/back/koopa.rs @@ -48,7 +48,7 @@ macro_rules! value { }; } -impl<'a, W: Write> VisitorImpl<'a, W> { +impl VisitorImpl<'_, W> { /// Visits the program. fn visit(&mut self) -> Result<()> { for inst in self.program.inst_layout() { diff --git a/src/back/llvm.rs b/src/back/llvm.rs index 21f0ac0..e752b4c 100644 --- a/src/back/llvm.rs +++ b/src/back/llvm.rs @@ -60,7 +60,7 @@ macro_rules! value_ty { }; } -impl<'a, W: Write> VisitorImpl<'a, W> { +impl VisitorImpl<'_, W> { /// Maximum length of LLVM IR identifier. const MAX_ID_LEN: usize = 512; diff --git a/src/front/span.rs b/src/front/span.rs index 20cfbbf..c54eb86 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::missing_const_for_thread_local)] static STATE: RefCell = RefCell::new(GlobalState { file: FileType::Buffer, err_num: 0, diff --git a/src/ir/builder.rs b/src/ir/builder.rs index 5c372b9..fe715c9 100644 --- a/src/ir/builder.rs +++ b/src/ir/builder.rs @@ -494,20 +494,20 @@ pub struct LocalBuilder<'a> { pub(in crate::ir) dfg: &'a mut DataFlowGraph, } -impl<'a> DfgBasedInfoQuerier for LocalBuilder<'a> { +impl DfgBasedInfoQuerier for LocalBuilder<'_> { fn dfg(&self) -> &DataFlowGraph { self.dfg } } -impl<'a> ValueInserter for LocalBuilder<'a> { +impl ValueInserter for LocalBuilder<'_> { fn insert_value(&mut self, data: ValueData) -> Value { self.dfg.new_value_data(data) } } -impl<'a> ValueBuilder for LocalBuilder<'a> {} -impl<'a> LocalInstBuilder for LocalBuilder<'a> {} +impl ValueBuilder for LocalBuilder<'_> {} +impl LocalInstBuilder for LocalBuilder<'_> {} /// An basic block builder that builds a new basic block and inserts it /// to the data flow graph. @@ -517,13 +517,13 @@ pub struct BlockBuilder<'a> { pub(in crate::ir) dfg: &'a mut DataFlowGraph, } -impl<'a> ValueInserter for BlockBuilder<'a> { +impl ValueInserter for BlockBuilder<'_> { fn insert_value(&mut self, data: ValueData) -> Value { self.dfg.new_value_data(data) } } -impl<'a> BasicBlockBuilder for BlockBuilder<'a> { +impl BasicBlockBuilder for BlockBuilder<'_> { fn insert_bb(&mut self, data: BasicBlockData) -> BasicBlock { self.dfg.new_bb_data(data) } @@ -538,21 +538,21 @@ pub struct ReplaceBuilder<'a> { pub(in crate::ir) value: Value, } -impl<'a> DfgBasedInfoQuerier for ReplaceBuilder<'a> { +impl DfgBasedInfoQuerier for ReplaceBuilder<'_> { fn dfg(&self) -> &DataFlowGraph { self.dfg } } -impl<'a> ValueInserter for ReplaceBuilder<'a> { +impl ValueInserter for ReplaceBuilder<'_> { fn insert_value(&mut self, data: ValueData) -> Value { self.dfg.replace_value_with_data(self.value, data); self.value } } -impl<'a> ValueBuilder for ReplaceBuilder<'a> {} -impl<'a> LocalInstBuilder for ReplaceBuilder<'a> {} +impl ValueBuilder for ReplaceBuilder<'_> {} +impl LocalInstBuilder for ReplaceBuilder<'_> {} /// An value builder that builds a new global value and inserts it /// to the program. @@ -562,7 +562,7 @@ pub struct GlobalBuilder<'a> { pub(in crate::ir) program: &'a mut Program, } -impl<'a> EntityInfoQuerier for GlobalBuilder<'a> { +impl EntityInfoQuerier for GlobalBuilder<'_> { fn value_type(&self, value: Value) -> Type { self .program @@ -594,7 +594,7 @@ impl<'a> EntityInfoQuerier for GlobalBuilder<'a> { } } -impl<'a> ValueInserter for GlobalBuilder<'a> { +impl ValueInserter for GlobalBuilder<'_> { fn insert_value(&mut self, data: ValueData) -> Value { let is_inst = data.kind().is_global_alloc(); let value = self.program.new_value_data(data); @@ -605,5 +605,5 @@ impl<'a> ValueInserter for GlobalBuilder<'a> { } } -impl<'a> ValueBuilder for GlobalBuilder<'a> {} -impl<'a> GlobalInstBuilder for GlobalBuilder<'a> {} +impl ValueBuilder for GlobalBuilder<'_> {} +impl GlobalInstBuilder for GlobalBuilder<'_> {} diff --git a/src/ir/entities.rs b/src/ir/entities.rs index c6b62d3..fa5c476 100644 --- a/src/ir/entities.rs +++ b/src/ir/entities.rs @@ -591,7 +591,7 @@ pub struct ValueUses<'a> { index: usize, } -impl<'a> Iterator for ValueUses<'a> { +impl Iterator for ValueUses<'_> { type Item = Value; fn next(&mut self) -> Option { @@ -658,7 +658,7 @@ pub struct BasicBlockUses<'a> { index: usize, } -impl<'a> Iterator for BasicBlockUses<'a> { +impl Iterator for BasicBlockUses<'_> { type Item = BasicBlock; fn next(&mut self) -> Option { diff --git a/src/ir/idman.rs b/src/ir/idman.rs index 1e542a4..a3f415c 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::missing_const_for_thread_local)] static NEXT_GLOBAL_VALUE_ID: Cell = Cell::new(GLOBAL_VALUE_ID_STARTS_FROM); /// The next local value ID. + #[allow(clippy::missing_const_for_thread_local)] static NEXT_LOCAL_VALUE_ID: Cell = Cell::new(LOCAL_VALUE_ID_STARTS_FROM); /// The next basic block ID. + #[allow(clippy::missing_const_for_thread_local)] static NEXT_BB_ID: Cell = Cell::new(BB_ID_STARTS_FROM); /// The next function ID. + #[allow(clippy::missing_const_for_thread_local)] 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..d3cdb17 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::missing_const_for_thread_local)] static PTR_SIZE: Cell = Cell::new(mem::size_of::<*const ()>()); }