Skip to content

Commit bba0d57

Browse files
Remove usage of rustc_lexer::unescape in rust-analyzer
1 parent aff2bc7 commit bba0d57

File tree

7 files changed

+21
-18
lines changed

7 files changed

+21
-18
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ dependencies = [
12701270
"edition",
12711271
"expect-test",
12721272
"ra-ap-rustc_lexer",
1273+
"rustc-literal-escaper",
12731274
"stdx",
12741275
"tracing",
12751276
]
@@ -1743,6 +1744,12 @@ version = "2.0.0"
17431744
source = "registry+https://github.com/rust-lang/crates.io-index"
17441745
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
17451746

1747+
[[package]]
1748+
name = "rustc-literal-escaper"
1749+
version = "0.0.1"
1750+
source = "registry+https://github.com/rust-lang/crates.io-index"
1751+
checksum = "cfdd0fcb1409d38cb2d940400497e2384a4a04b8685ee92a0a7a8986ccd72115"
1752+
17461753
[[package]]
17471754
name = "rustc-stable-hash"
17481755
version = "0.1.1"
@@ -1982,6 +1989,7 @@ dependencies = [
19821989
"rayon",
19831990
"rowan",
19841991
"rustc-hash 2.0.0",
1992+
"rustc-literal-escaper",
19851993
"rustc_apfloat",
19861994
"smol_str",
19871995
"stdx",

src/tools/rust-analyzer/crates/parser/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rust-version.workspace = true
1414
[dependencies]
1515
drop_bomb = "0.1.5"
1616
ra-ap-rustc_lexer.workspace = true
17+
rustc-literal-escaper = "0.0.1"
1718
tracing = { workspace = true, optional = true }
1819

1920
edition.workspace = true

src/tools/rust-analyzer/crates/parser/src/lexed_str.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
use std::ops;
1212

13-
use rustc_lexer::unescape::{EscapeError, Mode};
13+
use rustc_literal_escaper::{EscapeError, Mode, unescape_byte, unescape_char, unescape_mixed, unescape_unicode};
1414

1515
use crate::{
1616
Edition,
@@ -282,7 +282,7 @@ impl<'a> Converter<'a> {
282282
let text = &self.res.text[self.offset + 1..][..len - 1];
283283
let i = text.rfind('\'').unwrap();
284284
let text = &text[..i];
285-
if let Err(e) = rustc_lexer::unescape::unescape_char(text) {
285+
if let Err(e) = unescape_char(text) {
286286
err = error_to_diagnostic_message(e, Mode::Char);
287287
}
288288
}
@@ -295,7 +295,7 @@ impl<'a> Converter<'a> {
295295
let text = &self.res.text[self.offset + 2..][..len - 2];
296296
let i = text.rfind('\'').unwrap();
297297
let text = &text[..i];
298-
if let Err(e) = rustc_lexer::unescape::unescape_byte(text) {
298+
if let Err(e) = unescape_byte(text) {
299299
err = error_to_diagnostic_message(e, Mode::Byte);
300300
}
301301
}
@@ -402,14 +402,14 @@ fn unescape_string_error_message(text: &str, mode: Mode) -> &'static str {
402402
let mut error_message = "";
403403
match mode {
404404
Mode::CStr => {
405-
rustc_lexer::unescape::unescape_mixed(text, mode, &mut |_, res| {
405+
unescape_mixed(text, mode, &mut |_, res| {
406406
if let Err(e) = res {
407407
error_message = error_to_diagnostic_message(e, mode);
408408
}
409409
});
410410
}
411411
Mode::ByteStr | Mode::Str => {
412-
rustc_lexer::unescape::unescape_unicode(text, mode, &mut |_, res| {
412+
unescape_unicode(text, mode, &mut |_, res| {
413413
if let Err(e) = res {
414414
error_message = error_to_diagnostic_message(e, mode);
415415
}

src/tools/rust-analyzer/crates/syntax/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ either.workspace = true
1717
itertools.workspace = true
1818
rowan = "=0.15.15"
1919
rustc-hash.workspace = true
20+
rustc-literal-escaper = "0.0.1"
2021
indexmap.workspace = true
2122
smol_str.workspace = true
2223
triomphe.workspace = true

src/tools/rust-analyzer/crates/syntax/src/ast/token_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{borrow::Cow, num::ParseIntError};
44

5-
use rustc_lexer::unescape::{
5+
use rustc_literal_escaper::{
66
unescape_byte, unescape_char, unescape_mixed, unescape_unicode, EscapeError, MixedUnit, Mode,
77
};
88
use stdx::always;

src/tools/rust-analyzer/crates/syntax/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
//! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
2020
//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md>
2121
22-
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
23-
24-
#[cfg(not(feature = "in-rust-tree"))]
25-
extern crate ra_ap_rustc_lexer as rustc_lexer;
26-
#[cfg(feature = "in-rust-tree")]
27-
extern crate rustc_lexer;
28-
2922
mod parsing;
3023
mod ptr;
3124
mod syntax_error;
@@ -64,7 +57,7 @@ pub use rowan::{
6457
api::Preorder, Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize,
6558
TokenAtOffset, WalkEvent,
6659
};
67-
pub use rustc_lexer::unescape;
60+
pub use rustc_literal_escaper as unescape;
6861
pub use smol_str::{format_smolstr, SmolStr, SmolStrBuilder, ToSmolStr};
6962

7063
/// `Parse` is the result of the parsing: a syntax tree and a collection of

src/tools/rust-analyzer/crates/syntax/src/validation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
mod block;
66

77
use rowan::Direction;
8-
use rustc_lexer::unescape::{self, unescape_mixed, unescape_unicode, Mode};
8+
use rustc_literal_escaper::{unescape_mixed, unescape_unicode, EscapeError, Mode};
99

1010
use crate::{
1111
algo,
@@ -44,8 +44,8 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
4444
}
4545
}
4646

47-
fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> (&'static str, bool) {
48-
use unescape::EscapeError as EE;
47+
fn rustc_unescape_error_to_string(err: EscapeError) -> (&'static str, bool) {
48+
use rustc_literal_escaper::EscapeError as EE;
4949

5050
#[rustfmt::skip]
5151
let err_message = match err {
@@ -127,7 +127,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
127127
let text = token.text();
128128

129129
// FIXME: lift this lambda refactor to `fn` (https://github.com/rust-lang/rust-analyzer/pull/2834#discussion_r366199205)
130-
let mut push_err = |prefix_len, off, err: unescape::EscapeError| {
130+
let mut push_err = |prefix_len, off, err: EscapeError| {
131131
let off = token.text_range().start() + TextSize::try_from(off + prefix_len).unwrap();
132132
let (message, is_err) = rustc_unescape_error_to_string(err);
133133
// FIXME: Emit lexer warnings

0 commit comments

Comments
 (0)