2
2
3
3
mod block;
4
4
5
- use std:: convert:: TryFrom ;
6
-
7
- use rustc_lexer:: unescape;
8
-
9
5
use crate :: {
10
6
ast, match_ast, AstNode , SyntaxError ,
11
7
SyntaxKind :: { BYTE , BYTE_STRING , CHAR , CONST_DEF , FN_DEF , INT_NUMBER , STRING , TYPE_ALIAS_DEF } ,
12
8
SyntaxNode , SyntaxToken , TextSize , T ,
13
9
} ;
10
+ use rustc_lexer:: unescape:: {
11
+ self , unescape_byte, unescape_byte_literal, unescape_char, unescape_literal, Mode ,
12
+ } ;
13
+ use std:: convert:: TryFrom ;
14
14
15
15
fn rustc_unescape_error_to_string ( err : unescape:: EscapeError ) -> & ' static str {
16
16
use unescape:: EscapeError as EE ;
@@ -81,10 +81,8 @@ fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
81
81
82
82
pub ( crate ) fn validate ( root : & SyntaxNode ) -> Vec < SyntaxError > {
83
83
// FIXME:
84
- // * Add validation of character literal containing only a single char
85
- // * Add validation of `crate` keyword not appearing in the middle of the symbol path
84
+ // * Add unescape validation of raw string literals and raw byte string literals
86
85
// * Add validation of doc comments are being attached to nodes
87
- // * Remove validation of unterminated literals (it is already implemented in `tokenize()`)
88
86
89
87
let mut errors = Vec :: new ( ) ;
90
88
for node in root. descendants ( ) {
@@ -121,18 +119,18 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
121
119
122
120
match token. kind ( ) {
123
121
BYTE => {
124
- if let Some ( Err ( e) ) = unquote ( text, 2 , '\'' ) . map ( unescape :: unescape_byte) {
122
+ if let Some ( Err ( e) ) = unquote ( text, 2 , '\'' ) . map ( unescape_byte) {
125
123
push_err ( 2 , e) ;
126
124
}
127
125
}
128
126
CHAR => {
129
- if let Some ( Err ( e) ) = unquote ( text, 1 , '\'' ) . map ( unescape :: unescape_char) {
127
+ if let Some ( Err ( e) ) = unquote ( text, 1 , '\'' ) . map ( unescape_char) {
130
128
push_err ( 1 , e) ;
131
129
}
132
130
}
133
131
BYTE_STRING => {
134
132
if let Some ( without_quotes) = unquote ( text, 2 , '"' ) {
135
- unescape :: unescape_byte_str ( without_quotes, & mut |range, char| {
133
+ unescape_byte_literal ( without_quotes, Mode :: ByteStr , & mut |range, char| {
136
134
if let Err ( err) = char {
137
135
push_err ( 2 , ( range. start , err) ) ;
138
136
}
@@ -141,7 +139,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
141
139
}
142
140
STRING => {
143
141
if let Some ( without_quotes) = unquote ( text, 1 , '"' ) {
144
- unescape :: unescape_str ( without_quotes, & mut |range, char| {
142
+ unescape_literal ( without_quotes, Mode :: Str , & mut |range, char| {
145
143
if let Err ( err) = char {
146
144
push_err ( 1 , ( range. start , err) ) ;
147
145
}
0 commit comments