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
This commit is contained in:
Matthias Krüger 2024-10-16 20:15:56 +02:00 committed by GitHub
commit ac6353ed43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1028,7 +1028,7 @@ pub fn ty(&self, place_ty: Ty) -> Result<Ty, Error> {
ProjectionElem::Field(_idx, fty) => Ok(*fty),
ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => Self::index_ty(ty),
ProjectionElem::Subslice { from, to, from_end } => {
Self::subslice_ty(ty, from, to, from_end)
Self::subslice_ty(ty, *from, *to, *from_end)
}
ProjectionElem::Downcast(_) => Ok(ty),
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Subtype(ty) => Ok(*ty),
@ -1039,13 +1039,13 @@ fn index_ty(ty: Ty) -> Result<Ty, Error> {
ty.kind().builtin_index().ok_or_else(|| error!("Cannot index non-array type: {ty:?}"))
}
fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> {
fn subslice_ty(ty: Ty, from: u64, to: u64, from_end: bool) -> Result<Ty, Error> {
let ty_kind = ty.kind();
match ty_kind {
TyKind::RigidTy(RigidTy::Slice(..)) => Ok(ty),
TyKind::RigidTy(RigidTy::Array(inner, _)) if !from_end => Ty::try_new_array(
inner,
to.checked_sub(*from).ok_or_else(|| error!("Subslice overflow: {from}..{to}"))?,
to.checked_sub(from).ok_or_else(|| error!("Subslice overflow: {from}..{to}"))?,
),
TyKind::RigidTy(RigidTy::Array(inner, size)) => {
let size = size.eval_target_usize()?;