Fix trivially_copy_pass_by_ref in stable_mir

This commit is contained in:
Michal Piotrowski 2024-10-16 12:36:44 +02:00
parent 9618da7c99
commit 89ea9e44f0
No known key found for this signature in database
GPG Key ID: 2538DC6C8E7C7859

View File

@ -1028,7 +1028,7 @@ pub fn ty(&self, place_ty: Ty) -> Result<Ty, Error> {
ProjectionElem::Field(_idx, fty) => Ok(*fty), ProjectionElem::Field(_idx, fty) => Ok(*fty),
ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => Self::index_ty(ty), ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => Self::index_ty(ty),
ProjectionElem::Subslice { from, to, from_end } => { 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::Downcast(_) => Ok(ty),
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Subtype(ty) => 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:?}")) 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(); let ty_kind = ty.kind();
match ty_kind { match ty_kind {
TyKind::RigidTy(RigidTy::Slice(..)) => Ok(ty), TyKind::RigidTy(RigidTy::Slice(..)) => Ok(ty),
TyKind::RigidTy(RigidTy::Array(inner, _)) if !from_end => Ty::try_new_array( TyKind::RigidTy(RigidTy::Array(inner, _)) if !from_end => Ty::try_new_array(
inner, 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)) => { TyKind::RigidTy(RigidTy::Array(inner, size)) => {
let size = size.eval_target_usize()?; let size = size.eval_target_usize()?;