Revert parts of "Use absolute paths in generated code"

to restore compatibility with older versions of Rust.
This commit is contained in:
Jonas Platte 2020-12-17 18:25:11 +01:00
parent d19c57d23d
commit a1fc2f9fad
No known key found for this signature in database
GPG Key ID: 9D5B897BFF66575C
5 changed files with 23 additions and 19 deletions

View File

@ -256,17 +256,17 @@ impl Into<proc_macro2::TokenStream> for Field {
fn into(self) -> proc_macro2::TokenStream { fn into(self) -> proc_macro2::TokenStream {
match self { match self {
Field::FieldString => quote! { ::std::string::String }, Field::FieldString => quote! { ::std::string::String },
Field::FieldBool => quote! { ::std::primitive::bool }, Field::FieldBool => quote! { bool },
Field::FieldI8 => quote! { ::std::primitive::i8 }, Field::FieldI8 => quote! { i8 },
Field::FieldU8 => quote! { ::std::primitive::u8 }, Field::FieldU8 => quote! { u8 },
Field::FieldI16 => quote! { ::std::primitive::i16 }, Field::FieldI16 => quote! { i16 },
Field::FieldU16 => quote! { ::std::primitive::u16 }, Field::FieldU16 => quote! { u16 },
Field::FieldI32 => quote! { ::std::primitive::i32 }, Field::FieldI32 => quote! { i32 },
Field::FieldU32 => quote! { ::std::primitive::u32 }, Field::FieldU32 => quote! { u32 },
Field::FieldI64 => quote! { ::std::primitive::i64 }, Field::FieldI64 => quote! { i64 },
Field::FieldU64 => quote! { ::std::primitive::u64 }, Field::FieldU64 => quote! { u64 },
Field::FieldF32 => quote! { ::std::primitive::f32 }, Field::FieldF32 => quote! { f32 },
Field::FieldF64 => quote! { ::std::primitive::f64 }, Field::FieldF64 => quote! { f64 },
_ => panic!("Not a simple type: {:?}", self), _ => panic!("Not a simple type: {:?}", self),
} }
} }

View File

@ -161,7 +161,7 @@ fn build_unnamed_field_visitors(fields: &syn::FieldsUnnamed) -> TokenStream {
fn #visitor( fn #visitor(
self, self,
v: &::std::primitive::str, v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> { ) -> ::std::result::Result<Self::Value, ::std::string::String> {
#fn_body #fn_body
} }

View File

@ -82,7 +82,7 @@ pub fn parse(
fn visit_str( fn visit_str(
self, self,
v: &::std::primitive::str, v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> { ) -> ::std::result::Result<Self::Value, ::std::string::String> {
let content = "<".to_string() + #struct_id + ">" + v + "</" + #struct_id + ">"; let content = "<".to_string() + #struct_id + ">" + v + "</" + #struct_id + ">";
::yaserde::de::from_str(&content) ::yaserde::de::from_str(&content)
@ -114,7 +114,7 @@ pub fn parse(
fn #visitor( fn #visitor(
self, self,
v: &::std::primitive::str, v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> { ) -> ::std::result::Result<Self::Value, ::std::string::String> {
::std::result::Result::Ok(#field_type::from_str(#map_if_bool).unwrap()) ::std::result::Result::Ok(#field_type::from_str(#map_if_bool).unwrap())
} }
@ -363,7 +363,7 @@ pub fn parse(
let event = reader.peek()?.to_owned(); let event = reader.peek()?.to_owned();
::log::trace!( ::log::trace!(
"Struct {} @ {}: matching {:?}", "Struct {} @ {}: matching {:?}",
::std::stringify!(#name), start_depth, event, stringify!(#name), start_depth, event,
); );
match event { match event {
::xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => { ::xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => {

View File

@ -3,7 +3,7 @@ pub mod expand_enum;
pub mod expand_struct; pub mod expand_struct;
use crate::common::YaSerdeAttribute; use crate::common::YaSerdeAttribute;
use proc_macro2::TokenStream; use proc_macro2::{Ident, TokenStream};
use quote::quote; use quote::quote;
pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream, String> { pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream, String> {
@ -29,9 +29,11 @@ pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream,
syn::Data::Union(ref _data_union) => unimplemented!(), syn::Data::Union(ref _data_union) => unimplemented!(),
}; };
let dummy_const = Ident::new(&format!("_IMPL_YA_DESERIALIZE_FOR_{}", name), name.span());
Ok(quote! { Ok(quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = { const #dummy_const: () = {
use ::std::str::FromStr as _; use ::std::str::FromStr as _;
use ::yaserde::Visitor as _; use ::yaserde::Visitor as _;

View File

@ -6,7 +6,7 @@ pub mod label;
pub mod namespace; pub mod namespace;
use crate::common::YaSerdeAttribute; use crate::common::YaSerdeAttribute;
use proc_macro2::TokenStream; use proc_macro2::{Ident, TokenStream};
use quote::quote; use quote::quote;
pub fn expand_derive_serialize(ast: &syn::DeriveInput) -> Result<TokenStream, String> { pub fn expand_derive_serialize(ast: &syn::DeriveInput) -> Result<TokenStream, String> {
@ -32,9 +32,11 @@ pub fn expand_derive_serialize(ast: &syn::DeriveInput) -> Result<TokenStream, St
syn::Data::Union(ref _data_union) => unimplemented!(), syn::Data::Union(ref _data_union) => unimplemented!(),
}; };
let dummy_const = Ident::new(&format!("_IMPL_YA_SERIALIZE_FOR_{}", name), name.span());
Ok(quote! { Ok(quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = { const #dummy_const: () = {
use ::std::str::FromStr as _; use ::std::str::FromStr as _;
#impl_block #impl_block