nu_protocol/errors/
parse_warning.rs

1use crate::Span;
2use miette::Diagnostic;
3use std::hash::Hash;
4use thiserror::Error;
5
6use crate::{ReportMode, Reportable};
7
8#[derive(Clone, Debug, Error, Diagnostic)]
9#[diagnostic(severity(Warning))]
10pub enum ParseWarning {
11    /// A parse-time deprectaion. Indicates that something will be removed in a future release.
12    ///
13    /// Use [`ShellWarning::Deprecated`] if this is a deprecation which is only detectable at run-time.
14    #[error("{dep_type} deprecated.")]
15    #[diagnostic(code(nu::parser::deprecated))]
16    Deprecated {
17        dep_type: String,
18        label: String,
19        #[label("{label}")]
20        span: Span,
21        #[help]
22        help: Option<String>,
23        report_mode: ReportMode,
24    },
25}
26
27impl ParseWarning {
28    pub fn span(&self) -> Span {
29        match self {
30            ParseWarning::Deprecated { span, .. } => *span,
31        }
32    }
33}
34
35impl Reportable for ParseWarning {
36    fn report_mode(&self) -> ReportMode {
37        match self {
38            ParseWarning::Deprecated { report_mode, .. } => *report_mode,
39        }
40    }
41}
42
43// To keep track of reported warnings
44impl Hash for ParseWarning {
45    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
46        match self {
47            ParseWarning::Deprecated {
48                dep_type, label, ..
49            } => {
50                dep_type.hash(state);
51                label.hash(state);
52            }
53        }
54    }
55}