From f56a7cb7a6b7e282c35af6c8e32e6bb822371523 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine <vincent.lafeychine@proton.me> Date: Sun, 14 Apr 2024 19:17:07 +0200 Subject: [PATCH] clippy: Fix needless_borrowed_reference --- rr_frontend/.cargo/config.toml | 1 - .../src/environment/polonius_info.rs | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/rr_frontend/.cargo/config.toml b/rr_frontend/.cargo/config.toml index e8f46753..abbc7ce6 100644 --- a/rr_frontend/.cargo/config.toml +++ b/rr_frontend/.cargo/config.toml @@ -21,7 +21,6 @@ rustflags = [ "-Aunused_variables", # clippy::complexity - "-Aclippy::needless_borrowed_reference", "-Aclippy::needless_lifetimes", "-Aclippy::only_used_in_recursion", "-Aclippy::unnecessary_unwrap", diff --git a/rr_frontend/translation/src/environment/polonius_info.rs b/rr_frontend/translation/src/environment/polonius_info.rs index 8611bf26..c88caf5e 100644 --- a/rr_frontend/translation/src/environment/polonius_info.rs +++ b/rr_frontend/translation/src/environment/polonius_info.rs @@ -374,40 +374,43 @@ fn get_borrowed_places<'a, 'tcx: 'a>( } else { let statement = &statements[location.statement_index]; match statement.kind { - mir::StatementKind::Assign(box (ref _lhs, ref rhs)) => match rhs { - &mir::Rvalue::Ref(_, _, ref place) - | &mir::Rvalue::Discriminant(ref place) - | &mir::Rvalue::Use(mir::Operand::Copy(ref place)) - | &mir::Rvalue::Use(mir::Operand::Move(ref place)) => Ok(vec![place]), - &mir::Rvalue::Use(mir::Operand::Constant(_)) => Ok(Vec::new()), - &mir::Rvalue::Aggregate(_, ref operands) => Ok(operands + mir::StatementKind::Assign(box (ref _lhs, ref rhs)) => match *rhs { + mir::Rvalue::Use(mir::Operand::Copy(ref place) | mir::Operand::Move(ref place)) + | mir::Rvalue::Ref(_, _, ref place) + | mir::Rvalue::Discriminant(ref place) => Ok(vec![place]), + + mir::Rvalue::Use(mir::Operand::Constant(_)) => Ok(Vec::new()), + + mir::Rvalue::Aggregate(_, ref operands) => Ok(operands .iter() - .flat_map(|operand| match operand { + .flat_map(|operand| match *operand { mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => Some(place), mir::Operand::Constant(_) => None, }) .collect()), + // slice creation involves an unsize pointer cast like [i32; 3] -> &[i32] - &mir::Rvalue::Cast( + mir::Rvalue::Cast( mir::CastKind::PointerCoercion(ty::adjustment::PointerCoercion::Unsize), ref operand, ref ty, ) if ty.is_slice() && !ty.is_unsafe_ptr() => { trace!("slice: operand={:?}, ty={:?}", operand, ty); - Ok(match operand { + Ok(match *operand { mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => vec![place], mir::Operand::Constant(_) => vec![], }) }, - &mir::Rvalue::Cast(..) => { + mir::Rvalue::Cast(..) => { // all other loan-casts are unsupported Err(PoloniusInfoError::LoanInUnsupportedStatement( "cast statements that create loans are not supported".to_string(), *location, )) }, - x => unreachable!("{:?}", x), + + ref x => unreachable!("{:?}", x), }, ref x => unreachable!("{:?}", x), } -- GitLab