about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-09-25 11:56:23 +0000
committerGitHub <noreply@github.com>2021-09-25 11:56:23 +0000
commit0cb9ee2054c46183f0d49f449005047be426208f (patch)
tree338027d76cc32d722c559819ac6c0e29ba71bfce
parentde2ea00ace0910701620afbcaf3a124ea2cb9942 (diff)
parent5767f31cbfb8adf7586a5e101be9f9f9a21c1480 (diff)
downloadrust-0cb9ee2054c46183f0d49f449005047be426208f.tar.gz
rust-0cb9ee2054c46183f0d49f449005047be426208f.zip
Merge #10346
10346: minor: align code with code-style r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
-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 8d1c6f5d26e..745419f0741 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> {