Merge from rust-lang/rust

This commit is contained in:
Laurențiu Nicola 2025-04-28 11:06:53 +03:00
commit 6225bb9c44
15 changed files with 69 additions and 219 deletions

View file

@ -16,12 +16,11 @@ either.workspace = true
itertools.workspace = true
rowan = "=0.15.15"
rustc-hash.workspace = true
rustc-literal-escaper.workspace = true
smol_str.workspace = true
triomphe.workspace = true
tracing.workspace = true
ra-ap-rustc_lexer.workspace = true
parser.workspace = true
stdx.workspace = true

View file

@ -2,7 +2,7 @@
use std::{borrow::Cow, num::ParseIntError};
use rustc_lexer::unescape::{
use rustc_literal_escaper::{
EscapeError, MixedUnit, Mode, unescape_byte, unescape_char, unescape_mixed, unescape_unicode,
};
use stdx::always;

View file

@ -19,13 +19,6 @@
//! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md>
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
#[cfg(not(feature = "in-rust-tree"))]
extern crate ra_ap_rustc_lexer as rustc_lexer;
#[cfg(feature = "in-rust-tree")]
extern crate rustc_lexer;
mod parsing;
mod ptr;
mod syntax_error;
@ -64,7 +57,7 @@ pub use rowan::{
Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent,
api::Preorder,
};
pub use rustc_lexer::unescape;
pub use rustc_literal_escaper as unescape;
pub use smol_str::{SmolStr, SmolStrBuilder, ToSmolStr, format_smolstr};
/// `Parse` is the result of the parsing: a syntax tree and a collection of

View file

@ -6,7 +6,7 @@ mod block;
use itertools::Itertools;
use rowan::Direction;
use rustc_lexer::unescape::{self, Mode, unescape_mixed, unescape_unicode};
use rustc_literal_escaper::{self, EscapeError, Mode, unescape_mixed, unescape_unicode};
use crate::{
AstNode, SyntaxError,
@ -46,8 +46,8 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
}
}
fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> (&'static str, bool) {
use unescape::EscapeError as EE;
fn rustc_unescape_error_to_string(err: EscapeError) -> (&'static str, bool) {
use rustc_literal_escaper::EscapeError as EE;
#[rustfmt::skip]
let err_message = match err {
@ -129,7 +129,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
let text = token.text();
// FIXME: lift this lambda refactor to `fn` (https://github.com/rust-lang/rust-analyzer/pull/2834#discussion_r366199205)
let mut push_err = |prefix_len, off, err: unescape::EscapeError| {
let mut push_err = |prefix_len, off, err: EscapeError| {
let off = token.text_range().start() + TextSize::try_from(off + prefix_len).unwrap();
let (message, is_err) = rustc_unescape_error_to_string(err);
// FIXME: Emit lexer warnings