Skip to main content

sva_ast/
refusal.rs

1// Concern: declares the directory-level located Refusal, wrapping a Diag with the file it landed in | Non-concern: raising one (graph.rs), the code registry (diag.rs) | IO: none
2
3use crate::diag::{ByteSpan, DiagCode};
4
5#[derive(Clone, Debug, PartialEq, Eq)]
6pub struct Location {
7    pub path: String,
8    pub span: ByteSpan,
9    /// The line and column, from 1, where a check that read the file's text knows them.
10    pub start: Option<(usize, usize)>,
11}
12
13/// `{ at, code, reason }`: never a panic, never a poison node — a hole in the graph
14/// is data beside it, not inside it.
15#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct Refusal {
17    pub at: Location,
18    pub code: DiagCode,
19    pub reason: String,
20}
21
22impl Refusal {
23    pub fn new(
24        path: impl Into<String>,
25        span: ByteSpan,
26        code: DiagCode,
27        reason: impl Into<String>,
28    ) -> Refusal {
29        Refusal {
30            at: Location {
31                path: path.into(),
32                span,
33                start: None,
34            },
35            code,
36            reason: reason.into(),
37        }
38    }
39
40    pub fn placed(mut self, start: (usize, usize)) -> Refusal {
41        self.at.start = Some(start);
42        self
43    }
44}