From 669ca3e75745702c4c95a3d50200af0467db0acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:03:20 +0900 Subject: [PATCH 01/28] define trait --- src/traits.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/traits.rs b/src/traits.rs index 81f62760..aa1abdf8 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -10,6 +10,12 @@ use crate::targets::{Browsers, Targets}; use crate::vendor_prefix::VendorPrefix; use cssparser::*; +/// A trait for things that can be cloned with a new lifetime. +pub trait IntoOwned { + /// Make lifetime of `self` `'static`. + fn into_owned(self) -> Self; +} + /// Trait for things that can be parsed from CSS syntax. pub trait Parse<'i>: Sized { /// Parse a value of this type using an existing parser. From 308f1fa23b86ee5e5eec77a6c865eec663782ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:04:42 +0900 Subject: [PATCH 02/28] trivial impls --- src/traits.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/traits.rs b/src/traits.rs index aa1abdf8..4b0057bf 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -16,6 +16,22 @@ pub trait IntoOwned { fn into_owned(self) -> Self; } +macro_rules! impl_into_owned { + ($t: ty) => { + impl<'i> IntoOwned for $t { + #[inline] + fn into_owned(self) -> Self { + self + } + } + }; + ($($t:ty),*) => { + $(impl_into_owned!($t);)* + }; +} + +impl_into_owned!(bool, f32, f64, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize); + /// Trait for things that can be parsed from CSS syntax. pub trait Parse<'i>: Sized { /// Parse a value of this type using an existing parser. From f705407304f6cefb6c1191bdae3bdcf4545305ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:07:43 +0900 Subject: [PATCH 03/28] Patch derive --- derive/src/into_owned.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 4da1bc10..6c452c13 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -112,9 +112,10 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { } else { let params = generics.type_params(); quote! { - impl #impl_generics #self_name #ty_generics #where_clause { + impl #impl_generics lightningcss::traits::IntoOwned for #self_name #ty_generics #where_clause { + type Owned = #self_name<'staitc, #(#params),*>; /// Consumes the value and returns an owned clone. - pub fn into_owned<'x>(self) -> #self_name<'x, #(#params),*> { + fn into_owned(self) -> Self::Owned { #res } } From bc2436e12c32262ed24620316bf53957d38f5b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:07:46 +0900 Subject: [PATCH 04/28] trait def --- src/traits.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/traits.rs b/src/traits.rs index 4b0057bf..11329e1b 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -12,8 +12,10 @@ use cssparser::*; /// A trait for things that can be cloned with a new lifetime. pub trait IntoOwned { + type Owned: 'static; + /// Make lifetime of `self` `'static`. - fn into_owned(self) -> Self; + fn into_owned(self) -> Self::Owned; } macro_rules! impl_into_owned { From f49fe6996197d5434268092b1acfb883eaedbef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:08:44 +0900 Subject: [PATCH 05/28] Typo --- derive/src/into_owned.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 6c452c13..05c656bd 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -113,7 +113,7 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { let params = generics.type_params(); quote! { impl #impl_generics lightningcss::traits::IntoOwned for #self_name #ty_generics #where_clause { - type Owned = #self_name<'staitc, #(#params),*>; + type Owned = #self_name<'static, #(#params),*>; /// Consumes the value and returns an owned clone. fn into_owned(self) -> Self::Owned { #res From 45eecc93b3f89d0b557b51de9c4ed8b7a9b0f675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:11:38 +0900 Subject: [PATCH 06/28] fake module --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9d0338e5..ab0c8dbb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,10 @@ pub mod visitor; #[cfg(feature = "serde")] mod serialization; +/// hack for derive +mod lightningcss { + pub use crate::traits; +} #[cfg(test)] mod tests { From c8b13b438ecaada36d05a42d7b37d74e78f0ffaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:18:09 +0900 Subject: [PATCH 07/28] use crate::lightningcss; --- src/declaration.rs | 1 + src/error.rs | 1 + src/lib.rs | 1 + src/media_query.rs | 2 +- src/properties/animation.rs | 1 + src/properties/background.rs | 1 + src/properties/border_image.rs | 1 + src/properties/contain.rs | 1 + src/properties/css_modules.rs | 1 + src/properties/custom.rs | 1 + src/properties/effects.rs | 1 + src/properties/font.rs | 1 + src/properties/grid.rs | 1 + src/properties/list.rs | 1 + src/properties/masking.rs | 1 + src/properties/mod.rs | 1 + src/properties/svg.rs | 1 + src/properties/text.rs | 1 + src/properties/transition.rs | 1 + src/properties/ui.rs | 1 + src/rules/container.rs | 1 + src/rules/counter_style.rs | 1 + src/rules/custom_media.rs | 1 + src/rules/font_face.rs | 1 + src/rules/font_palette_values.rs | 1 + src/rules/import.rs | 1 + src/rules/keyframes.rs | 1 + src/rules/layer.rs | 1 + src/rules/namespace.rs | 1 + src/rules/page.rs | 1 + src/rules/property.rs | 1 + src/rules/supports.rs | 1 + src/rules/unknown.rs | 1 + src/rules/viewport.rs | 1 + src/stylesheet.rs | 1 + src/values/ident.rs | 1 + src/values/image.rs | 1 + src/values/string.rs | 1 + src/values/syntax.rs | 1 + src/values/url.rs | 1 + 40 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/declaration.rs b/src/declaration.rs index dd2283f3..6d2140b8 100644 --- a/src/declaration.rs +++ b/src/declaration.rs @@ -5,6 +5,7 @@ use std::ops::Range; use crate::context::PropertyHandlerContext; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::parser::ParserOptions; use crate::printer::Printer; use crate::properties::box_shadow::BoxShadowHandler; diff --git a/src/error.rs b/src/error.rs index 274a5cae..e1f5e3f4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ //! Error types. +use crate::lightningcss; use crate::properties::custom::Token; use crate::rules::Location; use crate::values::string::CowArcStr; diff --git a/src/lib.rs b/src/lib.rs index ab0c8dbb..f6ef5176 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,7 @@ pub mod visitor; #[cfg(feature = "serde")] mod serialization; + /// hack for derive mod lightningcss { pub use crate::traits; diff --git a/src/media_query.rs b/src/media_query.rs index f6921c61..da0d6711 100644 --- a/src/media_query.rs +++ b/src/media_query.rs @@ -1,6 +1,6 @@ //! Media queries. - use crate::error::{ErrorWithLocation, MinifyError, MinifyErrorKind, ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::enum_property; use crate::parser::starts_with_ignore_ascii_case; use crate::printer::Printer; diff --git a/src/properties/animation.rs b/src/properties/animation.rs index 169c2b9d..a5a8999d 100644 --- a/src/properties/animation.rs +++ b/src/properties/animation.rs @@ -3,6 +3,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::*; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/background.rs b/src/properties/background.rs index 873247ff..9916696c 100644 --- a/src/properties/background.rs +++ b/src/properties/background.rs @@ -3,6 +3,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::*; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/border_image.rs b/src/properties/border_image.rs index 973f0375..d789be22 100644 --- a/src/properties/border_image.rs +++ b/src/properties/border_image.rs @@ -3,6 +3,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::prefixes::Feature; use crate::printer::Printer; use crate::properties::{Property, PropertyId, VendorPrefix}; diff --git a/src/properties/contain.rs b/src/properties/contain.rs index 05fdc032..4d48332f 100644 --- a/src/properties/contain.rs +++ b/src/properties/contain.rs @@ -2,6 +2,7 @@ #![allow(non_upper_case_globals)] +use crate::lightningcss; use cssparser::*; use smallvec::SmallVec; diff --git a/src/properties/css_modules.rs b/src/properties/css_modules.rs index e4a21172..ab961d26 100644 --- a/src/properties/css_modules.rs +++ b/src/properties/css_modules.rs @@ -2,6 +2,7 @@ use crate::dependencies::Location; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; use crate::values::ident::{CustomIdent, CustomIdentList}; diff --git a/src/properties/custom.rs b/src/properties/custom.rs index 42a2f3b9..fc569d9f 100644 --- a/src/properties/custom.rs +++ b/src/properties/custom.rs @@ -1,6 +1,7 @@ //! CSS custom properties and unparsed token values. use crate::error::{ParserError, PrinterError, PrinterErrorKind}; +use crate::lightningcss; use crate::macros::enum_property; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/effects.rs b/src/properties/effects.rs index 20b2ee2e..80940798 100644 --- a/src/properties/effects.rs +++ b/src/properties/effects.rs @@ -1,6 +1,7 @@ //! CSS properties related to filters and effects. use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; use crate::traits::{FallbackValues, IsCompatible, Parse, ToCss, Zero}; diff --git a/src/properties/font.rs b/src/properties/font.rs index 3a81486f..c782625a 100644 --- a/src/properties/font.rs +++ b/src/properties/font.rs @@ -7,6 +7,7 @@ use crate::compat::Feature; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::*; use crate::printer::Printer; use crate::targets::should_compile; diff --git a/src/properties/grid.rs b/src/properties/grid.rs index 6c783b85..18eb765b 100644 --- a/src/properties/grid.rs +++ b/src/properties/grid.rs @@ -5,6 +5,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{Error, ErrorLocation, ParserError, PrinterError, PrinterErrorKind}; +use crate::lightningcss; use crate::macros::{define_shorthand, impl_shorthand}; use crate::printer::Printer; use crate::properties::{Property, PropertyId}; diff --git a/src/properties/list.rs b/src/properties/list.rs index b37bc0ab..1f05cef5 100644 --- a/src/properties/list.rs +++ b/src/properties/list.rs @@ -4,6 +4,7 @@ use super::{Property, PropertyId}; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::{define_shorthand, enum_property, shorthand_handler, shorthand_property}; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; diff --git a/src/properties/masking.rs b/src/properties/masking.rs index 5a91c56c..46829b73 100644 --- a/src/properties/masking.rs +++ b/src/properties/masking.rs @@ -6,6 +6,7 @@ use super::PropertyId; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::{define_list_shorthand, define_shorthand, enum_property, property_bitflags}; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/mod.rs b/src/properties/mod.rs index 9a060f32..a40688b4 100644 --- a/src/properties/mod.rs +++ b/src/properties/mod.rs @@ -122,6 +122,7 @@ pub mod ui; use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::logical::{LogicalGroup, PropertyCategory}; use crate::parser::starts_with_ignore_ascii_case; use crate::parser::ParserOptions; diff --git a/src/properties/svg.rs b/src/properties/svg.rs index aa471250..371ef808 100644 --- a/src/properties/svg.rs +++ b/src/properties/svg.rs @@ -1,6 +1,7 @@ //! CSS properties used in SVG. use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; diff --git a/src/properties/text.rs b/src/properties/text.rs index 92cdae79..350d77fa 100644 --- a/src/properties/text.rs +++ b/src/properties/text.rs @@ -7,6 +7,7 @@ use crate::compat; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::{define_shorthand, enum_property}; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/transition.rs b/src/properties/transition.rs index fd296a64..bf7222f4 100644 --- a/src/properties/transition.rs +++ b/src/properties/transition.rs @@ -5,6 +5,7 @@ use crate::compat; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::define_list_shorthand; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/ui.rs b/src/properties/ui.rs index 2fe83a04..831a99ff 100644 --- a/src/properties/ui.rs +++ b/src/properties/ui.rs @@ -2,6 +2,7 @@ use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::{define_shorthand, enum_property, shorthand_property}; use crate::printer::Printer; use crate::properties::{Property, PropertyId}; diff --git a/src/rules/container.rs b/src/rules/container.rs index 7529930e..0273034d 100644 --- a/src/rules/container.rs +++ b/src/rules/container.rs @@ -5,6 +5,7 @@ use cssparser::*; use super::Location; use super::{CssRuleList, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; +use crate::lightningcss; use crate::media_query::{ define_query_features, operation_to_css, parse_query_condition, to_css_with_parens_if_needed, FeatureToCss, MediaFeatureType, Operator, QueryCondition, QueryConditionFlags, QueryFeature, ValueType, diff --git a/src/rules/counter_style.rs b/src/rules/counter_style.rs index 50602807..d3b2c192 100644 --- a/src/rules/counter_style.rs +++ b/src/rules/counter_style.rs @@ -3,6 +3,7 @@ use super::Location; use crate::declaration::DeclarationBlock; use crate::error::PrinterError; +use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; use crate::values::ident::CustomIdent; diff --git a/src/rules/custom_media.rs b/src/rules/custom_media.rs index 322a1847..05940bac 100644 --- a/src/rules/custom_media.rs +++ b/src/rules/custom_media.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::PrinterError; +use crate::lightningcss; use crate::media_query::MediaList; use crate::printer::Printer; use crate::traits::ToCss; diff --git a/src/rules/font_face.rs b/src/rules/font_face.rs index df827e8f..b1202772 100644 --- a/src/rules/font_face.rs +++ b/src/rules/font_face.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; use crate::properties::custom::CustomProperty; diff --git a/src/rules/font_palette_values.rs b/src/rules/font_palette_values.rs index 08ea5417..88c394a7 100644 --- a/src/rules/font_palette_values.rs +++ b/src/rules/font_palette_values.rs @@ -3,6 +3,7 @@ use super::supports::SupportsRule; use super::{CssRule, CssRuleList, Location, MinifyContext}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::printer::Printer; use crate::properties::custom::CustomProperty; use crate::properties::font::FontFamily; diff --git a/src/rules/import.rs b/src/rules/import.rs index 9329fe9f..dea09ace 100644 --- a/src/rules/import.rs +++ b/src/rules/import.rs @@ -5,6 +5,7 @@ use super::supports::SupportsCondition; use super::Location; use crate::dependencies::{Dependency, ImportDependency}; use crate::error::PrinterError; +use crate::lightningcss; use crate::media_query::MediaList; use crate::printer::Printer; use crate::traits::ToCss; diff --git a/src/rules/keyframes.rs b/src/rules/keyframes.rs index 8e11218e..4ae40fb3 100644 --- a/src/rules/keyframes.rs +++ b/src/rules/keyframes.rs @@ -6,6 +6,7 @@ use super::{CssRule, CssRuleList, Location}; use crate::context::DeclarationContext; use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::parser::ParserOptions; use crate::printer::Printer; use crate::properties::custom::{CustomProperty, UnparsedProperty}; diff --git a/src/rules/layer.rs b/src/rules/layer.rs index eaa04c86..70933241 100644 --- a/src/rules/layer.rs +++ b/src/rules/layer.rs @@ -2,6 +2,7 @@ use super::{CssRuleList, Location, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; +use crate::lightningcss; use crate::parser::DefaultAtRule; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; diff --git a/src/rules/namespace.rs b/src/rules/namespace.rs index f70cd6fb..2f807293 100644 --- a/src/rules/namespace.rs +++ b/src/rules/namespace.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::PrinterError; +use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; use crate::values::ident::Ident; diff --git a/src/rules/page.rs b/src/rules/page.rs index e3a03cae..f4aa94ce 100644 --- a/src/rules/page.rs +++ b/src/rules/page.rs @@ -3,6 +3,7 @@ use super::Location; use crate::declaration::{parse_declaration, DeclarationBlock}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; use crate::stylesheet::ParserOptions; diff --git a/src/rules/property.rs b/src/rules/property.rs index 97d2e82b..87baaaee 100644 --- a/src/rules/property.rs +++ b/src/rules/property.rs @@ -1,6 +1,7 @@ //! The `@property` rule. use super::Location; +use crate::lightningcss; #[cfg(feature = "visitor")] use crate::visitor::Visit; use crate::{ diff --git a/src/rules/supports.rs b/src/rules/supports.rs index f16a4f0c..0cf42e95 100644 --- a/src/rules/supports.rs +++ b/src/rules/supports.rs @@ -3,6 +3,7 @@ use super::Location; use super::{CssRuleList, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; +use crate::lightningcss; use crate::parser::DefaultAtRule; use crate::printer::Printer; use crate::properties::PropertyId; diff --git a/src/rules/unknown.rs b/src/rules/unknown.rs index 492d4c52..c1822589 100644 --- a/src/rules/unknown.rs +++ b/src/rules/unknown.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::PrinterError; +use crate::lightningcss; use crate::printer::Printer; use crate::properties::custom::TokenList; use crate::traits::ToCss; diff --git a/src/rules/viewport.rs b/src/rules/viewport.rs index 531de878..21ff0043 100644 --- a/src/rules/viewport.rs +++ b/src/rules/viewport.rs @@ -3,6 +3,7 @@ use super::Location; use crate::declaration::DeclarationBlock; use crate::error::PrinterError; +use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; use crate::vendor_prefix::VendorPrefix; diff --git a/src/stylesheet.rs b/src/stylesheet.rs index ebd0a9f0..0ad3808f 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -8,6 +8,7 @@ use crate::css_modules::{CssModule, CssModuleExports, CssModuleReferences}; use crate::declaration::{DeclarationBlock, DeclarationHandler}; use crate::dependencies::Dependency; use crate::error::{Error, ErrorLocation, MinifyErrorKind, ParserError, PrinterError, PrinterErrorKind}; +use crate::lightningcss; use crate::parser::{DefaultAtRule, DefaultAtRuleParser, TopLevelRuleParser}; use crate::printer::Printer; use crate::rules::{CssRule, CssRuleList, MinifyContext}; diff --git a/src/values/ident.rs b/src/values/ident.rs index 5b775e98..ed0e718e 100644 --- a/src/values/ident.rs +++ b/src/values/ident.rs @@ -1,6 +1,7 @@ //! CSS identifiers. use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::printer::Printer; use crate::properties::css_modules::Specifier; use crate::traits::{Parse, ParseWithOptions, ToCss}; diff --git a/src/values/image.rs b/src/values/image.rs index 756b3d4c..becf6a1e 100644 --- a/src/values/image.rs +++ b/src/values/image.rs @@ -6,6 +6,7 @@ use super::resolution::Resolution; use crate::compat; use crate::dependencies::{Dependency, UrlDependency}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::prefixes::{is_webkit_gradient, Feature}; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; diff --git a/src/values/string.rs b/src/values/string.rs index b0cb5de3..78e7bb97 100644 --- a/src/values/string.rs +++ b/src/values/string.rs @@ -1,5 +1,6 @@ //! Types used to represent strings. +use crate::lightningcss; use crate::traits::{Parse, ToCss}; #[cfg(feature = "visitor")] use crate::visitor::{Visit, VisitTypes, Visitor}; diff --git a/src/values/syntax.rs b/src/values/syntax.rs index 94b8429e..662fd05c 100644 --- a/src/values/syntax.rs +++ b/src/values/syntax.rs @@ -3,6 +3,7 @@ use super::ident::Ident; use super::number::{CSSInteger, CSSNumber}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; use crate::values; diff --git a/src/values/url.rs b/src/values/url.rs index eaf37bfe..badb8166 100644 --- a/src/values/url.rs +++ b/src/values/url.rs @@ -2,6 +2,7 @@ use crate::dependencies::{Dependency, Location, UrlDependency}; use crate::error::{ParserError, PrinterError}; +use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; use crate::values::string::CowArcStr; From f7e27a704a7d97245d34cf60dc7f5050e8fd5c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:19:11 +0900 Subject: [PATCH 08/28] use trait --- derive/src/into_owned.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 05c656bd..23ed00f7 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -116,6 +116,8 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { type Owned = #self_name<'static, #(#params),*>; /// Consumes the value and returns an owned clone. fn into_owned(self) -> Self::Owned { + use lightningcss::traits::IntoOwned; + #res } } From 4c7254077f799382d5c1c57ea9bb6f2bbbf7b7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:20:46 +0900 Subject: [PATCH 09/28] More --- src/values/string.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/values/string.rs b/src/values/string.rs index 78e7bb97..4368ccc5 100644 --- a/src/values/string.rs +++ b/src/values/string.rs @@ -1,7 +1,7 @@ //! Types used to represent strings. use crate::lightningcss; -use crate::traits::{Parse, ToCss}; +use crate::traits::{IntoOwned, Parse, ToCss}; #[cfg(feature = "visitor")] use crate::visitor::{Visit, VisitTypes, Visitor}; use cssparser::{serialize_string, CowRcStr}; @@ -130,9 +130,13 @@ impl<'a> CowArcStr<'a> { } } } +} + +impl IntoOwned for CowArcStr<'_> { + type Owned = CowArcStr<'static>; /// Consumes the value and returns an owned clone. - pub fn into_owned<'x>(self) -> CowArcStr<'x> { + fn into_owned(self) -> Self::Owned { if self.borrowed_len_or_max != usize::MAX { CowArcStr::from(self.as_ref().to_owned()) } else { From bc87127ef07512ca97543c712b9adb7734a10e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:21:40 +0900 Subject: [PATCH 10/28] #[cfg(feature = "into_owned")] --- src/traits.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/traits.rs b/src/traits.rs index 11329e1b..efe2904c 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -11,6 +11,7 @@ use crate::vendor_prefix::VendorPrefix; use cssparser::*; /// A trait for things that can be cloned with a new lifetime. +#[cfg(feature = "into_owned")] pub trait IntoOwned { type Owned: 'static; From a399e6c934adaa25116da44ce2b3d61b6fd3bd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:22:12 +0900 Subject: [PATCH 11/28] Fix trivial impls --- src/media_query.rs | 3 +++ src/traits.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/media_query.rs b/src/media_query.rs index da0d6711..16169eb9 100644 --- a/src/media_query.rs +++ b/src/media_query.rs @@ -1,5 +1,6 @@ //! Media queries. use crate::error::{ErrorWithLocation, MinifyError, MinifyErrorKind, ParserError, PrinterError}; +#[cfg(feature = "into_owned")] use crate::lightningcss; use crate::macros::enum_property; use crate::parser::starts_with_ignore_ascii_case; @@ -11,6 +12,8 @@ use crate::rules::custom_media::CustomMediaRule; use crate::rules::Location; use crate::stylesheet::ParserOptions; use crate::targets::{should_compile, Targets}; +#[cfg(feature = "into_owned")] +use crate::traits::IntoOwned; use crate::traits::{Parse, ToCss}; use crate::values::ident::{DashedIdent, Ident}; use crate::values::number::{CSSInteger, CSSNumber}; diff --git a/src/traits.rs b/src/traits.rs index efe2904c..96091cce 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -19,9 +19,12 @@ pub trait IntoOwned { fn into_owned(self) -> Self::Owned; } +#[cfg(feature = "into_owned")] macro_rules! impl_into_owned { ($t: ty) => { impl<'i> IntoOwned for $t { + type Owned = Self; + #[inline] fn into_owned(self) -> Self { self @@ -33,6 +36,7 @@ macro_rules! impl_into_owned { }; } +#[cfg(feature = "into_owned")] impl_into_owned!(bool, f32, f64, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize); /// Trait for things that can be parsed from CSS syntax. From e7346e5d159d8d01e45767d973eb851b4cc77ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:23:10 +0900 Subject: [PATCH 12/28] use --- src/properties/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/properties/mod.rs b/src/properties/mod.rs index a40688b4..3820d774 100644 --- a/src/properties/mod.rs +++ b/src/properties/mod.rs @@ -129,6 +129,8 @@ use crate::parser::ParserOptions; use crate::prefixes::Feature; use crate::printer::{Printer, PrinterOptions}; use crate::targets::Targets; +#[cfg(feature = "into_owned")] +use crate::traits::IntoOwned; use crate::traits::{Parse, ParseWithOptions, Shorthand, ToCss}; use crate::values::number::{CSSInteger, CSSNumber}; use crate::values::string::CowArcStr; From 5fcd76b2822cb7c94aa7d6aec8ece3a1d206530c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:27:44 +0900 Subject: [PATCH 13/28] generic bound for type parameters --- derive/src/into_owned.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 23ed00f7..50881707 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -2,15 +2,15 @@ use proc_macro::{self, TokenStream}; use proc_macro2::Span; use quote::quote; use syn::{ - parse_macro_input, Data, DataEnum, DeriveInput, Field, Fields, GenericArgument, Ident, Member, PathArguments, - Type, + parse_macro_input, parse_quote, Data, DataEnum, DeriveInput, Field, Fields, GenericArgument, Ident, Member, + PathArguments, Type, }; pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { let DeriveInput { ident: self_name, data, - generics, + mut generics, .. } = parse_macro_input!(input); @@ -105,6 +105,19 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { } }; + // Add generic bounds for all type parameters. + let mut type_param_names = vec![]; + + for ty in generics.type_params() { + type_param_names.push(ty.ident.clone()); + } + + for type_param in type_param_names { + generics.make_where_clause().predicates.push_value(parse_quote! { + #type_param: lightningcss::traits::IntoOwned + }) + } + let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let into_owned = if generics.lifetimes().next().is_none() { From 84ec65eb0b2fd26652a70c90c9dedc163fe299b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:28:34 +0900 Subject: [PATCH 14/28] Add `'static` --- derive/src/into_owned.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 50881707..bedf9ec9 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -114,7 +114,7 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { for type_param in type_param_names { generics.make_where_clause().predicates.push_value(parse_quote! { - #type_param: lightningcss::traits::IntoOwned + #type_param: 'static + lightningcss::traits::IntoOwned }) } From ad3c09f03e57f55899c695938e7eb66def50225e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:29:14 +0900 Subject: [PATCH 15/28] More import --- src/error.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/error.rs b/src/error.rs index e1f5e3f4..9c21bd02 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,8 @@ use crate::lightningcss; use crate::properties::custom::Token; use crate::rules::Location; +#[cfg(feature = "into_owned")] +use crate::traits::IntoOwned; use crate::values::string::CowArcStr; use cssparser::{BasicParseErrorKind, ParseError, ParseErrorKind}; use parcel_selectors::parser::SelectorParseErrorKind; From 69ea0f6cfafbc04ed9ac07d0fc9f76c0eabbe24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:34:42 +0900 Subject: [PATCH 16/28] Patch derive to support more --- derive/src/into_owned.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index bedf9ec9..b131e418 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -121,7 +121,16 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let into_owned = if generics.lifetimes().next().is_none() { - panic!("can't derive IntoOwned on a type without any lifetimes") + quote! { + impl #impl_generics lightningcss::traits::IntoOwned for #self_name #ty_generics #where_clause { + type Owned = Self; + + #[inline] + fn into_owned(self) -> Self { + self + } + } + } } else { let params = generics.type_params(); quote! { From 3e672546fdd67dae63cfeb00fa83b693ea293663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:34:48 +0900 Subject: [PATCH 17/28] derive --- src/media_query.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/media_query.rs b/src/media_query.rs index 16169eb9..61358350 100644 --- a/src/media_query.rs +++ b/src/media_query.rs @@ -1260,6 +1260,7 @@ macro_rules! define_query_features { pub(crate) use define_query_features; define_query_features! { + #[cfg_attr(feature = "into_owned", derive(lightningcss_derive::IntoOwned))] /// A media query feature identifier. pub enum MediaFeatureId { /// The [width](https://w3c.github.io/csswg-drafts/mediaqueries-5/#width) media feature. From abaddb600775364b0ecbea279b36fa2e5e23b19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 14:35:27 +0900 Subject: [PATCH 18/28] more derive --- src/rules/container.rs | 1 + src/traits.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rules/container.rs b/src/rules/container.rs index 0273034d..670527e4 100644 --- a/src/rules/container.rs +++ b/src/rules/container.rs @@ -75,6 +75,7 @@ pub type ContainerSizeFeature<'i> = QueryFeature<'i, ContainerSizeFeatureId>; define_query_features! { /// A container query size feature identifier. + #[cfg_attr(feature = "into_owned", derive(lightningcss_derive::IntoOwned))] pub enum ContainerSizeFeatureId { /// The [width](https://w3c.github.io/csswg-drafts/css-contain-3/#width) size container feature. "width": Width = Length, diff --git a/src/traits.rs b/src/traits.rs index 96091cce..96434a97 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -22,7 +22,7 @@ pub trait IntoOwned { #[cfg(feature = "into_owned")] macro_rules! impl_into_owned { ($t: ty) => { - impl<'i> IntoOwned for $t { + impl IntoOwned for $t { type Owned = Self; #[inline] From c1fa878736c7aab4083fcd6c0c74bab61e58c651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:05:16 +0900 Subject: [PATCH 19/28] `'any` from derive --- derive/src/into_owned.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index b131e418..b3ace102 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -2,8 +2,8 @@ use proc_macro::{self, TokenStream}; use proc_macro2::Span; use quote::quote; use syn::{ - parse_macro_input, parse_quote, Data, DataEnum, DeriveInput, Field, Fields, GenericArgument, Ident, Member, - PathArguments, Type, + parse_macro_input, parse_quote, Data, DataEnum, DeriveInput, Field, Fields, GenericArgument, Generics, Ident, + Member, PathArguments, Type, }; pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { @@ -118,11 +118,25 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { }) } + // Prepend `'any` to generics + generics.params.insert( + 0, + syn::GenericParam::Lifetime(syn::LifetimeDef { + attrs: Default::default(), + lifetime: syn::Lifetime { + apostrophe: Span::call_site(), + ident: Ident::new("any", Span::call_site()), + }, + colon_token: None, + bounds: Default::default(), + }), + ); + let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let into_owned = if generics.lifetimes().next().is_none() { quote! { - impl #impl_generics lightningcss::traits::IntoOwned for #self_name #ty_generics #where_clause { + impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { type Owned = Self; #[inline] @@ -134,8 +148,8 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { } else { let params = generics.type_params(); quote! { - impl #impl_generics lightningcss::traits::IntoOwned for #self_name #ty_generics #where_clause { - type Owned = #self_name<'static, #(#params),*>; + impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { + type Owned = #self_name<'any, #(#params),*>; /// Consumes the value and returns an owned clone. fn into_owned(self) -> Self::Owned { use lightningcss::traits::IntoOwned; From 209df83541fc6df544bba6563532fc006052425d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:07:54 +0900 Subject: [PATCH 20/28] Rename existing type param --- derive/src/into_owned.rs | 32 ++++++++++++++++++++------------ src/traits.rs | 8 +++++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index b3ace102..61ceb828 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -1,3 +1,5 @@ +use std::f32::consts::E; + use proc_macro::{self, TokenStream}; use proc_macro2::Span; use quote::quote; @@ -119,18 +121,24 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { } // Prepend `'any` to generics - generics.params.insert( - 0, - syn::GenericParam::Lifetime(syn::LifetimeDef { - attrs: Default::default(), - lifetime: syn::Lifetime { - apostrophe: Span::call_site(), - ident: Ident::new("any", Span::call_site()), - }, - colon_token: None, - bounds: Default::default(), - }), - ); + let any = syn::GenericParam::Lifetime(syn::LifetimeDef { + attrs: Default::default(), + lifetime: syn::Lifetime { + apostrophe: Span::call_site(), + ident: Ident::new("any", Span::call_site()), + }, + colon_token: None, + bounds: Default::default(), + }); + if generics + .params + .first() + .map_or(true, |v| !matches!(v, syn::GenericParam::Lifetime(..))) + { + generics.params.insert(0, any.clone()); + } else { + generics.params[0] = any; + } let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); diff --git a/src/traits.rs b/src/traits.rs index 96434a97..469a7f1d 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -11,9 +11,11 @@ use crate::vendor_prefix::VendorPrefix; use cssparser::*; /// A trait for things that can be cloned with a new lifetime. +/// +/// `'any` lifeitme means the output should have `'static` lifetime. #[cfg(feature = "into_owned")] -pub trait IntoOwned { - type Owned: 'static; +pub trait IntoOwned<'any> { + type Owned: 'any; /// Make lifetime of `self` `'static`. fn into_owned(self) -> Self::Owned; @@ -22,7 +24,7 @@ pub trait IntoOwned { #[cfg(feature = "into_owned")] macro_rules! impl_into_owned { ($t: ty) => { - impl IntoOwned for $t { + impl<'a> IntoOwned<'a> for $t { type Owned = Self; #[inline] From de064a2dffb200893ff6b85d64ba7232e2c43cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:08:48 +0900 Subject: [PATCH 21/28] for <'aa> --- derive/src/into_owned.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 61ceb828..510781d6 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -1,11 +1,9 @@ -use std::f32::consts::E; - use proc_macro::{self, TokenStream}; use proc_macro2::Span; use quote::quote; use syn::{ - parse_macro_input, parse_quote, Data, DataEnum, DeriveInput, Field, Fields, GenericArgument, Generics, Ident, - Member, PathArguments, Type, + parse_macro_input, parse_quote, Data, DataEnum, DeriveInput, Field, Fields, GenericArgument, Ident, Member, + PathArguments, Type, }; pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { @@ -116,7 +114,7 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { for type_param in type_param_names { generics.make_where_clause().predicates.push_value(parse_quote! { - #type_param: 'static + lightningcss::traits::IntoOwned + #type_param: 'static + for<'aa> lightningcss::traits::IntoOwned<'aa> }) } From abcd3b7e264c656e02938f0caacceeb0f3e264e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:10:46 +0900 Subject: [PATCH 22/28] done? --- derive/src/into_owned.rs | 15 ++++++++------- src/values/string.rs | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 510781d6..5eb1eac3 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -118,6 +118,11 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { }) } + let has_lifetime = generics + .params + .first() + .map_or(false, |v| matches!(v, syn::GenericParam::Lifetime(..))); + // Prepend `'any` to generics let any = syn::GenericParam::Lifetime(syn::LifetimeDef { attrs: Default::default(), @@ -128,11 +133,7 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { colon_token: None, bounds: Default::default(), }); - if generics - .params - .first() - .map_or(true, |v| !matches!(v, syn::GenericParam::Lifetime(..))) - { + if !has_lifetime { generics.params.insert(0, any.clone()); } else { generics.params[0] = any; @@ -140,9 +141,9 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); - let into_owned = if generics.lifetimes().next().is_none() { + let into_owned = if !has_lifetime { quote! { - impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { + impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #where_clause { type Owned = Self; #[inline] diff --git a/src/values/string.rs b/src/values/string.rs index 4368ccc5..0cce3571 100644 --- a/src/values/string.rs +++ b/src/values/string.rs @@ -132,8 +132,8 @@ impl<'a> CowArcStr<'a> { } } -impl IntoOwned for CowArcStr<'_> { - type Owned = CowArcStr<'static>; +impl<'any> IntoOwned<'any> for CowArcStr<'_> { + type Owned = CowArcStr<'any>; /// Consumes the value and returns an owned clone. fn into_owned(self) -> Self::Owned { From 17a0db56035427d72260d291c92377b102ce5dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:14:05 +0900 Subject: [PATCH 23/28] fix derive --- derive/src/into_owned.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 5eb1eac3..1e923672 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -105,6 +105,8 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { } }; + let orig_generics = generics.clone(); + // Add generic bounds for all type parameters. let mut type_param_names = vec![]; @@ -142,8 +144,9 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let into_owned = if !has_lifetime { + let (_, ty_generics, _) = orig_generics.split_for_impl(); quote! { - impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #where_clause { + impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { type Owned = Self; #[inline] From b7fc5afa0ead03cee1b47602dc5cea1f433ccde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:22:33 +0900 Subject: [PATCH 24/28] done --- derive/src/into_owned.rs | 10 +++------- src/traits.rs | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index 1e923672..b686e438 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -135,16 +135,12 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { colon_token: None, bounds: Default::default(), }); - if !has_lifetime { - generics.params.insert(0, any.clone()); - } else { - generics.params[0] = any; - } + generics.params.insert(0, any.clone()); - let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); + let (impl_generics, _, where_clause) = generics.split_for_impl(); + let (_, ty_generics, _) = orig_generics.split_for_impl(); let into_owned = if !has_lifetime { - let (_, ty_generics, _) = orig_generics.split_for_impl(); quote! { impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { type Owned = Self; diff --git a/src/traits.rs b/src/traits.rs index 469a7f1d..d3cac881 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -15,6 +15,7 @@ use cssparser::*; /// `'any` lifeitme means the output should have `'static` lifetime. #[cfg(feature = "into_owned")] pub trait IntoOwned<'any> { + /// A variant of `Self` with a new lifetime. type Owned: 'any; /// Make lifetime of `self` `'static`. From 5dbb9357a09958894d9ad2e328297e739c6b0072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:23:55 +0900 Subject: [PATCH 25/28] fix --- node/src/transformer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/node/src/transformer.rs b/node/src/transformer.rs index 3480d2dd..6873b502 100644 --- a/node/src/transformer.rs +++ b/node/src/transformer.rs @@ -3,6 +3,7 @@ use std::{ ops::{Index, IndexMut}, }; +use lightningcss::traits::IntoOwned; use lightningcss::{ media_query::MediaFeatureValue, properties::{ From 03476dccd11af4b2826f1772417230d4d3175a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:29:54 +0900 Subject: [PATCH 26/28] Add `use` --- src/properties/custom.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/properties/custom.rs b/src/properties/custom.rs index fc569d9f..c6600488 100644 --- a/src/properties/custom.rs +++ b/src/properties/custom.rs @@ -181,6 +181,7 @@ impl<'i> UnparsedProperty<'i> { ) -> Result, ()> { use super::Property; use crate::stylesheet::PrinterOptions; + use crate::traits::IntoOwned; // Substitute variables in the token list. self.value.substitute_variables(vars); From 8f7ada0156f0d0858a38e5d27c269afb1adc1877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 6 Oct 2023 15:51:55 +0900 Subject: [PATCH 27/28] doctest seems buggy --- src/declaration.rs | 1 + src/error.rs | 1 + src/media_query.rs | 1 + src/properties/animation.rs | 1 + src/properties/background.rs | 1 + src/properties/border_image.rs | 1 + src/properties/contain.rs | 1 + src/properties/css_modules.rs | 1 + src/properties/custom.rs | 1 + src/properties/effects.rs | 1 + src/properties/font.rs | 1 + src/properties/grid.rs | 1 + src/properties/list.rs | 1 + src/properties/masking.rs | 1 + src/properties/mod.rs | 1 + src/properties/svg.rs | 1 + src/properties/text.rs | 1 + src/properties/transition.rs | 1 + src/properties/ui.rs | 1 + src/rules/container.rs | 1 + src/rules/counter_style.rs | 1 + src/rules/custom_media.rs | 1 + src/rules/font_face.rs | 1 + src/rules/font_palette_values.rs | 1 + src/rules/import.rs | 1 + src/rules/keyframes.rs | 1 + src/rules/layer.rs | 1 + src/rules/namespace.rs | 1 + src/rules/page.rs | 1 + src/rules/property.rs | 1 + src/rules/supports.rs | 1 + src/rules/unknown.rs | 1 + src/rules/viewport.rs | 1 + src/stylesheet.rs | 1 + src/values/ident.rs | 1 + src/values/image.rs | 1 + src/values/string.rs | 1 + src/values/syntax.rs | 1 + src/values/url.rs | 1 + 39 files changed, 39 insertions(+) diff --git a/src/declaration.rs b/src/declaration.rs index 6d2140b8..62605e5f 100644 --- a/src/declaration.rs +++ b/src/declaration.rs @@ -5,6 +5,7 @@ use std::ops::Range; use crate::context::PropertyHandlerContext; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::parser::ParserOptions; use crate::printer::Printer; diff --git a/src/error.rs b/src/error.rs index 9c21bd02..73c2e37a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ //! Error types. +#[cfg(not(doctest))] use crate::lightningcss; use crate::properties::custom::Token; use crate::rules::Location; diff --git a/src/media_query.rs b/src/media_query.rs index 61358350..83a48870 100644 --- a/src/media_query.rs +++ b/src/media_query.rs @@ -1,6 +1,7 @@ //! Media queries. use crate::error::{ErrorWithLocation, MinifyError, MinifyErrorKind, ParserError, PrinterError}; #[cfg(feature = "into_owned")] +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::enum_property; use crate::parser::starts_with_ignore_ascii_case; diff --git a/src/properties/animation.rs b/src/properties/animation.rs index a5a8999d..e36ed53e 100644 --- a/src/properties/animation.rs +++ b/src/properties/animation.rs @@ -3,6 +3,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::*; use crate::prefixes::Feature; diff --git a/src/properties/background.rs b/src/properties/background.rs index 9916696c..47224093 100644 --- a/src/properties/background.rs +++ b/src/properties/background.rs @@ -3,6 +3,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::*; use crate::prefixes::Feature; diff --git a/src/properties/border_image.rs b/src/properties/border_image.rs index d789be22..39834525 100644 --- a/src/properties/border_image.rs +++ b/src/properties/border_image.rs @@ -3,6 +3,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/contain.rs b/src/properties/contain.rs index 4d48332f..e43c76b3 100644 --- a/src/properties/contain.rs +++ b/src/properties/contain.rs @@ -2,6 +2,7 @@ #![allow(non_upper_case_globals)] +#[cfg(not(doctest))] use crate::lightningcss; use cssparser::*; use smallvec::SmallVec; diff --git a/src/properties/css_modules.rs b/src/properties/css_modules.rs index ab961d26..a8cd752b 100644 --- a/src/properties/css_modules.rs +++ b/src/properties/css_modules.rs @@ -2,6 +2,7 @@ use crate::dependencies::Location; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; diff --git a/src/properties/custom.rs b/src/properties/custom.rs index c6600488..447adbbf 100644 --- a/src/properties/custom.rs +++ b/src/properties/custom.rs @@ -1,6 +1,7 @@ //! CSS custom properties and unparsed token values. use crate::error::{ParserError, PrinterError, PrinterErrorKind}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::enum_property; use crate::prefixes::Feature; diff --git a/src/properties/effects.rs b/src/properties/effects.rs index 80940798..f0cc0f1b 100644 --- a/src/properties/effects.rs +++ b/src/properties/effects.rs @@ -1,6 +1,7 @@ //! CSS properties related to filters and effects. use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; diff --git a/src/properties/font.rs b/src/properties/font.rs index c782625a..171ca063 100644 --- a/src/properties/font.rs +++ b/src/properties/font.rs @@ -7,6 +7,7 @@ use crate::compat::Feature; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::*; use crate::printer::Printer; diff --git a/src/properties/grid.rs b/src/properties/grid.rs index 18eb765b..41155a3c 100644 --- a/src/properties/grid.rs +++ b/src/properties/grid.rs @@ -5,6 +5,7 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{Error, ErrorLocation, ParserError, PrinterError, PrinterErrorKind}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::{define_shorthand, impl_shorthand}; use crate::printer::Printer; diff --git a/src/properties/list.rs b/src/properties/list.rs index 1f05cef5..82a13cb9 100644 --- a/src/properties/list.rs +++ b/src/properties/list.rs @@ -4,6 +4,7 @@ use super::{Property, PropertyId}; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::{define_shorthand, enum_property, shorthand_handler, shorthand_property}; use crate::printer::Printer; diff --git a/src/properties/masking.rs b/src/properties/masking.rs index 46829b73..84a77412 100644 --- a/src/properties/masking.rs +++ b/src/properties/masking.rs @@ -6,6 +6,7 @@ use super::PropertyId; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::{define_list_shorthand, define_shorthand, enum_property, property_bitflags}; use crate::prefixes::Feature; diff --git a/src/properties/mod.rs b/src/properties/mod.rs index 3820d774..dc81427e 100644 --- a/src/properties/mod.rs +++ b/src/properties/mod.rs @@ -122,6 +122,7 @@ pub mod ui; use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::logical::{LogicalGroup, PropertyCategory}; use crate::parser::starts_with_ignore_ascii_case; diff --git a/src/properties/svg.rs b/src/properties/svg.rs index 371ef808..e2309096 100644 --- a/src/properties/svg.rs +++ b/src/properties/svg.rs @@ -1,6 +1,7 @@ //! CSS properties used in SVG. use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; diff --git a/src/properties/text.rs b/src/properties/text.rs index 350d77fa..187a84d6 100644 --- a/src/properties/text.rs +++ b/src/properties/text.rs @@ -7,6 +7,7 @@ use crate::compat; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::{define_shorthand, enum_property}; use crate::prefixes::Feature; diff --git a/src/properties/transition.rs b/src/properties/transition.rs index bf7222f4..1a2acdab 100644 --- a/src/properties/transition.rs +++ b/src/properties/transition.rs @@ -5,6 +5,7 @@ use crate::compat; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::define_list_shorthand; use crate::prefixes::Feature; diff --git a/src/properties/ui.rs b/src/properties/ui.rs index 831a99ff..91e84e9d 100644 --- a/src/properties/ui.rs +++ b/src/properties/ui.rs @@ -2,6 +2,7 @@ use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::{define_shorthand, enum_property, shorthand_property}; use crate::printer::Printer; diff --git a/src/rules/container.rs b/src/rules/container.rs index 670527e4..a858df9b 100644 --- a/src/rules/container.rs +++ b/src/rules/container.rs @@ -5,6 +5,7 @@ use cssparser::*; use super::Location; use super::{CssRuleList, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::media_query::{ define_query_features, operation_to_css, parse_query_condition, to_css_with_parens_if_needed, FeatureToCss, diff --git a/src/rules/counter_style.rs b/src/rules/counter_style.rs index d3b2c192..7674ba6b 100644 --- a/src/rules/counter_style.rs +++ b/src/rules/counter_style.rs @@ -3,6 +3,7 @@ use super::Location; use crate::declaration::DeclarationBlock; use crate::error::PrinterError; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; diff --git a/src/rules/custom_media.rs b/src/rules/custom_media.rs index 05940bac..75140522 100644 --- a/src/rules/custom_media.rs +++ b/src/rules/custom_media.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::PrinterError; +#[cfg(not(doctest))] use crate::lightningcss; use crate::media_query::MediaList; use crate::printer::Printer; diff --git a/src/rules/font_face.rs b/src/rules/font_face.rs index b1202772..a16eccc5 100644 --- a/src/rules/font_face.rs +++ b/src/rules/font_face.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; diff --git a/src/rules/font_palette_values.rs b/src/rules/font_palette_values.rs index 88c394a7..93c017b4 100644 --- a/src/rules/font_palette_values.rs +++ b/src/rules/font_palette_values.rs @@ -3,6 +3,7 @@ use super::supports::SupportsRule; use super::{CssRule, CssRuleList, Location, MinifyContext}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::properties::custom::CustomProperty; diff --git a/src/rules/import.rs b/src/rules/import.rs index dea09ace..ca351127 100644 --- a/src/rules/import.rs +++ b/src/rules/import.rs @@ -5,6 +5,7 @@ use super::supports::SupportsCondition; use super::Location; use crate::dependencies::{Dependency, ImportDependency}; use crate::error::PrinterError; +#[cfg(not(doctest))] use crate::lightningcss; use crate::media_query::MediaList; use crate::printer::Printer; diff --git a/src/rules/keyframes.rs b/src/rules/keyframes.rs index 4ae40fb3..8d74355e 100644 --- a/src/rules/keyframes.rs +++ b/src/rules/keyframes.rs @@ -6,6 +6,7 @@ use super::{CssRule, CssRuleList, Location}; use crate::context::DeclarationContext; use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::parser::ParserOptions; use crate::printer::Printer; diff --git a/src/rules/layer.rs b/src/rules/layer.rs index 70933241..064bdef5 100644 --- a/src/rules/layer.rs +++ b/src/rules/layer.rs @@ -2,6 +2,7 @@ use super::{CssRuleList, Location, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::parser::DefaultAtRule; use crate::printer::Printer; diff --git a/src/rules/namespace.rs b/src/rules/namespace.rs index 2f807293..cab54432 100644 --- a/src/rules/namespace.rs +++ b/src/rules/namespace.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::PrinterError; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; diff --git a/src/rules/page.rs b/src/rules/page.rs index f4aa94ce..8f275e69 100644 --- a/src/rules/page.rs +++ b/src/rules/page.rs @@ -3,6 +3,7 @@ use super::Location; use crate::declaration::{parse_declaration, DeclarationBlock}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; diff --git a/src/rules/property.rs b/src/rules/property.rs index 87baaaee..1528b021 100644 --- a/src/rules/property.rs +++ b/src/rules/property.rs @@ -1,6 +1,7 @@ //! The `@property` rule. use super::Location; +#[cfg(not(doctest))] use crate::lightningcss; #[cfg(feature = "visitor")] use crate::visitor::Visit; diff --git a/src/rules/supports.rs b/src/rules/supports.rs index 0cf42e95..903f8fd8 100644 --- a/src/rules/supports.rs +++ b/src/rules/supports.rs @@ -3,6 +3,7 @@ use super::Location; use super::{CssRuleList, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::parser::DefaultAtRule; use crate::printer::Printer; diff --git a/src/rules/unknown.rs b/src/rules/unknown.rs index c1822589..c084bd63 100644 --- a/src/rules/unknown.rs +++ b/src/rules/unknown.rs @@ -2,6 +2,7 @@ use super::Location; use crate::error::PrinterError; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::properties::custom::TokenList; diff --git a/src/rules/viewport.rs b/src/rules/viewport.rs index 21ff0043..41829e26 100644 --- a/src/rules/viewport.rs +++ b/src/rules/viewport.rs @@ -3,6 +3,7 @@ use super::Location; use crate::declaration::DeclarationBlock; use crate::error::PrinterError; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; diff --git a/src/stylesheet.rs b/src/stylesheet.rs index 0ad3808f..06965b03 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -8,6 +8,7 @@ use crate::css_modules::{CssModule, CssModuleExports, CssModuleReferences}; use crate::declaration::{DeclarationBlock, DeclarationHandler}; use crate::dependencies::Dependency; use crate::error::{Error, ErrorLocation, MinifyErrorKind, ParserError, PrinterError, PrinterErrorKind}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::parser::{DefaultAtRule, DefaultAtRuleParser, TopLevelRuleParser}; use crate::printer::Printer; diff --git a/src/values/ident.rs b/src/values/ident.rs index ed0e718e..6b8b3979 100644 --- a/src/values/ident.rs +++ b/src/values/ident.rs @@ -1,6 +1,7 @@ //! CSS identifiers. use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::properties::css_modules::Specifier; diff --git a/src/values/image.rs b/src/values/image.rs index becf6a1e..e7bbeb89 100644 --- a/src/values/image.rs +++ b/src/values/image.rs @@ -6,6 +6,7 @@ use super::resolution::Resolution; use crate::compat; use crate::dependencies::{Dependency, UrlDependency}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::prefixes::{is_webkit_gradient, Feature}; use crate::printer::Printer; diff --git a/src/values/string.rs b/src/values/string.rs index 0cce3571..d7dcbe7e 100644 --- a/src/values/string.rs +++ b/src/values/string.rs @@ -1,5 +1,6 @@ //! Types used to represent strings. +#[cfg(not(doctest))] use crate::lightningcss; use crate::traits::{IntoOwned, Parse, ToCss}; #[cfg(feature = "visitor")] diff --git a/src/values/syntax.rs b/src/values/syntax.rs index 662fd05c..3618cb9d 100644 --- a/src/values/syntax.rs +++ b/src/values/syntax.rs @@ -3,6 +3,7 @@ use super::ident::Ident; use super::number::{CSSInteger, CSSNumber}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; diff --git a/src/values/url.rs b/src/values/url.rs index badb8166..16f8081b 100644 --- a/src/values/url.rs +++ b/src/values/url.rs @@ -2,6 +2,7 @@ use crate::dependencies::{Dependency, Location, UrlDependency}; use crate::error::{ParserError, PrinterError}; +#[cfg(not(doctest))] use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; From fe91be4003d7479e73405b94f6de151925475937 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Sun, 8 Oct 2023 22:14:34 -0700 Subject: [PATCH 28/28] Simplify lightningcss_derive is only really intended to be used by lightningcss itself and not by other crates, so just use `crate` to refer to it. --- derive/src/into_owned.rs | 8 ++++---- src/declaration.rs | 2 -- src/error.rs | 2 -- src/lib.rs | 5 ----- src/media_query.rs | 3 --- src/properties/animation.rs | 2 -- src/properties/background.rs | 2 -- src/properties/border_image.rs | 2 -- src/properties/contain.rs | 2 -- src/properties/css_modules.rs | 2 -- src/properties/custom.rs | 2 -- src/properties/effects.rs | 2 -- src/properties/font.rs | 2 -- src/properties/grid.rs | 2 -- src/properties/list.rs | 2 -- src/properties/masking.rs | 2 -- src/properties/mod.rs | 2 -- src/properties/svg.rs | 2 -- src/properties/text.rs | 2 -- src/properties/transition.rs | 2 -- src/properties/ui.rs | 2 -- src/rules/container.rs | 2 -- src/rules/counter_style.rs | 2 -- src/rules/custom_media.rs | 2 -- src/rules/font_face.rs | 2 -- src/rules/font_palette_values.rs | 2 -- src/rules/import.rs | 2 -- src/rules/keyframes.rs | 2 -- src/rules/layer.rs | 2 -- src/rules/namespace.rs | 2 -- src/rules/page.rs | 2 -- src/rules/property.rs | 2 -- src/rules/supports.rs | 2 -- src/rules/unknown.rs | 2 -- src/rules/viewport.rs | 2 -- src/stylesheet.rs | 2 -- src/values/ident.rs | 2 -- src/values/image.rs | 2 -- src/values/string.rs | 7 +++---- src/values/syntax.rs | 2 -- src/values/url.rs | 2 -- 41 files changed, 7 insertions(+), 90 deletions(-) diff --git a/derive/src/into_owned.rs b/derive/src/into_owned.rs index b686e438..313117bd 100644 --- a/derive/src/into_owned.rs +++ b/derive/src/into_owned.rs @@ -116,7 +116,7 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { for type_param in type_param_names { generics.make_where_clause().predicates.push_value(parse_quote! { - #type_param: 'static + for<'aa> lightningcss::traits::IntoOwned<'aa> + #type_param: 'static + for<'aa> crate::traits::IntoOwned<'aa> }) } @@ -142,7 +142,7 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { let into_owned = if !has_lifetime { quote! { - impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { + impl #impl_generics crate::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { type Owned = Self; #[inline] @@ -154,11 +154,11 @@ pub(crate) fn derive_into_owned(input: TokenStream) -> TokenStream { } else { let params = generics.type_params(); quote! { - impl #impl_generics lightningcss::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { + impl #impl_generics crate::traits::IntoOwned<'any> for #self_name #ty_generics #where_clause { type Owned = #self_name<'any, #(#params),*>; /// Consumes the value and returns an owned clone. fn into_owned(self) -> Self::Owned { - use lightningcss::traits::IntoOwned; + use crate::traits::IntoOwned; #res } diff --git a/src/declaration.rs b/src/declaration.rs index 62605e5f..dd2283f3 100644 --- a/src/declaration.rs +++ b/src/declaration.rs @@ -5,8 +5,6 @@ use std::ops::Range; use crate::context::PropertyHandlerContext; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::parser::ParserOptions; use crate::printer::Printer; use crate::properties::box_shadow::BoxShadowHandler; diff --git a/src/error.rs b/src/error.rs index 73c2e37a..c142be00 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,5 @@ //! Error types. -#[cfg(not(doctest))] -use crate::lightningcss; use crate::properties::custom::Token; use crate::rules::Location; #[cfg(feature = "into_owned")] diff --git a/src/lib.rs b/src/lib.rs index f6ef5176..9d0338e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,11 +47,6 @@ pub mod visitor; #[cfg(feature = "serde")] mod serialization; -/// hack for derive -mod lightningcss { - pub use crate::traits; -} - #[cfg(test)] mod tests { use crate::css_modules::{CssModuleExport, CssModuleExports, CssModuleReference, CssModuleReferences}; diff --git a/src/media_query.rs b/src/media_query.rs index 83a48870..7497a58f 100644 --- a/src/media_query.rs +++ b/src/media_query.rs @@ -1,8 +1,5 @@ //! Media queries. use crate::error::{ErrorWithLocation, MinifyError, MinifyErrorKind, ParserError, PrinterError}; -#[cfg(feature = "into_owned")] -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::enum_property; use crate::parser::starts_with_ignore_ascii_case; use crate::printer::Printer; diff --git a/src/properties/animation.rs b/src/properties/animation.rs index e36ed53e..169c2b9d 100644 --- a/src/properties/animation.rs +++ b/src/properties/animation.rs @@ -3,8 +3,6 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::*; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/background.rs b/src/properties/background.rs index 47224093..873247ff 100644 --- a/src/properties/background.rs +++ b/src/properties/background.rs @@ -3,8 +3,6 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::*; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/border_image.rs b/src/properties/border_image.rs index 39834525..973f0375 100644 --- a/src/properties/border_image.rs +++ b/src/properties/border_image.rs @@ -3,8 +3,6 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::prefixes::Feature; use crate::printer::Printer; use crate::properties::{Property, PropertyId, VendorPrefix}; diff --git a/src/properties/contain.rs b/src/properties/contain.rs index e43c76b3..05fdc032 100644 --- a/src/properties/contain.rs +++ b/src/properties/contain.rs @@ -2,8 +2,6 @@ #![allow(non_upper_case_globals)] -#[cfg(not(doctest))] -use crate::lightningcss; use cssparser::*; use smallvec::SmallVec; diff --git a/src/properties/css_modules.rs b/src/properties/css_modules.rs index a8cd752b..e4a21172 100644 --- a/src/properties/css_modules.rs +++ b/src/properties/css_modules.rs @@ -2,8 +2,6 @@ use crate::dependencies::Location; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; use crate::values::ident::{CustomIdent, CustomIdentList}; diff --git a/src/properties/custom.rs b/src/properties/custom.rs index 447adbbf..891c4831 100644 --- a/src/properties/custom.rs +++ b/src/properties/custom.rs @@ -1,8 +1,6 @@ //! CSS custom properties and unparsed token values. use crate::error::{ParserError, PrinterError, PrinterErrorKind}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::enum_property; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/effects.rs b/src/properties/effects.rs index f0cc0f1b..20b2ee2e 100644 --- a/src/properties/effects.rs +++ b/src/properties/effects.rs @@ -1,8 +1,6 @@ //! CSS properties related to filters and effects. use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; use crate::traits::{FallbackValues, IsCompatible, Parse, ToCss, Zero}; diff --git a/src/properties/font.rs b/src/properties/font.rs index 171ca063..3a81486f 100644 --- a/src/properties/font.rs +++ b/src/properties/font.rs @@ -7,8 +7,6 @@ use crate::compat::Feature; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::*; use crate::printer::Printer; use crate::targets::should_compile; diff --git a/src/properties/grid.rs b/src/properties/grid.rs index 41155a3c..6c783b85 100644 --- a/src/properties/grid.rs +++ b/src/properties/grid.rs @@ -5,8 +5,6 @@ use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{Error, ErrorLocation, ParserError, PrinterError, PrinterErrorKind}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::{define_shorthand, impl_shorthand}; use crate::printer::Printer; use crate::properties::{Property, PropertyId}; diff --git a/src/properties/list.rs b/src/properties/list.rs index 82a13cb9..b37bc0ab 100644 --- a/src/properties/list.rs +++ b/src/properties/list.rs @@ -4,8 +4,6 @@ use super::{Property, PropertyId}; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::{define_shorthand, enum_property, shorthand_handler, shorthand_property}; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; diff --git a/src/properties/masking.rs b/src/properties/masking.rs index 84a77412..5a91c56c 100644 --- a/src/properties/masking.rs +++ b/src/properties/masking.rs @@ -6,8 +6,6 @@ use super::PropertyId; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::{define_list_shorthand, define_shorthand, enum_property, property_bitflags}; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/mod.rs b/src/properties/mod.rs index dc81427e..d5d9027d 100644 --- a/src/properties/mod.rs +++ b/src/properties/mod.rs @@ -122,8 +122,6 @@ pub mod ui; use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::logical::{LogicalGroup, PropertyCategory}; use crate::parser::starts_with_ignore_ascii_case; use crate::parser::ParserOptions; diff --git a/src/properties/svg.rs b/src/properties/svg.rs index e2309096..aa471250 100644 --- a/src/properties/svg.rs +++ b/src/properties/svg.rs @@ -1,8 +1,6 @@ //! CSS properties used in SVG. use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; diff --git a/src/properties/text.rs b/src/properties/text.rs index 187a84d6..92cdae79 100644 --- a/src/properties/text.rs +++ b/src/properties/text.rs @@ -7,8 +7,6 @@ use crate::compat; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::{define_shorthand, enum_property}; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/transition.rs b/src/properties/transition.rs index 1a2acdab..fd296a64 100644 --- a/src/properties/transition.rs +++ b/src/properties/transition.rs @@ -5,8 +5,6 @@ use crate::compat; use crate::context::PropertyHandlerContext; use crate::declaration::{DeclarationBlock, DeclarationList}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::define_list_shorthand; use crate::prefixes::Feature; use crate::printer::Printer; diff --git a/src/properties/ui.rs b/src/properties/ui.rs index 91e84e9d..2fe83a04 100644 --- a/src/properties/ui.rs +++ b/src/properties/ui.rs @@ -2,8 +2,6 @@ use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::{define_shorthand, enum_property, shorthand_property}; use crate::printer::Printer; use crate::properties::{Property, PropertyId}; diff --git a/src/rules/container.rs b/src/rules/container.rs index a858df9b..9af13d99 100644 --- a/src/rules/container.rs +++ b/src/rules/container.rs @@ -5,8 +5,6 @@ use cssparser::*; use super::Location; use super::{CssRuleList, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::media_query::{ define_query_features, operation_to_css, parse_query_condition, to_css_with_parens_if_needed, FeatureToCss, MediaFeatureType, Operator, QueryCondition, QueryConditionFlags, QueryFeature, ValueType, diff --git a/src/rules/counter_style.rs b/src/rules/counter_style.rs index 7674ba6b..50602807 100644 --- a/src/rules/counter_style.rs +++ b/src/rules/counter_style.rs @@ -3,8 +3,6 @@ use super::Location; use crate::declaration::DeclarationBlock; use crate::error::PrinterError; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; use crate::values::ident::CustomIdent; diff --git a/src/rules/custom_media.rs b/src/rules/custom_media.rs index 75140522..322a1847 100644 --- a/src/rules/custom_media.rs +++ b/src/rules/custom_media.rs @@ -2,8 +2,6 @@ use super::Location; use crate::error::PrinterError; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::media_query::MediaList; use crate::printer::Printer; use crate::traits::ToCss; diff --git a/src/rules/font_face.rs b/src/rules/font_face.rs index a16eccc5..df827e8f 100644 --- a/src/rules/font_face.rs +++ b/src/rules/font_face.rs @@ -2,8 +2,6 @@ use super::Location; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; use crate::properties::custom::CustomProperty; diff --git a/src/rules/font_palette_values.rs b/src/rules/font_palette_values.rs index 93c017b4..08ea5417 100644 --- a/src/rules/font_palette_values.rs +++ b/src/rules/font_palette_values.rs @@ -3,8 +3,6 @@ use super::supports::SupportsRule; use super::{CssRule, CssRuleList, Location, MinifyContext}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::properties::custom::CustomProperty; use crate::properties::font::FontFamily; diff --git a/src/rules/import.rs b/src/rules/import.rs index ca351127..9329fe9f 100644 --- a/src/rules/import.rs +++ b/src/rules/import.rs @@ -5,8 +5,6 @@ use super::supports::SupportsCondition; use super::Location; use crate::dependencies::{Dependency, ImportDependency}; use crate::error::PrinterError; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::media_query::MediaList; use crate::printer::Printer; use crate::traits::ToCss; diff --git a/src/rules/keyframes.rs b/src/rules/keyframes.rs index 8d74355e..8e11218e 100644 --- a/src/rules/keyframes.rs +++ b/src/rules/keyframes.rs @@ -6,8 +6,6 @@ use super::{CssRule, CssRuleList, Location}; use crate::context::DeclarationContext; use crate::declaration::DeclarationBlock; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::parser::ParserOptions; use crate::printer::Printer; use crate::properties::custom::{CustomProperty, UnparsedProperty}; diff --git a/src/rules/layer.rs b/src/rules/layer.rs index 064bdef5..eaa04c86 100644 --- a/src/rules/layer.rs +++ b/src/rules/layer.rs @@ -2,8 +2,6 @@ use super::{CssRuleList, Location, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::parser::DefaultAtRule; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; diff --git a/src/rules/namespace.rs b/src/rules/namespace.rs index cab54432..f70cd6fb 100644 --- a/src/rules/namespace.rs +++ b/src/rules/namespace.rs @@ -2,8 +2,6 @@ use super::Location; use crate::error::PrinterError; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; use crate::values::ident::Ident; diff --git a/src/rules/page.rs b/src/rules/page.rs index 8f275e69..e3a03cae 100644 --- a/src/rules/page.rs +++ b/src/rules/page.rs @@ -3,8 +3,6 @@ use super::Location; use crate::declaration::{parse_declaration, DeclarationBlock}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::macros::enum_property; use crate::printer::Printer; use crate::stylesheet::ParserOptions; diff --git a/src/rules/property.rs b/src/rules/property.rs index 1528b021..97d2e82b 100644 --- a/src/rules/property.rs +++ b/src/rules/property.rs @@ -1,8 +1,6 @@ //! The `@property` rule. use super::Location; -#[cfg(not(doctest))] -use crate::lightningcss; #[cfg(feature = "visitor")] use crate::visitor::Visit; use crate::{ diff --git a/src/rules/supports.rs b/src/rules/supports.rs index 903f8fd8..f16a4f0c 100644 --- a/src/rules/supports.rs +++ b/src/rules/supports.rs @@ -3,8 +3,6 @@ use super::Location; use super::{CssRuleList, MinifyContext}; use crate::error::{MinifyError, ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::parser::DefaultAtRule; use crate::printer::Printer; use crate::properties::PropertyId; diff --git a/src/rules/unknown.rs b/src/rules/unknown.rs index c084bd63..492d4c52 100644 --- a/src/rules/unknown.rs +++ b/src/rules/unknown.rs @@ -2,8 +2,6 @@ use super::Location; use crate::error::PrinterError; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::properties::custom::TokenList; use crate::traits::ToCss; diff --git a/src/rules/viewport.rs b/src/rules/viewport.rs index 41829e26..531de878 100644 --- a/src/rules/viewport.rs +++ b/src/rules/viewport.rs @@ -3,8 +3,6 @@ use super::Location; use crate::declaration::DeclarationBlock; use crate::error::PrinterError; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::traits::ToCss; use crate::vendor_prefix::VendorPrefix; diff --git a/src/stylesheet.rs b/src/stylesheet.rs index 06965b03..ebd0a9f0 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -8,8 +8,6 @@ use crate::css_modules::{CssModule, CssModuleExports, CssModuleReferences}; use crate::declaration::{DeclarationBlock, DeclarationHandler}; use crate::dependencies::Dependency; use crate::error::{Error, ErrorLocation, MinifyErrorKind, ParserError, PrinterError, PrinterErrorKind}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::parser::{DefaultAtRule, DefaultAtRuleParser, TopLevelRuleParser}; use crate::printer::Printer; use crate::rules::{CssRule, CssRuleList, MinifyContext}; diff --git a/src/values/ident.rs b/src/values/ident.rs index 6b8b3979..5b775e98 100644 --- a/src/values/ident.rs +++ b/src/values/ident.rs @@ -1,8 +1,6 @@ //! CSS identifiers. use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::properties::css_modules::Specifier; use crate::traits::{Parse, ParseWithOptions, ToCss}; diff --git a/src/values/image.rs b/src/values/image.rs index e7bbeb89..756b3d4c 100644 --- a/src/values/image.rs +++ b/src/values/image.rs @@ -6,8 +6,6 @@ use super::resolution::Resolution; use crate::compat; use crate::dependencies::{Dependency, UrlDependency}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::prefixes::{is_webkit_gradient, Feature}; use crate::printer::Printer; use crate::targets::{Browsers, Targets}; diff --git a/src/values/string.rs b/src/values/string.rs index d7dcbe7e..a067adaa 100644 --- a/src/values/string.rs +++ b/src/values/string.rs @@ -1,8 +1,6 @@ //! Types used to represent strings. -#[cfg(not(doctest))] -use crate::lightningcss; -use crate::traits::{IntoOwned, Parse, ToCss}; +use crate::traits::{Parse, ToCss}; #[cfg(feature = "visitor")] use crate::visitor::{Visit, VisitTypes, Visitor}; use cssparser::{serialize_string, CowRcStr}; @@ -133,7 +131,8 @@ impl<'a> CowArcStr<'a> { } } -impl<'any> IntoOwned<'any> for CowArcStr<'_> { +#[cfg(feature = "into_owned")] +impl<'any> crate::traits::IntoOwned<'any> for CowArcStr<'_> { type Owned = CowArcStr<'any>; /// Consumes the value and returns an owned clone. diff --git a/src/values/syntax.rs b/src/values/syntax.rs index 3618cb9d..94b8429e 100644 --- a/src/values/syntax.rs +++ b/src/values/syntax.rs @@ -3,8 +3,6 @@ use super::ident::Ident; use super::number::{CSSInteger, CSSNumber}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; use crate::values; diff --git a/src/values/url.rs b/src/values/url.rs index 16f8081b..eaf37bfe 100644 --- a/src/values/url.rs +++ b/src/values/url.rs @@ -2,8 +2,6 @@ use crate::dependencies::{Dependency, Location, UrlDependency}; use crate::error::{ParserError, PrinterError}; -#[cfg(not(doctest))] -use crate::lightningcss; use crate::printer::Printer; use crate::traits::{Parse, ToCss}; use crate::values::string::CowArcStr;