Unnamed repository; edit this file 'description' to name the repository.
Merge #10346
10346: minor: align code with code-style r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
bors[bot] 2021-09-25
parent de2ea00 · parent 5767f31 · commit 0cb9ee2
-rw-r--r--crates/syntax/src/validation.rs68
1 files changed, 35 insertions, 33 deletions
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 8d1c6f5d26..745419f074 100644
--- a/crates/syntax/src/validation.rs
+++ b/crates/syntax/src/validation.rs
@@ -4,6 +4,13 @@
mod block;
+use std::convert::TryFrom;
+
+use rowan::Direction;
+use rustc_lexer::unescape::{
+ self, unescape_byte, unescape_byte_literal, unescape_char, unescape_literal, Mode,
+};
+
use crate::{
algo,
ast::{self, VisibilityOwner},
@@ -11,11 +18,34 @@ use crate::{
SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS},
SyntaxNode, SyntaxToken, TextSize, T,
};
-use rowan::Direction;
-use rustc_lexer::unescape::{
- self, unescape_byte, unescape_byte_literal, unescape_char, unescape_literal, Mode,
-};
-use std::convert::TryFrom;
+
+pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
+ // FIXME:
+ // * Add unescape validation of raw string literals and raw byte string literals
+ // * Add validation of doc comments are being attached to nodes
+
+ let mut errors = Vec::new();
+ for node in root.descendants() {
+ 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),
+ ast::Visibility(it) => validate_visibility(it, &mut errors),
+ ast::RangeExpr(it) => validate_range_expr(it, &mut errors),
+ ast::PathSegment(it) => validate_path_keywords(it, &mut errors),
+ ast::RefType(it) => validate_trait_object_ref_ty(it, &mut errors),
+ ast::PtrType(it) => validate_trait_object_ptr_ty(it, &mut errors),
+ ast::FnPtrType(it) => validate_trait_object_fn_ptr_ret_ty(it, &mut errors),
+ ast::MacroRules(it) => validate_macro_rules(it, &mut errors),
+ _ => (),
+ }
+ }
+ }
+ errors
+}
fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
use unescape::EscapeError as EE;
@@ -84,34 +114,6 @@ fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
err_message
}
-pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
- // FIXME:
- // * Add unescape validation of raw string literals and raw byte string literals
- // * Add validation of doc comments are being attached to nodes
-
- let mut errors = Vec::new();
- for node in root.descendants() {
- 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),
- ast::Visibility(it) => validate_visibility(it, &mut errors),
- ast::RangeExpr(it) => validate_range_expr(it, &mut errors),
- ast::PathSegment(it) => validate_path_keywords(it, &mut errors),
- ast::RefType(it) => validate_trait_object_ref_ty(it, &mut errors),
- ast::PtrType(it) => validate_trait_object_ptr_ty(it, &mut errors),
- ast::FnPtrType(it) => validate_trait_object_fn_ptr_ret_ty(it, &mut errors),
- ast::MacroRules(it) => validate_macro_rules(it, &mut errors),
- _ => (),
- }
- }
- }
- errors
-}
-
fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
// FIXME: move this function to outer scope (https://github.com/rust-analyzer/rust-analyzer/pull/2834#discussion_r366196658)
fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {