Skip to content

Commit

Permalink
Fix trivially_copy_pass_by_ref in stable_mir
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalrs committed Oct 16, 2024
1 parent 9618da7 commit 89ea9e4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ impl ProjectionElem {
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),
Expand All @@ -1039,13 +1039,13 @@ impl ProjectionElem {
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()?;
Expand Down

0 comments on commit 89ea9e4

Please sign in to comment.