22
33mod block;
44
5- use std:: convert:: TryFrom ;
6-
7- use rustc_lexer:: unescape;
8-
95use crate :: {
106 ast, match_ast, AstNode , SyntaxError ,
117 SyntaxKind :: { BYTE , BYTE_STRING , CHAR , CONST_DEF , FN_DEF , INT_NUMBER , STRING , TYPE_ALIAS_DEF } ,
128 SyntaxNode , SyntaxToken , TextSize , T ,
139} ;
10+ use rustc_lexer:: unescape:: {
11+ self , unescape_byte, unescape_byte_literal, unescape_char, unescape_literal, Mode ,
12+ } ;
13+ use std:: convert:: TryFrom ;
1414
1515fn rustc_unescape_error_to_string ( err : unescape:: EscapeError ) -> & ' static str {
1616 use unescape:: EscapeError as EE ;
@@ -81,10 +81,8 @@ fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str {
8181
8282pub ( crate ) fn validate ( root : & SyntaxNode ) -> Vec < SyntaxError > {
8383 // 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
8685 // * Add validation of doc comments are being attached to nodes
87- // * Remove validation of unterminated literals (it is already implemented in `tokenize()`)
8886
8987 let mut errors = Vec :: new ( ) ;
9088 for node in root. descendants ( ) {
@@ -121,18 +119,18 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
121119
122120 match token. kind ( ) {
123121 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) {
125123 push_err ( 2 , e) ;
126124 }
127125 }
128126 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) {
130128 push_err ( 1 , e) ;
131129 }
132130 }
133131 BYTE_STRING => {
134132 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| {
136134 if let Err ( err) = char {
137135 push_err ( 2 , ( range. start , err) ) ;
138136 }
@@ -141,7 +139,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
141139 }
142140 STRING => {
143141 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| {
145143 if let Err ( err) = char {
146144 push_err ( 1 , ( range. start , err) ) ;
147145 }
0 commit comments