Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare stylo crates for switching to the 2018 edition #22083

Merged
merged 5 commits into from Nov 10, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Use 2018-style paths in code generated by style_derive

  • Loading branch information
SimonSapin committed Nov 10, 2018
commit ede79a6a5db4beacfbf5b2989a4ba9b565f507c1
@@ -16,7 +16,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
if !no_bound.contains(&param.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(&param.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,32 +12,32 @@ 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;
let name = &input.ident;
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(&param.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 &params {
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,
&params,
&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,40 +55,40 @@ 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;

#[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)
}
}
};
}

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
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.