Skip to content

Commit

Permalink
(src) made Clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxXSoft committed Nov 30, 2024
1 parent cfb7628 commit edb70e0
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 34 deletions.
6 changes: 3 additions & 3 deletions crates/libkoopa/src/raw/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct RawSliceIter<'a, T: Pointer> {
phantom: PhantomData<T>,
}

impl<'a, T, E> RawSliceIter<'a, T>
impl<T, E> RawSliceIter<'_, T>
where
T: Pointer + GenerateOnRaw<Entity = E>,
{
Expand All @@ -109,7 +109,7 @@ where
}
}

impl<'a, T: Pointer> Iterator for RawSliceIter<'a, T> {
impl<T: Pointer> Iterator for RawSliceIter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -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<Self::Entity> {
Expand Down
2 changes: 1 addition & 1 deletion src/back/koopa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ macro_rules! value {
};
}

impl<'a, W: Write> VisitorImpl<'a, W> {
impl<W: Write> VisitorImpl<'_, W> {
/// Visits the program.
fn visit(&mut self) -> Result<()> {
for inst in self.program.inst_layout() {
Expand Down
2 changes: 1 addition & 1 deletion src/back/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! value_ty {
};
}

impl<'a, W: Write> VisitorImpl<'a, W> {
impl<W: Write> VisitorImpl<'_, W> {
/// Maximum length of LLVM IR identifier.
const MAX_ID_LEN: usize = 512;

Expand Down
1 change: 1 addition & 0 deletions src/front/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl Span {
const TAB_WIDTH: usize = 2;

thread_local! {
#[allow(clippy::missing_const_for_thread_local)]
static STATE: RefCell<GlobalState> = RefCell::new(GlobalState {
file: FileType::Buffer,
err_num: 0,
Expand Down
28 changes: 14 additions & 14 deletions src/ir/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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<'_> {}
4 changes: 2 additions & 2 deletions src/ir/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Item> {
Expand Down Expand Up @@ -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<Self::Item> {
Expand Down
6 changes: 5 additions & 1 deletion src/ir/idman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand All @@ -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<ValueId> = 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<ValueId> = Cell::new(LOCAL_VALUE_ID_STARTS_FROM);
/// The next basic block ID.
#[allow(clippy::missing_const_for_thread_local)]
static NEXT_BB_ID: Cell<BasicBlockId> = Cell::new(BB_ID_STARTS_FROM);
/// The next function ID.
#[allow(clippy::missing_const_for_thread_local)]
static NEXT_FUNC_ID: Cell<FunctionId> = Cell::new(FUNC_ID_STARTS_FROM);
}

Expand Down
24 changes: 12 additions & 12 deletions src/ir/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ impl Map<BasicBlock, BasicBlockNode> for BasicBlockMap {
self.map.clear()
}

fn get<Q: ?Sized>(&self, k: &Q) -> Option<&BasicBlockNode>
fn get<Q>(&self, k: &Q) -> Option<&BasicBlockNode>
where
BasicBlock: Borrow<Q>,
Q: Hash + Eq,
Q: ?Sized + Hash + Eq,
{
self.map.get(k)
}

fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut BasicBlockNode>
fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut BasicBlockNode>
where
BasicBlock: Borrow<Q>,
Q: Hash + Eq,
Q: ?Sized + Hash + Eq,
{
self.map.get_mut(k)
}
Expand All @@ -135,10 +135,10 @@ impl Map<BasicBlock, BasicBlockNode> for BasicBlockMap {
}
}

fn remove_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(BasicBlock, BasicBlockNode)>
fn remove_entry<Q>(&mut self, k: &Q) -> Option<(BasicBlock, BasicBlockNode)>
where
BasicBlock: Borrow<Q>,
Q: Hash + Eq,
Q: ?Sized + Hash + Eq,
{
self.map.remove_entry(k)
}
Expand Down Expand Up @@ -225,18 +225,18 @@ impl Map<Value, InstNode> for InstMap {
self.map.clear()
}

fn get<Q: ?Sized>(&self, k: &Q) -> Option<&InstNode>
fn get<Q>(&self, k: &Q) -> Option<&InstNode>
where
Value: Borrow<Q>,
Q: Hash + Eq,
Q: ?Sized + Hash + Eq,
{
self.map.get(k)
}

fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut InstNode>
fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut InstNode>
where
Value: Borrow<Q>,
Q: Hash + Eq,
Q: ?Sized + Hash + Eq,
{
self.map.get_mut(k)
}
Expand All @@ -260,10 +260,10 @@ impl Map<Value, InstNode> for InstMap {
}
}

fn remove_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(Value, InstNode)>
fn remove_entry<Q>(&mut self, k: &Q) -> Option<(Value, InstNode)>
where
Value: Borrow<Q>,
Q: Hash + Eq,
Q: ?Sized + Hash + Eq,
{
let kv = self.map.remove_entry(k);
if kv.is_some() {
Expand Down
1 change: 1 addition & 0 deletions src/ir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl Type {
static POOL: RefCell<HashMap<TypeKind, Type>> = RefCell::new(HashMap::new());

/// Size of pointers.
#[allow(clippy::missing_const_for_thread_local)]
static PTR_SIZE: Cell<usize> = Cell::new(mem::size_of::<*const ()>());
}

Expand Down

0 comments on commit edb70e0

Please sign in to comment.