Skip to content

Commit 0cb9ee2

Browse files
bors[bot]matklad
andauthored
Merge #10346
10346: minor: align code with code-style r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents de2ea00 + 5767f31 commit 0cb9ee2

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

crates/syntax/src/validation.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,48 @@
44
55
mod block;
66

7+
use std::convert::TryFrom;
8+
9+
use rowan::Direction;
10+
use rustc_lexer::unescape::{
11+
self, unescape_byte, unescape_byte_literal, unescape_char, unescape_literal, Mode,
12+
};
13+
714
use crate::{
815
algo,
916
ast::{self, VisibilityOwner},
1017
match_ast, AstNode, SyntaxError,
1118
SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS},
1219
SyntaxNode, SyntaxToken, TextSize, T,
1320
};
14-
use rowan::Direction;
15-
use rustc_lexer::unescape::{
16-
self, unescape_byte, unescape_byte_literal, unescape_char, unescape_literal, Mode,
17-
};
18-
use std::convert::TryFrom;
21+
22+
pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
23+
// FIXME:
24+
// * Add unescape validation of raw string literals and raw byte string literals
25+
// * Add validation of doc comments are being attached to nodes
26+
27+
let mut errors = Vec::new();
28+
for node in root.descendants() {
29+
match_ast! {
30+
match node {
31+
ast::Literal(it) => validate_literal(it, &mut errors),
32+
ast::Const(it) => validate_const(it, &mut errors),
33+
ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors),
34+
ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors),
35+
ast::RecordExprField(it) => validate_numeric_name(it.name_ref(), &mut errors),
36+
ast::Visibility(it) => validate_visibility(it, &mut errors),
37+
ast::RangeExpr(it) => validate_range_expr(it, &mut errors),
38+
ast::PathSegment(it) => validate_path_keywords(it, &mut errors),
39+
ast::RefType(it) => validate_trait_object_ref_ty(it, &mut errors),
40+
ast::PtrType(it) => validate_trait_object_ptr_ty(it, &mut errors),
41+
ast::FnPtrType(it) => validate_trait_object_fn_ptr_ret_ty(it, &mut errors),
42+
ast::MacroRules(it) => validate_macro_rules(it, &mut errors),
43+
_ => (),
44+
}
45+
}
46+
}
47+
errors
48+
}
1949

2050
fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
2151
use unescape::EscapeError as EE;
@@ -84,34 +114,6 @@ fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
84114
err_message
85115
}
86116

87-
pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
88-
// FIXME:
89-
// * Add unescape validation of raw string literals and raw byte string literals
90-
// * Add validation of doc comments are being attached to nodes
91-
92-
let mut errors = Vec::new();
93-
for node in root.descendants() {
94-
match_ast! {
95-
match node {
96-
ast::Literal(it) => validate_literal(it, &mut errors),
97-
ast::Const(it) => validate_const(it, &mut errors),
98-
ast::BlockExpr(it) => block::validate_block_expr(it, &mut errors),
99-
ast::FieldExpr(it) => validate_numeric_name(it.name_ref(), &mut errors),
100-
ast::RecordExprField(it) => validate_numeric_name(it.name_ref(), &mut errors),
101-
ast::Visibility(it) => validate_visibility(it, &mut errors),
102-
ast::RangeExpr(it) => validate_range_expr(it, &mut errors),
103-
ast::PathSegment(it) => validate_path_keywords(it, &mut errors),
104-
ast::RefType(it) => validate_trait_object_ref_ty(it, &mut errors),
105-
ast::PtrType(it) => validate_trait_object_ptr_ty(it, &mut errors),
106-
ast::FnPtrType(it) => validate_trait_object_fn_ptr_ret_ty(it, &mut errors),
107-
ast::MacroRules(it) => validate_macro_rules(it, &mut errors),
108-
_ => (),
109-
}
110-
}
111-
}
112-
errors
113-
}
114-
115117
fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
116118
// FIXME: move this function to outer scope (https://github.com/rust-analyzer/rust-analyzer/pull/2834#discussion_r366196658)
117119
fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {

0 commit comments

Comments
 (0)