aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/validation.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 7694e8834..3e216fb70 100644
--- a/crates/syntax/src/validation.rs
+++ b/crates/syntax/src/validation.rs
@@ -1,4 +1,6 @@
1//! FIXME: write short doc here 1//! This module implements syntax validation that the parser doesn't handle.
2//!
3//! A failed validation emits a diagnostic.
2 4
3mod block; 5mod block;
4 6
@@ -92,6 +94,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
92 match_ast! { 94 match_ast! {
93 match node { 95 match node {
94 ast::Literal(it) => validate_literal(it, &mut errors), 96 ast::Literal(it) => validate_literal(it, &mut errors),
97 ast::Const(it) => validate_const(it, &mut errors),
95 ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors), 98 ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors),
96 ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors), 99 ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors),
97 ast::RecordExprField(it) => validate_numeric_name(it.name_ref(), &mut errors), 100 ast::RecordExprField(it) => validate_numeric_name(it.name_ref(), &mut errors),
@@ -362,3 +365,14 @@ fn validate_macro_rules(mac: ast::MacroRules, errors: &mut Vec<SyntaxError>) {
362 )); 365 ));
363 } 366 }
364} 367}
368
369fn validate_const(const_: ast::Const, errors: &mut Vec<SyntaxError>) {
370 if let Some(mut_token) = const_
371 .const_token()
372 .and_then(|t| t.next_token())
373 .and_then(|t| algo::skip_trivia_token(t, Direction::Next))
374 .filter(|t| t.kind() == T![mut])
375 {
376 errors.push(SyntaxError::new("const globals cannot be mutable", mut_token.text_range()));
377 }
378}