rune/diagnostics/
runtime_warning.rs

1use core::fmt;
2
3use crate::Hash;
4
5/// Runtime Warning diagnostic emitted during the execution of the VM. Warning diagnostics indicates
6/// an recoverable issues.
7#[derive(Debug)]
8pub struct RuntimeWarningDiagnostic {
9    /// The instruction pointer of the vm where the warning happened.
10    pub(crate) ip: usize,
11    /// The kind of the warning.
12    pub(crate) kind: RuntimeWarningDiagnosticKind,
13}
14
15impl RuntimeWarningDiagnostic {
16    /// The instruction pointer of the vm where the warning happened.
17    pub fn ip(&self) -> usize {
18        self.ip
19    }
20
21    /// The kind of the warning.
22    #[cfg(feature = "emit")]
23    #[allow(unused)]
24    pub(crate) fn kind(&self) -> &RuntimeWarningDiagnosticKind {
25        &self.kind
26    }
27
28    #[cfg(test)]
29    #[allow(unused)]
30    pub(crate) fn into_kind(self) -> RuntimeWarningDiagnosticKind {
31        self.kind
32    }
33}
34
35impl fmt::Display for RuntimeWarningDiagnostic {
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 RuntimeWarningDiagnostic {
43    #[inline]
44    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
45        None
46    }
47}
48
49/// The kind of a [RuntimeWarningDiagnostic].
50#[derive(Debug)]
51#[allow(missing_docs)]
52#[non_exhaustive]
53pub(crate) enum RuntimeWarningDiagnosticKind {
54    UsedDeprecated {
55        /// The hash which produced the deprecation
56        #[cfg_attr(not(feature = "emit"), allow(dead_code))]
57        hash: Hash,
58    },
59}
60
61impl fmt::Display for RuntimeWarningDiagnosticKind {
62    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63        match self {
64            RuntimeWarningDiagnosticKind::UsedDeprecated { .. } => {
65                write!(f, "Used deprecated function")
66            }
67        }
68    }
69}