Skip to content

Commit 2cd4ee6

Browse files
committed
Auto merge of #149192 - gmorenz:normalize_lifetimes, r=madsmtm
NFC normalize lifetime identifiers Fixes #126759
2 parents 430d829 + b1cde92 commit 2cd4ee6

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
316316
// Include the leading `'` in the real identifier, for macro
317317
// expansion purposes. See #12512 for the gory details of why
318318
// this is necessary.
319-
let lifetime_name = self.str_from(start);
319+
let lifetime_name = nfc_normalize(self.str_from(start));
320320
self.last_lifetime = Some(self.mk_sp(start, start + BytePos(1)));
321321
if starts_with_number {
322322
let span = self.mk_sp(start, self.pos);
@@ -325,8 +325,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
325325
.with_span(span)
326326
.stash(span, StashKey::LifetimeIsChar);
327327
}
328-
let ident = Symbol::intern(lifetime_name);
329-
token::Lifetime(ident, IdentIsRaw::No)
328+
token::Lifetime(lifetime_name, IdentIsRaw::No)
330329
}
331330
rustc_lexer::TokenKind::RawLifetime => {
332331
self.last_lifetime = Some(self.mk_sp(start, start + BytePos(1)));
@@ -373,7 +372,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
373372
String::with_capacity(lifetime_name_without_tick.as_str().len() + 1);
374373
lifetime_name.push('\'');
375374
lifetime_name += lifetime_name_without_tick.as_str();
376-
let sym = Symbol::intern(&lifetime_name);
375+
let sym = nfc_normalize(&lifetime_name);
377376

378377
// Make sure we mark this as a raw identifier.
379378
self.psess.raw_identifier_spans.push(span);
@@ -393,9 +392,8 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
393392
self.pos = lt_start;
394393
self.cursor = Cursor::new(&str_before[2 as usize..], FrontmatterAllowed::No);
395394

396-
let lifetime_name = self.str_from(start);
397-
let ident = Symbol::intern(lifetime_name);
398-
token::Lifetime(ident, IdentIsRaw::No)
395+
let lifetime_name = nfc_normalize(self.str_from(start));
396+
token::Lifetime(lifetime_name, IdentIsRaw::No)
399397
}
400398
}
401399
rustc_lexer::TokenKind::Semi => token::Semi,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@check-pass
2+
//@edition:2021
3+
4+
#![allow(non_snake_case)]
5+
6+
// Tests that identifiers are NFC-normalized as per
7+
// https://rust-lang.github.io/rfcs/2457-non-ascii-idents.html
8+
9+
// Note that in the first argument of each function `K` is LATIN CAPITAL LETTER K
10+
// and in the second it is K (KELVIN SIGN).
11+
12+
fn ident_nfc<K>(_p1: K, _p2: ) {}
13+
14+
fn raw_ident_nfc<K>(_p1: r#K, _p2: r#K) {}
15+
16+
fn lifetime_nfc<'K>(_p1: &'K str, _p2: &' str) {}
17+
18+
fn raw_lifetime_nfc<'K>(_p1: &'r#K str, _p2: &'r#K str) {}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)