From cd4ffc1945a3a1ca89776e9abdcd60b1896f356c Mon Sep 17 00:00:00 2001 From: Julian Wollersberger <24991778+Julian-Wollersberger@users.noreply.github.com> Date: Sun, 24 May 2020 13:12:16 +0200 Subject: Update to rustc_lexer version 660. Change `unescape_*()` to `unescape_literal()`. --- crates/ra_syntax/Cargo.toml | 2 +- crates/ra_syntax/src/ast/tokens.rs | 5 +++-- crates/ra_syntax/src/validation.rs | 16 ++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'crates') diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index c07ff488e..a9a5cc7bc 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml @@ -13,7 +13,7 @@ doctest = false [dependencies] itertools = "0.9.0" rowan = "0.10.0" -rustc_lexer = { version = "656.0.0", package = "rustc-ap-rustc_lexer" } +rustc_lexer = { version = "660.0.0", package = "rustc-ap-rustc_lexer" } rustc-hash = "1.1.0" arrayvec = "0.5.1" once_cell = "1.3.1" diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 74906d8a6..3cd6d99c3 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs @@ -6,6 +6,7 @@ use crate::{ ast::{AstToken, Comment, RawString, String, Whitespace}, TextRange, TextSize, }; +use rustc_lexer::unescape::{unescape_literal, Mode}; impl Comment { pub fn kind(&self) -> CommentKind { @@ -147,7 +148,7 @@ impl HasStringValue for String { let mut buf = std::string::String::with_capacity(text.len()); let mut has_error = false; - rustc_lexer::unescape::unescape_str(text, &mut |_, unescaped_char| match unescaped_char { + unescape_literal(text, Mode::Str, &mut |_, unescaped_char| match unescaped_char { Ok(c) => buf.push(c), Err(_) => has_error = true, }); @@ -498,7 +499,7 @@ impl HasFormatSpecifier for String { let offset = self.text_range_between_quotes()?.start() - self.syntax().text_range().start(); let mut res = Vec::with_capacity(text.len()); - rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| { + unescape_literal(text, Mode::Str, &mut |range, unescaped_char| { res.push(( TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap()) + offset, diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index d68cf0a82..436ab033d 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -2,15 +2,15 @@ mod block; -use std::convert::TryFrom; - -use rustc_lexer::unescape; - use crate::{ ast, match_ast, AstNode, SyntaxError, SyntaxKind::{BYTE, BYTE_STRING, CHAR, CONST_DEF, FN_DEF, INT_NUMBER, STRING, TYPE_ALIAS_DEF}, SyntaxNode, SyntaxToken, TextSize, T, }; +use rustc_lexer::unescape::{ + self, unescape_byte, unescape_byte_literal, unescape_char, unescape_literal, Mode, +}; +use std::convert::TryFrom; fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str { use unescape::EscapeError as EE; @@ -121,18 +121,18 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec) { match token.kind() { BYTE => { - if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape::unescape_byte) { + if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) { push_err(2, e); } } CHAR => { - if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape::unescape_char) { + if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) { push_err(1, e); } } BYTE_STRING => { if let Some(without_quotes) = unquote(text, 2, '"') { - unescape::unescape_byte_str(without_quotes, &mut |range, char| { + unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| { if let Err(err) = char { push_err(2, (range.start, err)); } @@ -141,7 +141,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec) { } STRING => { if let Some(without_quotes) = unquote(text, 1, '"') { - unescape::unescape_str(without_quotes, &mut |range, char| { + unescape_literal(without_quotes, Mode::Str, &mut |range, char| { if let Err(err) = char { push_err(1, (range.start, err)); } -- cgit v1.2.3 From ff9d553fe3af092e4ef5467f07cef62af27b868b Mon Sep 17 00:00:00 2001 From: Julian Wollersberger <24991778+Julian-Wollersberger@users.noreply.github.com> Date: Sun, 24 May 2020 13:17:16 +0200 Subject: Some FIXMEs were outdated: * Done at line 243: "Add validation of `crate` keyword not appearing in the middle of the symbol path" * Already happened: "Remove validation of unterminated literals (it is already implemented in `tokenize()`)" * Happens in `unescape()`: "Add validation of character literal containing only a single char" * Missing: "raw string literals and raw byte string literals" --- crates/ra_syntax/src/validation.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index 436ab033d..fdec48fb0 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -81,10 +81,8 @@ fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> &'static str { pub(crate) fn validate(root: &SyntaxNode) -> Vec { // FIXME: - // * Add validation of character literal containing only a single char - // * Add validation of `crate` keyword not appearing in the middle of the symbol path + // * Add unescape validation of raw string literals and raw byte string literals // * Add validation of doc comments are being attached to nodes - // * Remove validation of unterminated literals (it is already implemented in `tokenize()`) let mut errors = Vec::new(); for node in root.descendants() { -- cgit v1.2.3