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`](crate::ShellWarning::Deprecated) if this is a deprecation
14    /// which is only detectable at run-time.
15    #[error("{dep_type} deprecated.")]
16    #[diagnostic(code(nu::parser::deprecated))]
17    Deprecated {
18        dep_type: String,
19        label: String,
20        #[label("{label}")]
21        span: Span,
22        #[help]
23        help: Option<String>,
24        report_mode: ReportMode,
25    },
26}
27
28impl ParseWarning {
29    pub fn span(&self) -> Span {
30        match self {
31            ParseWarning::Deprecated { span, .. } => *span,
32        }
33    }
34}
35
36impl Reportable for ParseWarning {
37    fn report_mode(&self) -> ReportMode {
38        match self {
39            ParseWarning::Deprecated { report_mode, .. } => *report_mode,
40        }
41    }
42}
43
44// To keep track of reported warnings
45impl Hash for ParseWarning {
46    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
47        match self {
48            ParseWarning::Deprecated {
49                dep_type, label, ..
50            } => {
51                dep_type.hash(state);
52                label.hash(state);
53            }
54        }
55    }
56}