1use std::fmt::{Debug, Display, Formatter};
8use std::{fmt, io};
9
10use rustc_public_bridge::bridge;
11
12macro_rules! error {
13 ($fmt: literal $(,)?) => { Error(format!($fmt)) };
14 ($fmt: literal, $($arg:tt)*) => { Error(format!($fmt, $($arg)*)) };
15}
16
17pub(crate) use error;
18
19#[derive(#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for CompilerError<T> {
#[inline]
fn clone(&self) -> CompilerError<T> {
match self {
CompilerError::Failed => CompilerError::Failed,
CompilerError::Interrupted(__self_0) =>
CompilerError::Interrupted(::core::clone::Clone::clone(__self_0)),
CompilerError::Skipped => CompilerError::Skipped,
}
}
}Clone, #[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for CompilerError<T> { }Copy, #[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for CompilerError<T> {
#[inline]
fn eq(&self, other: &CompilerError<T>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(CompilerError::Interrupted(__self_0),
CompilerError::Interrupted(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<T: ::core::cmp::Eq> ::core::cmp::Eq for CompilerError<T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<T>;
}
}Eq)]
21pub enum CompilerError<T> {
22 Failed,
24 Interrupted(T),
26 Skipped,
29}
30
31#[derive(#[automatically_derived]
impl ::core::clone::Clone for Error {
#[inline]
fn clone(&self) -> Error { Error(::core::clone::Clone::clone(&self.0)) }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Error {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Error",
&&self.0)
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for Error {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<String>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for Error {
#[inline]
fn eq(&self, other: &Error) -> bool { self.0 == other.0 }
}PartialEq)]
33pub struct Error(pub(crate) String);
34
35impl bridge::Error for Error {
36 fn new(msg: String) -> Self {
37 Self(msg)
38 }
39
40 fn from_internal<T: Debug>(err: T) -> Self {
41 Self(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", err))
})format!("{err:?}"))
42 }
43}
44
45impl From<&str> for Error {
46 fn from(value: &str) -> Self {
47 Self(value.into())
48 }
49}
50
51impl Display for Error {
52 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
53 Display::fmt(&self.0, f)
54 }
55}
56
57impl<T> Display for CompilerError<T>
58where
59 T: Display,
60{
61 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
62 match self {
63 CompilerError::Failed => f.write_fmt(format_args!("Compilation Failed"))write!(f, "Compilation Failed"),
64 CompilerError::Interrupted(reason) => f.write_fmt(format_args!("Compilation Interrupted: {0}", reason))write!(f, "Compilation Interrupted: {reason}"),
65 CompilerError::Skipped => f.write_fmt(format_args!("Compilation Skipped"))write!(f, "Compilation Skipped"),
66 }
67 }
68}
69
70impl<T> Debug for CompilerError<T>
71where
72 T: Debug,
73{
74 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
75 match self {
76 CompilerError::Failed => f.write_fmt(format_args!("Compilation Failed"))write!(f, "Compilation Failed"),
77 CompilerError::Interrupted(reason) => f.write_fmt(format_args!("Compilation Interrupted: {0:?}", reason))write!(f, "Compilation Interrupted: {reason:?}"),
78 CompilerError::Skipped => f.write_fmt(format_args!("Compilation Skipped"))write!(f, "Compilation Skipped"),
79 }
80 }
81}
82
83impl std::error::Error for Error {}
84
85impl<T> std::error::Error for CompilerError<T> where T: Display + Debug {}
86
87impl From<io::Error> for Error {
88 fn from(value: io::Error) -> Self {
89 Error(value.to_string())
90 }
91}