aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/validation.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-11-06 21:39:02 +0000
committerGitHub <[email protected]>2020-11-06 21:39:02 +0000
commit7f12a1f225c7d3397f27964ce039b55d680772d3 (patch)
tree26043b20588eae4510e28249f11a094aacaf190d /crates/syntax/src/validation.rs
parentcdddcaee851be1cff1eeb23599f5a58f1b30a927 (diff)
parent6158304f8b64ef7cdf58b14bc675baf33a27a853 (diff)
Merge #6485
6485: Remove RAW literals r=matklad a=matklad bors r+ 🤖 closes https://github.com/rust-analyzer/rust-analyzer/issues/6308 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/syntax/src/validation.rs')
-rw-r--r--crates/syntax/src/validation.rs41
1 files changed, 23 insertions, 18 deletions
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 0f9a5e8ae..62a37c50a 100644
--- a/crates/syntax/src/validation.rs
+++ b/crates/syntax/src/validation.rs
@@ -4,7 +4,7 @@ mod block;
4 4
5use crate::{ 5use crate::{
6 algo, ast, match_ast, AstNode, SyntaxError, 6 algo, ast, match_ast, AstNode, SyntaxError,
7 SyntaxKind::{BYTE, BYTE_STRING, CHAR, CONST, FN, INT_NUMBER, STRING, TYPE_ALIAS}, 7 SyntaxKind::{BYTE, CHAR, CONST, FN, INT_NUMBER, TYPE_ALIAS},
8 SyntaxNode, SyntaxToken, TextSize, T, 8 SyntaxNode, SyntaxToken, TextSize, T,
9}; 9};
10use rowan::Direction; 10use rowan::Direction;
@@ -121,18 +121,19 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
121 acc.push(SyntaxError::new_at_offset(rustc_unescape_error_to_string(err), off)); 121 acc.push(SyntaxError::new_at_offset(rustc_unescape_error_to_string(err), off));
122 }; 122 };
123 123
124 match token.kind() { 124 if let Some(s) = literal.as_string() {
125 BYTE => { 125 if !s.is_raw() {
126 if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) { 126 if let Some(without_quotes) = unquote(text, 1, '"') {
127 push_err(2, e); 127 unescape_literal(without_quotes, Mode::Str, &mut |range, char| {
128 } 128 if let Err(err) = char {
129 } 129 push_err(1, (range.start, err));
130 CHAR => { 130 }
131 if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) { 131 })
132 push_err(1, e);
133 } 132 }
134 } 133 }
135 BYTE_STRING => { 134 }
135 if let Some(s) = literal.as_byte_string() {
136 if !s.is_raw() {
136 if let Some(without_quotes) = unquote(text, 2, '"') { 137 if let Some(without_quotes) = unquote(text, 2, '"') {
137 unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| { 138 unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
138 if let Err(err) = char { 139 if let Err(err) = char {
@@ -141,13 +142,17 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
141 }) 142 })
142 } 143 }
143 } 144 }
144 STRING => { 145 }
145 if let Some(without_quotes) = unquote(text, 1, '"') { 146
146 unescape_literal(without_quotes, Mode::Str, &mut |range, char| { 147 match token.kind() {
147 if let Err(err) = char { 148 BYTE => {
148 push_err(1, (range.start, err)); 149 if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) {
149 } 150 push_err(2, e);
150 }) 151 }
152 }
153 CHAR => {
154 if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) {
155 push_err(1, e);
151 } 156 }
152 } 157 }
153 _ => (), 158 _ => (),