Skip to main content

nu_protocol/errors/
parse_warning.rs

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