Skip to content

Commit 2d4e300

Browse files
committed
refactor: impl SmirError for stable_mir::Error
1 parent be05aa4 commit 2d4e300

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_smir/src/stable_mir/error.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use std::fmt::{Debug, Display, Formatter};
88
use std::{fmt, io};
99

10+
use rustc_smir::SmirError;
11+
12+
use crate::rustc_smir;
13+
1014
macro_rules! error {
1115
($fmt: literal $(,)?) => { Error(format!($fmt)) };
1216
($fmt: literal, $($arg:tt)*) => { Error(format!($fmt, $($arg)*)) };
@@ -30,10 +34,14 @@ pub enum CompilerError<T> {
3034
#[derive(Clone, Debug, Eq, PartialEq)]
3135
pub struct Error(pub(crate) String);
3236

33-
impl Error {
34-
pub fn new(msg: String) -> Self {
37+
impl SmirError for Error {
38+
fn new(msg: String) -> Self {
3539
Self(msg)
3640
}
41+
42+
fn from_internal<T: Debug>(err: T) -> Self {
43+
Self(format!("{err:?}"))
44+
}
3745
}
3846

3947
impl From<&str> for Error {

compiler/rustc_smir/src/stable_mir/mir/mono.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::fmt::{Debug, Formatter};
22
use std::io;
33

4+
use rustc_smir::{IndexedVal, SmirError};
45
use serde::Serialize;
56
use stable_mir::abi::FnAbi;
67
use stable_mir::crate_def::CrateDef;
78
use stable_mir::mir::Body;
8-
use stable_mir::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, IndexedVal, Ty};
9+
use stable_mir::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, Ty};
910
use stable_mir::{CrateItem, DefId, Error, ItemKind, Opaque, Symbol, with};
1011

11-
use crate::stable_mir;
12+
use crate::{rustc_smir, stable_mir};
1213

1314
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
1415
pub enum MonoItem {

0 commit comments

Comments
 (0)