aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/syntax_error.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-12 17:31:42 +0100
committerGitHub <[email protected]>2020-08-12 17:31:42 +0100
commitd583f2c46d22cf8d643ebf98be9cb7059a304431 (patch)
tree9d898eb9600b0c36a74e4f95238f679c683fa566 /crates/syntax/src/syntax_error.rs
parent3d6889cba72a9d02199f7adaa2ecc69bc30af834 (diff)
parenta1c187eef3ba08076aedb5154929f7eda8d1b424 (diff)
Merge #5729
5729: Rename ra_syntax -> syntax r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/syntax/src/syntax_error.rs')
-rw-r--r--crates/syntax/src/syntax_error.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/crates/syntax/src/syntax_error.rs b/crates/syntax/src/syntax_error.rs
new file mode 100644
index 000000000..7c4511fec
--- /dev/null
+++ b/crates/syntax/src/syntax_error.rs
@@ -0,0 +1,44 @@
1//! See docs for `SyntaxError`.
2
3use std::fmt;
4
5use crate::{TextRange, TextSize};
6
7/// Represents the result of unsuccessful tokenization, parsing
8/// or tree validation.
9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub struct SyntaxError(String, TextRange);
11
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.
15//
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")
20// }
21
22impl SyntaxError {
23 pub fn new(message: impl Into<String>, range: TextRange) -> Self {
24 Self(message.into(), range)
25 }
26 pub fn new_at_offset(message: impl Into<String>, offset: TextSize) -> Self {
27 Self(message.into(), TextRange::empty(offset))
28 }
29
30 pub fn range(&self) -> TextRange {
31 self.1
32 }
33
34 pub fn with_range(mut self, range: TextRange) -> Self {
35 self.1 = range;
36 self
37 }
38}
39
40impl fmt::Display for SyntaxError {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 self.0.fmt(f)
43 }
44}