Skip to content

Commit

Permalink
Revert signature change for AssertMessage description
Browse files Browse the repository at this point in the history
  • Loading branch information
celinval committed Dec 15, 2023
1 parent c0f1207 commit 6004386
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ty::{
VariantIdx,
};
use crate::{Error, Opaque, Span, Symbol};
use std::borrow::Cow;
use std::io;
/// The SMIR representation of a single function.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -265,63 +264,51 @@ pub enum AssertMessage {
}

impl AssertMessage {
pub fn description(&self) -> Result<Cow<'static, str>, 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")
}
}
}
Expand Down

0 comments on commit 6004386

Please sign in to comment.