nu_protocol/errors/
parse_warning.rs

1use crate::Span;
2use miette::Diagnostic;
3use serde::{Deserialize, Serialize};
4use std::hash::Hash;
5use thiserror::Error;
6
7use super::ReportMode;
8
9#[derive(Clone, Debug, Error, Diagnostic, Serialize, Deserialize)]
10pub enum ParseWarning {
11    #[error("{dep_type} deprecated.")]
12    #[diagnostic(code(nu::parser::deprecated))]
13    DeprecationWarning {
14        dep_type: String,
15        #[label("{label}")]
16        span: Span,
17        label: String,
18        report_mode: ReportMode,
19        #[help]
20        help: Option<String>,
21    },
22}
23
24impl ParseWarning {
25    pub fn span(&self) -> Span {
26        match self {
27            ParseWarning::DeprecationWarning { span, .. } => *span,
28        }
29    }
30
31    pub fn report_mode(&self) -> ReportMode {
32        match self {
33            ParseWarning::DeprecationWarning { report_mode, .. } => *report_mode,
34        }
35    }
36}
37
38// To keep track of reported warnings
39impl Hash for ParseWarning {
40    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
41        match self {
42            ParseWarning::DeprecationWarning {
43                dep_type, label, ..
44            } => {
45                dep_type.hash(state);
46                label.hash(state);
47            }
48        }
49    }
50}