From 600438679d2ea06d0284497a42215f2f243fd1d9 Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Thu, 14 Dec 2023 22:04:14 -0800 Subject: [PATCH] Revert signature change for AssertMessage description --- compiler/stable_mir/src/mir/body.rs | 55 +++++++++++------------------ 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index 566a44a64a3..5023af9ab79 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -4,7 +4,6 @@ VariantIdx, }; use crate::{Error, Opaque, Span, Symbol}; -use std::borrow::Cow; use std::io; /// The SMIR representation of a single function. #[derive(Clone, Debug)] @@ -265,63 +264,51 @@ pub enum AssertMessage { } impl AssertMessage { - pub fn description(&self) -> Result, Error> { + pub fn description(&self) -> Result<&'static str, Error> { match self { - AssertMessage::Overflow(BinOp::Add, _, _) => Ok("attempt to add with overflow".into()), - AssertMessage::Overflow(BinOp::Sub, _, _) => { - Ok("attempt to subtract with overflow".into()) - } - AssertMessage::Overflow(BinOp::Mul, _, _) => { - Ok("attempt to multiply with overflow".into()) - } - AssertMessage::Overflow(BinOp::Div, _, _) => { - Ok("attempt to divide with overflow".into()) - } + AssertMessage::Overflow(BinOp::Add, _, _) => Ok("attempt to add with overflow"), + AssertMessage::Overflow(BinOp::Sub, _, _) => Ok("attempt to subtract with overflow"), + AssertMessage::Overflow(BinOp::Mul, _, _) => Ok("attempt to multiply with overflow"), + AssertMessage::Overflow(BinOp::Div, _, _) => Ok("attempt to divide with overflow"), AssertMessage::Overflow(BinOp::Rem, _, _) => { - Ok("attempt to calculate the remainder with overflow".into()) - } - AssertMessage::OverflowNeg(_) => Ok("attempt to negate with overflow".into()), - AssertMessage::Overflow(BinOp::Shr, _, _) => { - Ok("attempt to shift right with overflow".into()) - } - AssertMessage::Overflow(BinOp::Shl, _, _) => { - Ok("attempt to shift left with overflow".into()) + Ok("attempt to calculate the remainder with overflow") } + AssertMessage::OverflowNeg(_) => Ok("attempt to negate with overflow"), + AssertMessage::Overflow(BinOp::Shr, _, _) => Ok("attempt to shift right with overflow"), + AssertMessage::Overflow(BinOp::Shl, _, _) => Ok("attempt to shift left with overflow"), AssertMessage::Overflow(op, _, _) => Err(error!("`{:?}` cannot overflow", op)), - AssertMessage::DivisionByZero(_) => Ok("attempt to divide by zero".into()), + AssertMessage::DivisionByZero(_) => Ok("attempt to divide by zero"), AssertMessage::RemainderByZero(_) => { - Ok("attempt to calculate the remainder with a divisor of zero".into()) + Ok("attempt to calculate the remainder with a divisor of zero") } AssertMessage::ResumedAfterReturn(CoroutineKind::Coroutine) => { - Ok("coroutine resumed after completion".into()) + Ok("coroutine resumed after completion") } AssertMessage::ResumedAfterReturn(CoroutineKind::Async(_)) => { - Ok("`async fn` resumed after completion".into()) + Ok("`async fn` resumed after completion") } AssertMessage::ResumedAfterReturn(CoroutineKind::Gen(_)) => { - Ok("`async gen fn` resumed after completion".into()) + Ok("`async gen fn` resumed after completion") } AssertMessage::ResumedAfterReturn(CoroutineKind::AsyncGen(_)) => { - Ok("`gen fn` should just keep returning `AssertMessage::None` after completion" - .into()) + Ok("`gen fn` should just keep returning `AssertMessage::None` after completion") } AssertMessage::ResumedAfterPanic(CoroutineKind::Coroutine) => { - Ok("coroutine resumed after panicking".into()) + Ok("coroutine resumed after panicking") } AssertMessage::ResumedAfterPanic(CoroutineKind::Async(_)) => { - Ok("`async fn` resumed after panicking".into()) + Ok("`async fn` resumed after panicking") } AssertMessage::ResumedAfterPanic(CoroutineKind::Gen(_)) => { - Ok("`async gen fn` resumed after panicking".into()) + Ok("`async gen fn` resumed after panicking") } AssertMessage::ResumedAfterPanic(CoroutineKind::AsyncGen(_)) => { - Ok("`gen fn` should just keep returning `AssertMessage::None` after panicking" - .into()) + Ok("`gen fn` should just keep returning `AssertMessage::None` after panicking") } - AssertMessage::BoundsCheck { .. } => Ok("index out of bounds".into()), + AssertMessage::BoundsCheck { .. } => Ok("index out of bounds"), AssertMessage::MisalignedPointerDereference { .. } => { - Ok("misaligned pointer dereference".into()) + Ok("misaligned pointer dereference") } } }