From 5767f31cbfb8adf7586a5e101be9f9f9a21c1480 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Sep 2021 14:55:42 +0300 Subject: [PATCH] minor: align code with code-style --- crates/syntax/src/validation.rs | 68 +++++++++++++++++---------------- 1 file 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 { + // 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 { - // 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) { // 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> {