Skip to content

Commit 7f9cc88

Browse files
committed
Add symbol normalization for proc_macro_server.
1 parent a9dd56f commit 7f9cc88

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/librustc_expand/proc_macro_server.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::base::ExtCtxt;
22

3+
use rustc_parse::lexer::nfc_normalize;
34
use rustc_parse::{nt_to_tokenstream, parse_stream_from_source_str};
45
use syntax::ast;
56
use syntax::print::pprust;
@@ -327,6 +328,7 @@ impl Ident {
327328
}
328329
}
329330
fn new(sym: Symbol, is_raw: bool, span: Span) -> Ident {
331+
let sym = nfc_normalize(&sym.as_str());
330332
let string = sym.as_str();
331333
if !Self::is_valid(&string) {
332334
panic!("`{:?}` is not a valid identifier", string)

src/librustc_parse/lexer/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,9 @@ impl<'a> StringReader<'a> {
471471

472472
/// As symbol_from, with the text normalized into Unicode NFC form.
473473
fn nfc_symbol_from(&self, start: BytePos) -> Symbol {
474-
use unicode_normalization::{is_nfc_quick, IsNormalized, UnicodeNormalization};
475474
debug!("taking an normalized ident from {:?} to {:?}", start, self.pos);
476475
let sym = self.str_from(start);
477-
match is_nfc_quick(sym.chars()) {
478-
IsNormalized::Yes => Symbol::intern(sym),
479-
_ => {
480-
let sym_str: String = sym.chars().nfc().collect();
481-
Symbol::intern(&sym_str)
482-
}
483-
}
476+
nfc_normalize(sym)
484477
}
485478

486479
/// Slice of the source text spanning from `start` up to but excluding `end`.
@@ -651,3 +644,14 @@ impl<'a> StringReader<'a> {
651644
}
652645
}
653646
}
647+
648+
pub fn nfc_normalize(string: &str) -> Symbol {
649+
use unicode_normalization::{is_nfc_quick, IsNormalized, UnicodeNormalization};
650+
match is_nfc_quick(string.chars()) {
651+
IsNormalized::Yes => Symbol::intern(string),
652+
_ => {
653+
let normalized_str: String = string.chars().nfc().collect();
654+
Symbol::intern(&normalized_str)
655+
}
656+
}
657+
}

0 commit comments

Comments
 (0)