Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
// Include the leading `'` in the real identifier, for macro
// expansion purposes. See #12512 for the gory details of why
// this is necessary.
let lifetime_name = self.str_from(start);
let lifetime_name = nfc_normalize(self.str_from(start));
self.last_lifetime = Some(self.mk_sp(start, start + BytePos(1)));
if starts_with_number {
let span = self.mk_sp(start, self.pos);
Expand All @@ -325,8 +325,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
.with_span(span)
.stash(span, StashKey::LifetimeIsChar);
}
let ident = Symbol::intern(lifetime_name);
token::Lifetime(ident, IdentIsRaw::No)
token::Lifetime(lifetime_name, IdentIsRaw::No)
}
rustc_lexer::TokenKind::RawLifetime => {
self.last_lifetime = Some(self.mk_sp(start, start + BytePos(1)));
Expand Down Expand Up @@ -373,7 +372,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
String::with_capacity(lifetime_name_without_tick.as_str().len() + 1);
lifetime_name.push('\'');
lifetime_name += lifetime_name_without_tick.as_str();
let sym = Symbol::intern(&lifetime_name);
let sym = nfc_normalize(&lifetime_name);

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

let lifetime_name = self.str_from(start);
let ident = Symbol::intern(lifetime_name);
token::Lifetime(ident, IdentIsRaw::No)
let lifetime_name = nfc_normalize(self.str_from(start));
token::Lifetime(lifetime_name, IdentIsRaw::No)
}
}
rustc_lexer::TokenKind::Semi => token::Semi,
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/lexer/ident_normalization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@check-pass
//@edition:2021

#![allow(non_snake_case)]

// Tests that identifiers are NFC-normalized as per
// https://rust-lang.github.io/rfcs/2457-non-ascii-idents.html

// Note that in the first argument of each function `K` is LATIN CAPITAL LETTER K
// and in the second it is K (KELVIN SIGN).

fn ident_nfc<K>(_p1: K, _p2: ) {}

fn raw_ident_nfc<K>(_p1: r#K, _p2: r#K) {}

fn lifetime_nfc<'K>(_p1: &'K str, _p2: &' str) {}

fn raw_lifetime_nfc<'K>(_p1: &'r#K str, _p2: &'r#K str) {}

fn main() {}
Loading