macros: update string interning
This commit is contained in:
parent
d7cbdb509c
commit
7ebef5bbe6
|
@ -25,10 +25,9 @@ use syntax::ext::base::{ExtCtxt, Annotatable};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax_ext::deriving::generic::*;
|
use syntax_ext::deriving::generic::*;
|
||||||
use syntax_ext::deriving::generic::ty::*;
|
use syntax_ext::deriving::generic::ty::*;
|
||||||
use syntax::parse::token::InternedString;
|
use syntax::symbol::Symbol;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::ext::base::MultiDecorator;
|
use syntax::ext::base::MultiDecorator;
|
||||||
use syntax::parse::token;
|
|
||||||
|
|
||||||
use rustc_plugin::Registry;
|
use rustc_plugin::Registry;
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
|
||||||
item: &Annotatable,
|
item: &Annotatable,
|
||||||
push: &mut FnMut(Annotatable))
|
push: &mut FnMut(Annotatable))
|
||||||
{
|
{
|
||||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
let inline = cx.meta_word(span, Symbol::intern("inline"));
|
||||||
let attrs = vec!(cx.attribute(span, inline));
|
let attrs = vec!(cx.attribute(span, inline));
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
is_unsafe: false,
|
is_unsafe: false,
|
||||||
|
@ -128,13 +127,13 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
StaticStruct(..) => {
|
StaticStruct(..) => {
|
||||||
cx.span_err(trait_span, "`FromPrimitive` cannot be derived for structs");
|
cx.span_err(trait_span, "`FromPrimitive` cannot be derived for structs");
|
||||||
return cx.expr_fail(trait_span, InternedString::new(""));
|
return cx.expr_fail(trait_span, Symbol::intern(""));
|
||||||
}
|
}
|
||||||
StaticEnum(enum_def, _) => {
|
StaticEnum(enum_def, _) => {
|
||||||
if enum_def.variants.is_empty() {
|
if enum_def.variants.is_empty() {
|
||||||
cx.span_err(trait_span,
|
cx.span_err(trait_span,
|
||||||
"`FromPrimitive` cannot be derived for enums with no variants");
|
"`FromPrimitive` cannot be derived for enums with no variants");
|
||||||
return cx.expr_fail(trait_span, InternedString::new(""));
|
return cx.expr_fail(trait_span, Symbol::intern(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut arms = Vec::new();
|
let mut arms = Vec::new();
|
||||||
|
@ -169,14 +168,14 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
||||||
"`FromPrimitive` cannot be derived for \
|
"`FromPrimitive` cannot be derived for \
|
||||||
enum variants with arguments");
|
enum variants with arguments");
|
||||||
return cx.expr_fail(trait_span,
|
return cx.expr_fail(trait_span,
|
||||||
InternedString::new(""));
|
Symbol::intern(""));
|
||||||
}
|
}
|
||||||
ast::VariantData::Struct(..) => {
|
ast::VariantData::Struct(..) => {
|
||||||
cx.span_err(trait_span,
|
cx.span_err(trait_span,
|
||||||
"`FromPrimitive` cannot be derived for enums \
|
"`FromPrimitive` cannot be derived for enums \
|
||||||
with struct variants");
|
with struct variants");
|
||||||
return cx.expr_fail(trait_span,
|
return cx.expr_fail(trait_span,
|
||||||
InternedString::new(""));
|
Symbol::intern(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,6 +199,6 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn plugin_registrar(reg: &mut Registry) {
|
pub fn plugin_registrar(reg: &mut Registry) {
|
||||||
reg.register_syntax_extension(
|
reg.register_syntax_extension(
|
||||||
token::intern("derive_NumFromPrimitive"),
|
Symbol::intern("derive_NumFromPrimitive"),
|
||||||
MultiDecorator(Box::new(expand_deriving_from_primitive)));
|
MultiDecorator(Box::new(expand_deriving_from_primitive)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue