From 6ad55b3decefd53263f20a6c575aaa85c1edcbec Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 27 Feb 2019 22:06:26 +0300 Subject: syntax: Introduce `Ident::can_be_raw` --- src/libsyntax_ext/proc_macro_decls.rs | 4 ++-- src/libsyntax_ext/proc_macro_server.rs | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'src/libsyntax_ext') diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index efa6ce56648..6787ba6dd43 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -128,7 +128,7 @@ impl<'a> CollectProcMacros<'a> { } }; - if trait_ident.is_path_segment_keyword() { + if !trait_ident.can_be_raw() { self.handler.span_err(trait_attr.span(), &format!("`{}` cannot be a name of derive macro", trait_ident)); } @@ -162,7 +162,7 @@ impl<'a> CollectProcMacros<'a> { return None; } }; - if ident.is_path_segment_keyword() { + if !ident.can_be_raw() { self.handler.span_err( attr.span(), &format!("`{}` cannot be a name of derive helper attribute", ident), diff --git a/src/libsyntax_ext/proc_macro_server.rs b/src/libsyntax_ext/proc_macro_server.rs index a7ac95ba9ef..c0a9dfe6189 100644 --- a/src/libsyntax_ext/proc_macro_server.rs +++ b/src/libsyntax_ext/proc_macro_server.rs @@ -340,12 +340,8 @@ impl Ident { if !Self::is_valid(string) { panic!("`{:?}` is not a valid identifier", string) } - if is_raw { - let normalized_sym = Symbol::intern(string); - if normalized_sym == keywords::Underscore.name() || - ast::Ident::with_empty_ctxt(normalized_sym).is_path_segment_keyword() { - panic!("`{:?}` is not a valid raw identifier", string) - } + if is_raw && !ast::Ident::from_str(string).can_be_raw() { + panic!("`{}` cannot be a raw identifier", string); } Ident { sym, is_raw, span } } -- cgit 1.4.1-3-g733a5