mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-19 01:50:32 +00:00
Add validation for mutable const items
This commit is contained in:
parent
89fef5307e
commit
70d43c3faf
6 changed files with 40 additions and 25 deletions
|
@ -1,4 +1,6 @@
|
|||
//! FIXME: write short doc here
|
||||
//! This module implements syntax validation that the parser doesn't handle.
|
||||
//!
|
||||
//! A failed validation emits a diagnostic.
|
||||
|
||||
mod block;
|
||||
|
||||
|
@ -92,6 +94,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
|
|||
match_ast! {
|
||||
match node {
|
||||
ast::Literal(it) => validate_literal(it, &mut errors),
|
||||
ast::Const(it) => validate_const(it, &mut errors),
|
||||
ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors),
|
||||
ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors),
|
||||
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>) {
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_const(const_: ast::Const, errors: &mut Vec<SyntaxError>) {
|
||||
if let Some(mut_token) = const_
|
||||
.const_token()
|
||||
.and_then(|t| t.next_token())
|
||||
.and_then(|t| algo::skip_trivia_token(t, Direction::Next))
|
||||
.filter(|t| t.kind() == T![mut])
|
||||
{
|
||||
errors.push(SyntaxError::new("const globals cannot be mutable", mut_token.text_range()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue