|
4 | 4 |
|
5 | 5 | mod block;
|
6 | 6 |
|
| 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 | + |
7 | 14 | use crate::{
|
8 | 15 | algo,
|
9 | 16 | ast::{self, VisibilityOwner},
|
10 | 17 | match_ast, AstNode, SyntaxError,
|
11 | 18 | SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS},
|
12 | 19 | SyntaxNode, SyntaxToken, TextSize, T,
|
13 | 20 | };
|
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 | +} |
19 | 49 |
|
20 | 50 | fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
|
21 | 51 | use unescape::EscapeError as EE;
|
@@ -84,34 +114,6 @@ fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
|
84 | 114 | err_message
|
85 | 115 | }
|
86 | 116 |
|
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 |
| - |
115 | 117 | fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
|
116 | 118 | // FIXME: move this function to outer scope (https://github.com/rust-analyzer/rust-analyzer/pull/2834#discussion_r366196658)
|
117 | 119 | fn unquote(text: &str, prefix_len: usize, end_delimiter: char) -> Option<&str> {
|
|
0 commit comments