Skip to content

Commit b56deeb

Browse files
authoredApr 11, 2023
Rollup merge of rust-lang#110135 - compiler-errors:revert-108031, r=davidtwco
Revert "Don't recover lifetimes/labels containing emojis as character literals" Reverts PR rust-lang#108031 per rust-lang#109754 (comment) Fixes (doesnt close until beta backported) rust-lang#109746 This reverts commit e3f9db5. This reverts commit 98b82ae. This reverts commit 380fa26.
2 parents 45749b2 + a047064 commit b56deeb

File tree

8 files changed

+17
-178
lines changed

8 files changed

+17
-178
lines changed
 

‎compiler/rustc_errors/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,6 @@ pub enum StashKey {
475475
/// When an invalid lifetime e.g. `'2` should be reinterpreted
476476
/// as a char literal in the parser
477477
LifetimeIsChar,
478-
/// When an invalid lifetime e.g. `'🐱` contains emoji.
479-
LifetimeContainsEmoji,
480478
/// Maybe there was a typo where a comma was forgotten before
481479
/// FRU syntax
482480
MaybeFruTypo,

‎compiler/rustc_lexer/src/lib.rs

+10-33
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum TokenKind {
9595
Literal { kind: LiteralKind, suffix_start: u32 },
9696

9797
/// "'a"
98-
Lifetime { starts_with_number: bool, contains_emoji: bool },
98+
Lifetime { starts_with_number: bool },
9999

100100
// One-char tokens:
101101
/// ";"
@@ -632,13 +632,7 @@ impl Cursor<'_> {
632632
// If the first symbol is valid for identifier, it can be a lifetime.
633633
// Also check if it's a number for a better error reporting (so '0 will
634634
// be reported as invalid lifetime and not as unterminated char literal).
635-
// We also have to account for potential `'🐱` emojis to avoid reporting
636-
// it as an unterminated char literal.
637-
is_id_start(self.first())
638-
|| self.first().is_digit(10)
639-
// FIXME(#108019): `unic-emoji-char` seems to have data tables only up to Unicode
640-
// 5.0, but Unicode is already newer than this.
641-
|| unic_emoji_char::is_emoji(self.first())
635+
is_id_start(self.first()) || self.first().is_digit(10)
642636
};
643637

644638
if !can_be_a_lifetime {
@@ -651,33 +645,16 @@ impl Cursor<'_> {
651645
return Literal { kind, suffix_start };
652646
}
653647

654-
// Either a lifetime or a character literal.
648+
// Either a lifetime or a character literal with
649+
// length greater than 1.
655650

656651
let starts_with_number = self.first().is_digit(10);
657-
let mut contains_emoji = false;
658652

659-
// FIXME(#108019): `unic-emoji-char` seems to have data tables only up to Unicode
660-
// 5.0, but Unicode is already newer than this.
661-
if unic_emoji_char::is_emoji(self.first()) {
662-
contains_emoji = true;
663-
} else {
664-
// Skip the literal contents.
665-
// First symbol can be a number (which isn't a valid identifier start),
666-
// so skip it without any checks.
667-
self.bump();
668-
}
669-
self.eat_while(|c| {
670-
if is_id_continue(c) {
671-
true
672-
// FIXME(#108019): `unic-emoji-char` seems to have data tables only up to Unicode
673-
// 5.0, but Unicode is already newer than this.
674-
} else if unic_emoji_char::is_emoji(c) {
675-
contains_emoji = true;
676-
true
677-
} else {
678-
false
679-
}
680-
});
653+
// Skip the literal contents.
654+
// First symbol can be a number (which isn't a valid identifier start),
655+
// so skip it without any checks.
656+
self.bump();
657+
self.eat_while(is_id_continue);
681658

682659
// Check if after skipping literal contents we've met a closing
683660
// single quote (which means that user attempted to create a
@@ -687,7 +664,7 @@ impl Cursor<'_> {
687664
let kind = Char { terminated: true };
688665
Literal { kind, suffix_start: self.pos_within_token() }
689666
} else {
690-
Lifetime { starts_with_number, contains_emoji }
667+
Lifetime { starts_with_number }
691668
}
692669
}
693670

‎compiler/rustc_lexer/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn lifetime() {
235235
check_lexing(
236236
"'abc",
237237
expect![[r#"
238-
Token { kind: Lifetime { starts_with_number: false, contains_emoji: false }, len: 4 }
238+
Token { kind: Lifetime { starts_with_number: false }, len: 4 }
239239
"#]],
240240
);
241241
}

‎compiler/rustc_parse/src/lexer/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,16 @@ impl<'a> StringReader<'a> {
223223
};
224224
token::Literal(token::Lit { kind, symbol, suffix })
225225
}
226-
rustc_lexer::TokenKind::Lifetime { starts_with_number, contains_emoji } => {
226+
rustc_lexer::TokenKind::Lifetime { starts_with_number } => {
227227
// Include the leading `'` in the real identifier, for macro
228228
// expansion purposes. See #12512 for the gory details of why
229229
// this is necessary.
230230
let lifetime_name = self.str_from(start);
231231
if starts_with_number {
232232
let span = self.mk_sp(start, self.pos);
233-
let mut diag = self.sess.struct_err("lifetimes or labels cannot start with a number");
233+
let mut diag = self.sess.struct_err("lifetimes cannot start with a number");
234234
diag.set_span(span);
235235
diag.stash(span, StashKey::LifetimeIsChar);
236-
} else if contains_emoji {
237-
let span = self.mk_sp(start, self.pos);
238-
let mut diag = self.sess.struct_err("lifetimes or labels cannot contain emojis");
239-
diag.set_span(span);
240-
diag.stash(span, StashKey::LifetimeContainsEmoji);
241236
}
242237
let ident = Symbol::intern(lifetime_name);
243238
token::Lifetime(ident)

‎tests/ui/lexer/issue-108019-bad-emoji-recovery.rs

-45
This file was deleted.

‎tests/ui/lexer/issue-108019-bad-emoji-recovery.stderr

-86
This file was deleted.

‎tests/ui/parser/numeric-lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct S<'1> { s: &'1 usize }
2-
//~^ ERROR lifetimes or labels cannot start with a number
3-
//~| ERROR lifetimes or labels cannot start with a number
2+
//~^ ERROR lifetimes cannot start with a number
3+
//~| ERROR lifetimes cannot start with a number
44
fn main() {
55
// verify that the parse error doesn't stop type checking
66
let x: usize = "";

‎tests/ui/parser/numeric-lifetime.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ LL | let x: usize = "";
66
| |
77
| expected due to this
88

9-
error: lifetimes or labels cannot start with a number
9+
error: lifetimes cannot start with a number
1010
--> $DIR/numeric-lifetime.rs:1:10
1111
|
1212
LL | struct S<'1> { s: &'1 usize }
1313
| ^^
1414

15-
error: lifetimes or labels cannot start with a number
15+
error: lifetimes cannot start with a number
1616
--> $DIR/numeric-lifetime.rs:1:20
1717
|
1818
LL | struct S<'1> { s: &'1 usize }

0 commit comments

Comments
 (0)