Skip to content

Commit cc6ccf7

Browse files
Merge #4590
4590: Update to rustc_lexer version 660 r=matklad a=Julian-Wollersberger Change the `unescape_*()` functions to `unescape_literal()`, to address the canges I made in rust-lang/rust#72047. I also noticed some outdated FIXMEs. Co-authored-by: Julian Wollersberger <[email protected]>
2 parents f4f5fca + ff9d553 commit cc6ccf7

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_syntax/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ doctest = false
1313
[dependencies]
1414
itertools = "0.9.0"
1515
rowan = "0.10.0"
16-
rustc_lexer = { version = "656.0.0", package = "rustc-ap-rustc_lexer" }
16+
rustc_lexer = { version = "660.0.0", package = "rustc-ap-rustc_lexer" }
1717
rustc-hash = "1.1.0"
1818
arrayvec = "0.5.1"
1919
once_cell = "1.3.1"

crates/ra_syntax/src/ast/tokens.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
ast::{AstToken, Comment, RawString, String, Whitespace},
77
TextRange, TextSize,
88
};
9+
use rustc_lexer::unescape::{unescape_literal, Mode};
910

1011
impl Comment {
1112
pub fn kind(&self) -> CommentKind {
@@ -147,7 +148,7 @@ impl HasStringValue for String {
147148

148149
let mut buf = std::string::String::with_capacity(text.len());
149150
let mut has_error = false;
150-
rustc_lexer::unescape::unescape_str(text, &mut |_, unescaped_char| match unescaped_char {
151+
unescape_literal(text, Mode::Str, &mut |_, unescaped_char| match unescaped_char {
151152
Ok(c) => buf.push(c),
152153
Err(_) => has_error = true,
153154
});
@@ -498,7 +499,7 @@ impl HasFormatSpecifier for String {
498499
let offset = self.text_range_between_quotes()?.start() - self.syntax().text_range().start();
499500

500501
let mut res = Vec::with_capacity(text.len());
501-
rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| {
502+
unescape_literal(text, Mode::Str, &mut |range, unescaped_char| {
502503
res.push((
503504
TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap())
504505
+ offset,

crates/ra_syntax/src/validation.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
33
mod block;
44

5-
use std::convert::TryFrom;
6-
7-
use rustc_lexer::unescape;
8-
95
use 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

1515
fn 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

8282
pub(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

Comments
 (0)