mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Use 2018-style paths in code generated by style_derive
This commit is contained in:
parent
b60006ae11
commit
ede79a6a5d
9 changed files with 65 additions and 65 deletions
|
@ -16,7 +16,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
if !no_bound.contains(¶m.ident) {
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#param: ::values::animated::Animate),
|
||||
parse_quote!(#param: crate::values::animated::Animate),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -51,13 +51,13 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
quote! {
|
||||
impl #impl_generics ::values::animated::Animate for #name #ty_generics #where_clause {
|
||||
impl #impl_generics crate::values::animated::Animate for #name #ty_generics #where_clause {
|
||||
#[allow(unused_variables, unused_imports)]
|
||||
#[inline]
|
||||
fn animate(
|
||||
&self,
|
||||
other: &Self,
|
||||
procedure: ::values::animated::Procedure,
|
||||
procedure: crate::values::animated::Procedure,
|
||||
) -> Result<Self, ()> {
|
||||
match (self, other) {
|
||||
#match_body
|
||||
|
@ -84,12 +84,12 @@ fn derive_variant_arm(variant: &VariantInfo) -> Result<Tokens, ()> {
|
|||
if #this != #other {
|
||||
return Err(());
|
||||
}
|
||||
let #result = ::std::clone::Clone::clone(#this);
|
||||
let #result = std::clone::Clone::clone(#this);
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
let #result =
|
||||
::values::animated::Animate::animate(#this, #other, procedure)?;
|
||||
crate::values::animated::Animate::animate(#this, #other, procedure)?;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -54,7 +54,7 @@ pub fn fmap_trait_output(input: &DeriveInput, trait_path: &Path, trait_output: I
|
|||
&GenericParam::Type(ref data) => {
|
||||
let ident = data.ident;
|
||||
GenericArgument::Type(
|
||||
parse_quote!(<#ident as ::#trait_path>::#trait_output),
|
||||
parse_quote!(<#ident as #trait_path>::#trait_output),
|
||||
)
|
||||
},
|
||||
ref arg => panic!("arguments {:?} cannot be mapped yet", arg),
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
if !no_bound.contains(¶m.ident) {
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#param: ::values::distance::ComputeSquaredDistance),
|
||||
parse_quote!(#param: crate::values::distance::ComputeSquaredDistance),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
let (this_pattern, this_info) = cg::ref_pattern(&variant, "this");
|
||||
let (other_pattern, other_info) = cg::ref_pattern(&variant, "other");
|
||||
let sum = if this_info.is_empty() {
|
||||
quote! { ::values::distance::SquaredDistance::from_sqrt(0.) }
|
||||
quote! { crate::values::distance::SquaredDistance::from_sqrt(0.) }
|
||||
} else {
|
||||
let mut sum = quote!();
|
||||
sum.append_separated(this_info.iter().zip(&other_info).map(|(this, other)| {
|
||||
|
@ -44,7 +44,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
let ty = &this.ast().ty;
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#ty: ::values::distance::ComputeSquaredDistance),
|
||||
parse_quote!(#ty: crate::values::distance::ComputeSquaredDistance),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -57,12 +57,12 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
if #this != #other {
|
||||
return Err(());
|
||||
}
|
||||
::values::distance::SquaredDistance::from_sqrt(0.)
|
||||
crate::values::distance::SquaredDistance::from_sqrt(0.)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)?
|
||||
crate::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)?
|
||||
}
|
||||
}
|
||||
}), quote!(+));
|
||||
|
@ -95,13 +95,13 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
quote! {
|
||||
impl #impl_generics ::values::distance::ComputeSquaredDistance for #name #ty_generics #where_clause {
|
||||
impl #impl_generics crate::values::distance::ComputeSquaredDistance for #name #ty_generics #where_clause {
|
||||
#[allow(unused_variables, unused_imports)]
|
||||
#[inline]
|
||||
fn compute_squared_distance(
|
||||
&self,
|
||||
other: &Self,
|
||||
) -> Result<::values::distance::SquaredDistance, ()> {
|
||||
) -> Result<crate::values::distance::SquaredDistance, ()> {
|
||||
match (self, other) {
|
||||
#match_body
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
match_ignore_ascii_case! { &ident,
|
||||
#match_body
|
||||
_ => Err(location.new_unexpected_token_error(
|
||||
::cssparser::Token::Ident(ident.clone())
|
||||
cssparser::Token::Ident(ident.clone())
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +88,12 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
};
|
||||
|
||||
let parse_trait_impl = quote! {
|
||||
impl ::parser::Parse for #name {
|
||||
impl crate::parser::Parse for #name {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
#context_ident: &::parser::ParserContext,
|
||||
input: &mut ::cssparser::Parser<'i, 't>,
|
||||
) -> Result<Self, ::style_traits::ParseError<'i>> {
|
||||
#context_ident: &crate::parser::ParserContext,
|
||||
input: &mut cssparser::Parser<'i, 't>,
|
||||
) -> Result<Self, style_traits::ParseError<'i>> {
|
||||
#parse_body
|
||||
}
|
||||
}
|
||||
|
@ -110,13 +110,13 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
/// Parse this keyword.
|
||||
#[inline]
|
||||
pub fn parse<'i, 't>(
|
||||
input: &mut ::cssparser::Parser<'i, 't>,
|
||||
) -> Result<Self, ::style_traits::ParseError<'i>> {
|
||||
input: &mut cssparser::Parser<'i, 't>,
|
||||
) -> Result<Self, style_traits::ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
let ident = input.expect_ident()?;
|
||||
Self::from_ident(ident.as_ref()).map_err(|()| {
|
||||
location.new_unexpected_token_error(
|
||||
::cssparser::Token::Ident(ident.clone())
|
||||
cssparser::Token::Ident(ident.clone())
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
for param in input.generics.type_params() {
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#param: ::style_traits::SpecifiedValueInfo),
|
||||
parse_quote!(#param: style_traits::SpecifiedValueInfo),
|
||||
);
|
||||
}
|
||||
input.generics.where_clause = where_clause;
|
||||
|
@ -86,20 +86,20 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
let mut types_value = quote!(0);
|
||||
types_value.append_all(types.iter().map(|ty| {
|
||||
quote! {
|
||||
| <#ty as ::style_traits::SpecifiedValueInfo>::SUPPORTED_TYPES
|
||||
| <#ty as style_traits::SpecifiedValueInfo>::SUPPORTED_TYPES
|
||||
}
|
||||
}));
|
||||
|
||||
let mut nested_collects = quote!();
|
||||
nested_collects.append_all(types.iter().map(|ty| {
|
||||
quote! {
|
||||
<#ty as ::style_traits::SpecifiedValueInfo>::collect_completion_keywords(_f);
|
||||
<#ty as style_traits::SpecifiedValueInfo>::collect_completion_keywords(_f);
|
||||
}
|
||||
}));
|
||||
|
||||
if let Some(ty) = info_attrs.ty {
|
||||
types_value.append_all(quote! {
|
||||
| ::style_traits::CssType::#ty
|
||||
| style_traits::CssType::#ty
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
let name = &input.ident;
|
||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
quote! {
|
||||
impl #impl_generics ::style_traits::SpecifiedValueInfo for #name #ty_generics
|
||||
impl #impl_generics style_traits::SpecifiedValueInfo for #name #ty_generics
|
||||
#where_clause
|
||||
{
|
||||
const SUPPORTED_TYPES: u8 = #types_value;
|
||||
|
|
|
@ -12,19 +12,19 @@ pub fn derive(mut input: DeriveInput) -> quote::Tokens {
|
|||
for param in input.generics.type_params() {
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#param: ::values::animated::ToAnimatedValue),
|
||||
parse_quote!(#param: crate::values::animated::ToAnimatedValue),
|
||||
);
|
||||
}
|
||||
|
||||
let to_body = cg::fmap_match(
|
||||
&input,
|
||||
BindStyle::Move,
|
||||
|binding| quote!(::values::animated::ToAnimatedValue::to_animated_value(#binding)),
|
||||
|binding| quote!(crate::values::animated::ToAnimatedValue::to_animated_value(#binding)),
|
||||
);
|
||||
let from_body = cg::fmap_match(
|
||||
&input,
|
||||
BindStyle::Move,
|
||||
|binding| quote!(::values::animated::ToAnimatedValue::from_animated_value(#binding)),
|
||||
|binding| quote!(crate::values::animated::ToAnimatedValue::from_animated_value(#binding)),
|
||||
);
|
||||
|
||||
input.generics.where_clause = where_clause;
|
||||
|
@ -32,12 +32,12 @@ pub fn derive(mut input: DeriveInput) -> quote::Tokens {
|
|||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
let animated_value_type = cg::fmap_trait_output(
|
||||
&input,
|
||||
&parse_quote!(values::animated::ToAnimatedValue),
|
||||
&parse_quote!(crate::values::animated::ToAnimatedValue),
|
||||
"AnimatedValue".into(),
|
||||
);
|
||||
|
||||
quote! {
|
||||
impl #impl_generics ::values::animated::ToAnimatedValue for #name #ty_generics #where_clause {
|
||||
impl #impl_generics crate::values::animated::ToAnimatedValue for #name #ty_generics #where_clause {
|
||||
type AnimatedValue = #animated_value_type;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens {
|
|||
if !no_bound.contains(¶m.ident) {
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#param: ::values::animated::ToAnimatedZero),
|
||||
parse_quote!(#param: crate::values::animated::ToAnimatedZero),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,12 @@ pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens {
|
|||
let field_attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.ast());
|
||||
if field_attrs.constant {
|
||||
quote! {
|
||||
let #mapped_binding = ::std::clone::Clone::clone(#binding);
|
||||
let #mapped_binding = std::clone::Clone::clone(#binding);
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
let #mapped_binding =
|
||||
::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
||||
crate::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
@ -51,7 +51,7 @@ pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens {
|
|||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
quote! {
|
||||
impl #impl_generics ::values::animated::ToAnimatedZero for #name #ty_generics #where_clause {
|
||||
impl #impl_generics crate::values::animated::ToAnimatedZero for #name #ty_generics #where_clause {
|
||||
#[allow(unused_variables)]
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
for param in ¶ms {
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#param: ::values::computed::ToComputedValue),
|
||||
parse_quote!(#param: crate::values::computed::ToComputedValue),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -26,23 +26,23 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
let output_type = cg::map_type_params(
|
||||
ty,
|
||||
¶ms,
|
||||
&mut |ident| parse_quote!(<#ident as ::values::computed::ToComputedValue>::ComputedValue),
|
||||
&mut |ident| parse_quote!(<#ident as crate::values::computed::ToComputedValue>::ComputedValue),
|
||||
);
|
||||
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(
|
||||
#ty: ::values::computed::ToComputedValue<ComputedValue = #output_type>
|
||||
#ty: crate::values::computed::ToComputedValue<ComputedValue = #output_type>
|
||||
),
|
||||
);
|
||||
}
|
||||
quote! {
|
||||
::values::computed::ToComputedValue::to_computed_value(#binding, context)
|
||||
crate::values::computed::ToComputedValue::to_computed_value(#binding, context)
|
||||
}
|
||||
});
|
||||
let from_body = cg::fmap_match(&input, BindStyle::Ref, |binding| {
|
||||
quote! {
|
||||
::values::computed::ToComputedValue::from_computed_value(#binding)
|
||||
crate::values::computed::ToComputedValue::from_computed_value(#binding)
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -55,7 +55,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
|
||||
if input.generics.type_params().next().is_none() {
|
||||
return quote! {
|
||||
impl #impl_generics ::values::computed::ToComputedValue for #name #ty_generics
|
||||
impl #impl_generics crate::values::computed::ToComputedValue for #name #ty_generics
|
||||
#where_clause
|
||||
{
|
||||
type ComputedValue = Self;
|
||||
|
@ -63,14 +63,14 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
#[inline]
|
||||
fn to_computed_value(
|
||||
&self,
|
||||
_context: &::values::computed::Context,
|
||||
_context: &crate::values::computed::Context,
|
||||
) -> Self::ComputedValue {
|
||||
::std::clone::Clone::clone(self)
|
||||
std::clone::Clone::clone(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
::std::clone::Clone::clone(computed)
|
||||
std::clone::Clone::clone(computed)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -78,17 +78,17 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
|
||||
let computed_value_type = cg::fmap_trait_output(
|
||||
&input,
|
||||
&parse_quote!(values::computed::ToComputedValue),
|
||||
&parse_quote!(crate::values::computed::ToComputedValue),
|
||||
"ComputedValue".into(),
|
||||
);
|
||||
|
||||
quote! {
|
||||
impl #impl_generics ::values::computed::ToComputedValue for #name #ty_generics #where_clause {
|
||||
impl #impl_generics crate::values::computed::ToComputedValue for #name #ty_generics #where_clause {
|
||||
type ComputedValue = #computed_value_type;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &::values::computed::Context) -> Self::ComputedValue {
|
||||
fn to_computed_value(&self, context: &crate::values::computed::Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
#to_body
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ pub fn derive(mut input: syn::DeriveInput) -> Tokens {
|
|||
for param in input.generics.type_params() {
|
||||
cg::add_predicate(
|
||||
&mut where_clause,
|
||||
parse_quote!(#param: ::style_traits::ToCss),
|
||||
parse_quote!(#param: style_traits::ToCss),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -36,15 +36,15 @@ pub fn derive(mut input: syn::DeriveInput) -> Tokens {
|
|||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
let mut impls = quote! {
|
||||
impl #impl_generics ::style_traits::ToCss for #name #ty_generics #where_clause {
|
||||
impl #impl_generics style_traits::ToCss for #name #ty_generics #where_clause {
|
||||
#[allow(unused_variables)]
|
||||
#[inline]
|
||||
fn to_css<W>(
|
||||
&self,
|
||||
dest: &mut ::style_traits::CssWriter<W>,
|
||||
) -> ::std::fmt::Result
|
||||
dest: &mut style_traits::CssWriter<W>,
|
||||
) -> std::fmt::Result
|
||||
where
|
||||
W: ::std::fmt::Write,
|
||||
W: std::fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
#match_body
|
||||
|
@ -55,11 +55,11 @@ pub fn derive(mut input: syn::DeriveInput) -> Tokens {
|
|||
|
||||
if input_attrs.derive_debug {
|
||||
impls.append_all(quote! {
|
||||
impl #impl_generics ::std::fmt::Debug for #name #ty_generics #where_clause {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
::style_traits::ToCss::to_css(
|
||||
impl #impl_generics std::fmt::Debug for #name #ty_generics #where_clause {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
style_traits::ToCss::to_css(
|
||||
self,
|
||||
&mut ::style_traits::CssWriter::new(f),
|
||||
&mut style_traits::CssWriter::new(f),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -90,28 +90,28 @@ fn derive_variant_arm(variant: &VariantInfo, generics: &mut Option<WhereClause>)
|
|||
let mut expr = if let Some(keyword) = variant_attrs.keyword {
|
||||
assert!(bindings.is_empty());
|
||||
quote! {
|
||||
::std::fmt::Write::write_str(dest, #keyword)
|
||||
std::fmt::Write::write_str(dest, #keyword)
|
||||
}
|
||||
} else if !bindings.is_empty() {
|
||||
derive_variant_fields_expr(bindings, generics, separator)
|
||||
} else {
|
||||
quote! {
|
||||
::std::fmt::Write::write_str(dest, #identifier)
|
||||
std::fmt::Write::write_str(dest, #identifier)
|
||||
}
|
||||
};
|
||||
|
||||
if variant_attrs.dimension {
|
||||
expr = quote! {
|
||||
#expr?;
|
||||
::std::fmt::Write::write_str(dest, #identifier)
|
||||
std::fmt::Write::write_str(dest, #identifier)
|
||||
}
|
||||
} else if let Some(function) = variant_attrs.function {
|
||||
let mut identifier = function.explicit().map_or(identifier, |name| name);
|
||||
identifier.push_str("(");
|
||||
expr = quote! {
|
||||
::std::fmt::Write::write_str(dest, #identifier)?;
|
||||
std::fmt::Write::write_str(dest, #identifier)?;
|
||||
#expr?;
|
||||
::std::fmt::Write::write_str(dest, ")")
|
||||
std::fmt::Write::write_str(dest, ")")
|
||||
}
|
||||
}
|
||||
expr
|
||||
|
@ -140,9 +140,9 @@ fn derive_variant_fields_expr(
|
|||
if !attrs.iterable && iter.peek().is_none() {
|
||||
if attrs.field_bound {
|
||||
let ty = &first.ast().ty;
|
||||
cg::add_predicate(where_clause, parse_quote!(#ty: ::style_traits::ToCss));
|
||||
cg::add_predicate(where_clause, parse_quote!(#ty: style_traits::ToCss));
|
||||
}
|
||||
let mut expr = quote! { ::style_traits::ToCss::to_css(#first, dest) };
|
||||
let mut expr = quote! { style_traits::ToCss::to_css(#first, dest) };
|
||||
if let Some(condition) = attrs.skip_if {
|
||||
expr = quote! {
|
||||
if !#condition(#first) {
|
||||
|
@ -159,7 +159,7 @@ fn derive_variant_fields_expr(
|
|||
}
|
||||
|
||||
quote! {{
|
||||
let mut writer = ::style_traits::values::SequenceWriter::new(dest, #separator);
|
||||
let mut writer = style_traits::values::SequenceWriter::new(dest, #separator);
|
||||
#expr
|
||||
Ok(())
|
||||
}}
|
||||
|
@ -205,7 +205,7 @@ fn derive_single_field_expr(
|
|||
} else {
|
||||
if attrs.field_bound {
|
||||
let ty = &field.ast().ty;
|
||||
cg::add_predicate(where_clause, parse_quote!(#ty: ::style_traits::ToCss));
|
||||
cg::add_predicate(where_clause, parse_quote!(#ty: style_traits::ToCss));
|
||||
}
|
||||
quote! { writer.item(#field)?; }
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue