Skip to content

Commit 3a8ff7a

Browse files
authored
Rollup merge of #131777 - practicalrs:fix_trivially_copy_pass_by_ref, r=jieyouxu
Fix trivially_copy_pass_by_ref in stable_mir Hi, This PR fixes the following clippy warnings ``` warning: this argument (8 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> compiler/stable_mir/src/mir/body.rs:1042:34 | 1042 | fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> { | ^^^^ help: consider passing by value instead: `u64` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref = note: requested on the command line with `-W clippy::trivially-copy-pass-by-ref` warning: this argument (8 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> compiler/stable_mir/src/mir/body.rs:1042:44 | 1042 | fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> { | ^^^^ help: consider passing by value instead: `u64` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref warning: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> compiler/stable_mir/src/mir/body.rs:1042:60 | 1042 | fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> { | ^^^^^ help: consider passing by value instead: `bool` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref ``` Best regards, Michal
2 parents d6c51cf + 89ea9e4 commit 3a8ff7a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: compiler/stable_mir/src/mir/body.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ impl ProjectionElem {
10281028
ProjectionElem::Field(_idx, fty) => Ok(*fty),
10291029
ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => Self::index_ty(ty),
10301030
ProjectionElem::Subslice { from, to, from_end } => {
1031-
Self::subslice_ty(ty, from, to, from_end)
1031+
Self::subslice_ty(ty, *from, *to, *from_end)
10321032
}
10331033
ProjectionElem::Downcast(_) => Ok(ty),
10341034
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Subtype(ty) => Ok(*ty),
@@ -1039,13 +1039,13 @@ impl ProjectionElem {
10391039
ty.kind().builtin_index().ok_or_else(|| error!("Cannot index non-array type: {ty:?}"))
10401040
}
10411041

1042-
fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> {
1042+
fn subslice_ty(ty: Ty, from: u64, to: u64, from_end: bool) -> Result<Ty, Error> {
10431043
let ty_kind = ty.kind();
10441044
match ty_kind {
10451045
TyKind::RigidTy(RigidTy::Slice(..)) => Ok(ty),
10461046
TyKind::RigidTy(RigidTy::Array(inner, _)) if !from_end => Ty::try_new_array(
10471047
inner,
1048-
to.checked_sub(*from).ok_or_else(|| error!("Subslice overflow: {from}..{to}"))?,
1048+
to.checked_sub(from).ok_or_else(|| error!("Subslice overflow: {from}..{to}"))?,
10491049
),
10501050
TyKind::RigidTy(RigidTy::Array(inner, size)) => {
10511051
let size = size.eval_target_usize()?;

0 commit comments

Comments
 (0)