rune/diagnostics/
runtime.rs1use core::fmt;
2
3use crate::Hash;
4
5#[derive(Debug)]
8pub struct RuntimeDiagnostic {
9 pub(crate) ip: usize,
11 pub(crate) kind: RuntimeDiagnosticKind,
13}
14
15impl RuntimeDiagnostic {
16 pub fn ip(&self) -> usize {
18 self.ip
19 }
20
21 #[cfg(feature = "emit")]
23 #[allow(unused)]
24 pub(crate) fn kind(&self) -> &RuntimeDiagnosticKind {
25 &self.kind
26 }
27
28 #[cfg(test)]
29 #[allow(unused)]
30 pub(crate) fn into_kind(self) -> RuntimeDiagnosticKind {
31 self.kind
32 }
33}
34
35impl fmt::Display for RuntimeDiagnostic {
36 #[inline]
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 fmt::Display::fmt(&self.kind, f)
39 }
40}
41
42impl core::error::Error for RuntimeDiagnostic {}
43
44#[derive(Debug)]
46#[allow(missing_docs)]
47#[non_exhaustive]
48pub(crate) enum RuntimeDiagnosticKind {
49 UsedDeprecated {
50 #[cfg_attr(not(feature = "emit"), allow(dead_code))]
52 hash: Hash,
53 },
54}
55
56impl fmt::Display for RuntimeDiagnosticKind {
57 #[inline]
58 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59 match self {
60 RuntimeDiagnosticKind::UsedDeprecated { .. } => {
61 write!(f, "Used deprecated function")
62 }
63 }
64 }
65}