1
Fork 0

Add symbol normalization for proc_macro_server.

This commit is contained in:
Charles Lew 2019-12-29 19:50:43 +08:00
parent a9dd56ff9a
commit 7f9cc88f4a
2 changed files with 14 additions and 8 deletions

View file

@ -1,5 +1,6 @@
use crate::base::ExtCtxt;
use rustc_parse::lexer::nfc_normalize;
use rustc_parse::{nt_to_tokenstream, parse_stream_from_source_str};
use syntax::ast;
use syntax::print::pprust;
@ -327,6 +328,7 @@ impl Ident {
}
}
fn new(sym: Symbol, is_raw: bool, span: Span) -> Ident {
let sym = nfc_normalize(&sym.as_str());
let string = sym.as_str();
if !Self::is_valid(&string) {
panic!("`{:?}` is not a valid identifier", string)

View file

@ -471,16 +471,9 @@ impl<'a> StringReader<'a> {
/// As symbol_from, with the text normalized into Unicode NFC form.
fn nfc_symbol_from(&self, start: BytePos) -> Symbol {
use unicode_normalization::{is_nfc_quick, IsNormalized, UnicodeNormalization};
debug!("taking an normalized ident from {:?} to {:?}", start, self.pos);
let sym = self.str_from(start);
match is_nfc_quick(sym.chars()) {
IsNormalized::Yes => Symbol::intern(sym),
_ => {
let sym_str: String = sym.chars().nfc().collect();
Symbol::intern(&sym_str)
}
}
nfc_normalize(sym)
}
/// Slice of the source text spanning from `start` up to but excluding `end`.
@ -651,3 +644,14 @@ impl<'a> StringReader<'a> {
}
}
}
pub fn nfc_normalize(string: &str) -> Symbol {
use unicode_normalization::{is_nfc_quick, IsNormalized, UnicodeNormalization};
match is_nfc_quick(string.chars()) {
IsNormalized::Yes => Symbol::intern(string),
_ => {
let normalized_str: String = string.chars().nfc().collect();
Symbol::intern(&normalized_str)
}
}
}