Account for confusable codepoints when recovering emoji identifiers
This commit is contained in:
parent
4489aeb907
commit
21224e6ee0
4 changed files with 30 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
|||
use crate::lexer::unicode_chars::UNICODE_ARRAY;
|
||||
use rustc_ast::ast::{self, AttrStyle};
|
||||
use rustc_ast::token::{self, CommentKind, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::{Spacing, TokenStream};
|
||||
|
@ -222,7 +223,17 @@ impl<'a> StringReader<'a> {
|
|||
}
|
||||
token::Ident(sym, is_raw_ident)
|
||||
}
|
||||
rustc_lexer::TokenKind::InvalidIdent => {
|
||||
rustc_lexer::TokenKind::InvalidIdent
|
||||
// Do not recover an identifier with emojis if the codepoint is a confusable
|
||||
// with a recoverable substitution token, like `➖`.
|
||||
if UNICODE_ARRAY
|
||||
.iter()
|
||||
.find(|&&(c, _, _)| {
|
||||
let sym = self.str_from(start);
|
||||
sym.chars().count() == 1 && c == sym.chars().next().unwrap()
|
||||
})
|
||||
.is_none() =>
|
||||
{
|
||||
let sym = nfc_normalize(self.str_from(start));
|
||||
let span = self.mk_sp(start, self.pos);
|
||||
self.sess.bad_unicode_identifiers.borrow_mut().entry(sym).or_default().push(span);
|
||||
|
@ -299,7 +310,7 @@ impl<'a> StringReader<'a> {
|
|||
rustc_lexer::TokenKind::Caret => token::BinOp(token::Caret),
|
||||
rustc_lexer::TokenKind::Percent => token::BinOp(token::Percent),
|
||||
|
||||
rustc_lexer::TokenKind::Unknown => {
|
||||
rustc_lexer::TokenKind::Unknown | rustc_lexer::TokenKind::InvalidIdent => {
|
||||
let c = self.str_from(start).chars().next().unwrap();
|
||||
let mut err =
|
||||
self.struct_fatal_span_char(start, self.pos, "unknown start of token", c);
|
||||
|
|
|
@ -7,7 +7,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
|
|||
use rustc_span::{symbol::kw, BytePos, Pos, Span};
|
||||
|
||||
#[rustfmt::skip] // for line breaks
|
||||
const UNICODE_ARRAY: &[(char, &str, char)] = &[
|
||||
pub(crate) const UNICODE_ARRAY: &[(char, &str, char)] = &[
|
||||
('
', "Line Separator", ' '),
|
||||
('
', "Paragraph Separator", ' '),
|
||||
(' ', "Ogham Space mark", ' '),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue