Skip to content

Commit 1fdb13b

Browse files
committed
Make Clippy happy
1 parent 6302a5f commit 1fdb13b

File tree

5 files changed

+39
-43
lines changed

5 files changed

+39
-43
lines changed

crate/tests/diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,5 @@ fn diff() {
101101

102102
#[must_use]
103103
pub fn enabled(key: &str) -> bool {
104-
std::env::var(key).map_or(false, |value| value != "0")
104+
std::env::var(key).is_ok_and(|value| value != "0")
105105
}

lints/arbitrary_cpi/src/lib.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,12 @@ fn find_place_aliases<'tcx>(
262262
for stmt in body.basic_blocks[cur_block].statements.iter().rev() {
263263
match &stmt.kind {
264264
// if the statement assigns to `inst_arg`, update `inst_arg` to the rhs
265-
StatementKind::Assign(box (assign_place, rvalue))
266-
if assign_place.local_or_deref_local() == id_arg.local_or_deref_local() =>
267-
{
268-
if let Rvalue::Use(Operand::Copy(pl) | Operand::Move(pl))
269-
| Rvalue::Ref(_, _, pl) = rvalue
270-
{
271-
id_arg = pl;
272-
likely_program_id_aliases.push(*pl);
273-
}
265+
StatementKind::Assign(box (
266+
assign_place,
267+
Rvalue::Use(Operand::Copy(pl) | Operand::Move(pl)) | Rvalue::Ref(_, _, pl),
268+
)) if assign_place.local_or_deref_local() == id_arg.local_or_deref_local() => {
269+
id_arg = pl;
270+
likely_program_id_aliases.push(*pl);
274271
}
275272
_ => {}
276273
}
@@ -356,21 +353,18 @@ fn is_moved_from<'tcx>(
356353
loop {
357354
for stmt in body.basic_blocks[cur_block].statements.iter().rev() {
358355
match &stmt.kind {
359-
StatementKind::Assign(box (assign_place, rvalue))
360-
if assign_place.local_or_deref_local()
361-
== search_place.local_or_deref_local() =>
356+
StatementKind::Assign(box (
357+
assign_place,
358+
Rvalue::Use(Operand::Copy(rvalue_place) | Operand::Move(rvalue_place))
359+
| Rvalue::Ref(_, _, rvalue_place),
360+
)) if assign_place.local_or_deref_local()
361+
== search_place.local_or_deref_local() =>
362362
{
363-
match rvalue {
364-
Rvalue::Use(Operand::Copy(rvalue_place) | Operand::Move(rvalue_place))
365-
| Rvalue::Ref(_, _, rvalue_place) => {
366-
search_place = rvalue_place;
367-
if let Some(search_loc) = search_place.local_or_deref_local() {
368-
if search_list.contains(&search_loc) {
369-
return true;
370-
}
371-
}
363+
search_place = rvalue_place;
364+
if let Some(search_loc) = search_place.local_or_deref_local() {
365+
if search_list.contains(&search_loc) {
366+
return true;
372367
}
373-
_ => {}
374368
}
375369
}
376370
_ => {}

lints/bump_seed_canonicalization/src/lib.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,14 @@ impl BumpSeedCanonicalization {
276276
// the location of &[bump]. update it to store the location of bump.
277277
if let Operand::Move(pl) = &elements[FieldIdx::from_u32(0)] {
278278
// store the location of bump
279-
seeds_arg = &pl;
279+
// smoelius: Clippy recommends to remove the next borrow.
280+
// However, removing the borrow causes the lint's warning
281+
// message to change and the tests to fail. I don't
282+
// understand why.
283+
#[allow(clippy::needless_borrow)]
284+
{
285+
seeds_arg = &pl;
286+
}
280287
likely_bump_seed_aliases.push(*seeds_arg);
281288
// seeds_arg is a location of bump
282289
state = BackwardDataflowState::Bump;
@@ -321,24 +328,19 @@ impl BumpSeedCanonicalization {
321328
loop {
322329
for stmt in body.basic_blocks[cur_block].statements.iter().rev() {
323330
match &stmt.kind {
324-
StatementKind::Assign(box (assign_place, rvalue))
325-
if assign_place.local_or_deref_local()
326-
== search_place.local_or_deref_local() =>
331+
StatementKind::Assign(box (
332+
assign_place,
333+
Rvalue::Use(Operand::Copy(rvalue_place) | Operand::Move(rvalue_place))
334+
| Rvalue::Ref(_, _, rvalue_place),
335+
)) if assign_place.local_or_deref_local()
336+
== search_place.local_or_deref_local() =>
327337
{
328-
match rvalue {
329-
Rvalue::Use(
330-
Operand::Copy(rvalue_place) | Operand::Move(rvalue_place),
331-
)
332-
| Rvalue::Ref(_, _, rvalue_place) => {
333-
// println!("Found assignment {:?}", stmt);
334-
search_place = rvalue_place;
335-
if let Some(search_loc) = search_place.local_or_deref_local() {
336-
if search_list.contains(&search_loc) {
337-
return true;
338-
}
339-
}
338+
// println!("Found assignment {:?}", stmt);
339+
search_place = rvalue_place;
340+
if let Some(search_loc) = search_place.local_or_deref_local() {
341+
if search_list.contains(&search_loc) {
342+
return true;
340343
}
341-
_ => {}
342344
}
343345
}
344346
_ => {}

lints/missing_owner_check/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn get_referenced_accounts<'tcx>(
235235
accounts.uses
236236
}
237237

238-
impl<'cx, 'tcx> Visitor<'tcx> for AccountUses<'cx, 'tcx> {
238+
impl<'tcx> Visitor<'tcx> for AccountUses<'_, 'tcx> {
239239
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
240240
if_chain! {
241241
// s3v3ru5: the following check removes duplicate warnings where lint would report both `x` and `x.clone()` expressions.
@@ -366,7 +366,7 @@ fn is_safe_constraint_for_owner(constraints: &ConstraintGroup) -> bool {
366366
|| constraints
367367
.init
368368
.as_ref()
369-
.map_or(false, |init_constraint| init_constraint.if_needed)
369+
.is_some_and(|init_constraint| init_constraint.if_needed)
370370
|| constraints.seeds.is_some()
371371
|| constraints.address.is_some()
372372
|| constraints.owner.is_some()

lints/sysvar_get/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn find_from_account_info_exprs<'tcx>(
134134
f.uses
135135
}
136136

137-
impl<'cx, 'tcx> Visitor<'tcx> for FromAccountInfoUses<'cx, 'tcx> {
137+
impl<'tcx> Visitor<'tcx> for FromAccountInfoUses<'_, 'tcx> {
138138
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
139139
if_chain! {
140140
if let ExprKind::Call(func, _) = expr.kind;

0 commit comments

Comments
 (0)