1 //! See docs for `SyntaxError`.
5 use crate::{TextRange, TextSize};
7 /// Represents the result of unsuccessful tokenization, parsing
8 /// or tree validation.
9 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
10 pub struct SyntaxError(String, TextRange);
12 // FIXME: there was an unused SyntaxErrorKind previously (before this enum was removed)
13 // It was introduced in this PR: https://github.com/rust-analyzer/rust-analyzer/pull/846/files#diff-827da9b03b8f9faa1bade5cdd44d5dafR95
14 // but it was not removed by a mistake.
16 // So, we need to find a place where to stick validation for attributes in match clauses.
17 // Code before refactor:
18 // InvalidMatchInnerAttr => {
19 // write!(f, "Inner attributes are only allowed directly after the opening brace of the match expression")
23 pub fn new(message: impl Into<String>, range: TextRange) -> Self {
24 Self(message.into(), range)
26 pub fn new_at_offset(message: impl Into<String>, offset: TextSize) -> Self {
27 Self(message.into(), TextRange::empty(offset))
30 pub fn range(&self) -> TextRange {
34 pub fn with_range(mut self, range: TextRange) -> Self {
40 impl fmt::Display for SyntaxError {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {