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

fix: Remove unsafe in derive(IntoOwned) #614

Merged
merged 26 commits into from
Oct 25, 2023
Merged
2 changes: 2 additions & 0 deletions selectors/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl<AttrValue> AttrSelectorOperation<AttrValue> {
serde(rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum AttrSelectorOperator {
Equal,
Includes,
Expand Down Expand Up @@ -172,6 +173,7 @@ pub static SELECTOR_WHITESPACE: &[char] = &[' ', '\t', '\n', '\r', '\x0C'];
serde(rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum ParsedCaseSensitivity {
// 's' was specified.
ExplicitCaseSensitive,
Expand Down
1 change: 1 addition & 0 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub struct SourceRange {
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(serde::Serialize))]
#[cfg_attr(any(feature = "serde"), derive(serde::Deserialize))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct Location {
/// The line number, starting from 1.
pub line: u32,
Expand Down
4 changes: 4 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ macro_rules! enum_property {
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
$vis enum $name {
$(
$(#[$meta])*
Expand Down Expand Up @@ -78,6 +79,7 @@ macro_rules! enum_property {
#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
$vis enum $name {
$(
$(#[$meta])*
Expand Down Expand Up @@ -386,6 +388,7 @@ macro_rules! define_shorthand {
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct $name$(<$l>)? {
$(
$(#[$meta])*
Expand Down Expand Up @@ -613,6 +616,7 @@ macro_rules! define_list_shorthand {
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct $name$(<$l>)? {
$(
$(#[$meta])*
Expand Down
2 changes: 1 addition & 1 deletion src/media_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ impl<'i> ToCss for MediaCondition<'i> {
serde(rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum MediaFeatureComparison {
/// `=`
Equal,
Expand Down Expand Up @@ -1258,7 +1259,6 @@ macro_rules! define_query_features {
pub(crate) use define_query_features;

define_query_features! {
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
/// A media query feature identifier.
pub enum MediaFeatureId {
/// The [width](https://w3c.github.io/csswg-drafts/mediaqueries-5/#width) media feature.
Expand Down
7 changes: 7 additions & 0 deletions src/properties/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ enum_property! {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum AlignContent {
/// Default alignment.
Normal,
Expand Down Expand Up @@ -188,6 +189,7 @@ impl ToCss for AlignContent {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum JustifyContent {
/// Default justification.
Normal,
Expand Down Expand Up @@ -372,6 +374,7 @@ enum_property! {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum AlignSelf {
/// Automatic alignment.
Auto,
Expand Down Expand Up @@ -446,6 +449,7 @@ impl ToCss for AlignSelf {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum JustifySelf {
/// Automatic justification.
Auto,
Expand Down Expand Up @@ -619,6 +623,7 @@ impl ToCss for PlaceSelf {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum AlignItems {
/// Default alignment.
Normal,
Expand Down Expand Up @@ -754,6 +759,7 @@ impl ToCss for LegacyJustify {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum JustifyItems {
/// Default justification.
Normal,
Expand Down Expand Up @@ -927,6 +933,7 @@ impl ToCss for PlaceItems {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum GapValue {
/// Equal to `1em` for multi-column containers, and zero otherwise.
Normal,
Expand Down
2 changes: 1 addition & 1 deletion src/properties/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub type AnimationNameList<'i> = SmallVec<[AnimationName<'i>; 1]>;
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum AnimationIterationCount {
/// The animation will repeat the specified number of times.
Number(CSSNumber),
Expand Down Expand Up @@ -192,7 +193,6 @@ impl Default for AnimationFillMode {

define_list_shorthand! {
/// A value for the [animation](https://drafts.csswg.org/css-animations/#animation) shorthand property.
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct Animation<'i>(VendorPrefix) {
/// The animation name.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand Down
2 changes: 2 additions & 0 deletions src/properties/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use smallvec::SmallVec;
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum BackgroundSize {
/// An explicit background size.
Explicit {
Expand Down Expand Up @@ -127,6 +128,7 @@ enum_property! {
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct BackgroundRepeat {
/// A repeat style for the x direction.
pub x: BackgroundRepeatKeyword,
Expand Down
16 changes: 16 additions & 0 deletions src/properties/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use cssparser::*;
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum BorderSideWidth {
/// A UA defined `thin` value.
Thin,
Expand Down Expand Up @@ -140,6 +141,21 @@ pub struct GenericBorder<S, const P: u8> {
pub color: CssColor,
}

#[cfg(feature = "into_owned")]
impl<'any, S, const P: u8> static_self::IntoOwned<'any> for GenericBorder<S, P>
where
S: static_self::IntoOwned<'any>,
{
type Owned = GenericBorder<S::Owned, P>;
fn into_owned(self) -> Self::Owned {
GenericBorder {
width: self.width,
style: self.style.into_owned(),
color: self.color,
}
}
}

impl<S: Default, const P: u8> Default for GenericBorder<S, P> {
fn default() -> GenericBorder<S, P> {
GenericBorder {
Expand Down
4 changes: 3 additions & 1 deletion src/properties/border_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl IsCompatible for BorderImageRepeatKeyword {
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct BorderImageRepeat {
/// The horizontal repeat value.
pub horizontal: BorderImageRepeatKeyword,
Expand Down Expand Up @@ -109,6 +110,7 @@ impl IsCompatible for BorderImageRepeat {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum BorderImageSideWidth {
/// A number representing a multiple of the border width.
Number(CSSNumber),
Expand Down Expand Up @@ -170,6 +172,7 @@ impl IsCompatible for BorderImageSideWidth {
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct BorderImageSlice {
/// The offsets from the edges of the image.
pub offsets: Rect<NumberOrPercentage>,
Expand Down Expand Up @@ -219,7 +222,6 @@ impl IsCompatible for BorderImageSlice {
define_shorthand! {
/// A value for the [border-image](https://www.w3.org/TR/css-backgrounds-3/#border-image) shorthand property.
#[derive(Default)]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct BorderImage<'i>(VendorPrefix) {
/// The border image.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand Down
1 change: 1 addition & 0 deletions src/properties/box_shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use smallvec::SmallVec;
serde(rename_all = "camelCase")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct BoxShadow {
/// The color of the box shadow.
pub color: CssColor,
Expand Down
1 change: 0 additions & 1 deletion src/properties/contain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl IsCompatible for ContainerNameList<'_> {

define_shorthand! {
/// A value for the [container](https://drafts.csswg.org/css-contain-3/#container-shorthand) shorthand property.
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct Container<'i> {
/// The container name.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand Down
1 change: 1 addition & 0 deletions src/properties/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ enum_property! {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum Display {
/// A display keyword.
#[cfg_attr(
Expand Down
1 change: 1 addition & 0 deletions src/properties/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ impl IsCompatible for Filter<'_> {
serde(rename_all = "camelCase")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct DropShadow {
/// The color of the drop shadow.
pub color: CssColor,
Expand Down
7 changes: 6 additions & 1 deletion src/properties/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use cssparser::*;
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum FontWeight {
/// An absolute font weight.
Absolute(AbsoluteFontWeight),
Expand Down Expand Up @@ -204,6 +205,7 @@ enum_property! {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum FontSize {
/// An explicit size.
Length(LengthPercentage),
Expand Down Expand Up @@ -315,6 +317,7 @@ impl Into<Percentage> for &FontStretchKeyword {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum FontStretch {
/// A font stretch keyword.
Keyword(FontStretchKeyword),
Expand Down Expand Up @@ -522,6 +525,7 @@ impl IsCompatible for FontFamily<'_> {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum FontStyle {
/// Normal font style.
Normal,
Expand Down Expand Up @@ -648,6 +652,7 @@ impl IsCompatible for FontVariantCaps {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum LineHeight {
/// The UA sets the line height based on the font.
Normal,
Expand Down Expand Up @@ -731,6 +736,7 @@ enum_property! {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum VerticalAlign {
/// A vertical align keyword.
Keyword(VerticalAlignKeyword),
Expand Down Expand Up @@ -763,7 +769,6 @@ impl ToCss for VerticalAlign {

define_shorthand! {
/// A value for the [font](https://www.w3.org/TR/css-fonts-4/#font-prop) shorthand property.
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct Font<'i> {
/// The font family.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand Down
9 changes: 6 additions & 3 deletions src/properties/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub enum TrackListItem<'i> {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum TrackSize {
/// An explicit track breadth.
#[cfg_attr(feature = "serde", serde(with = "ValueWrapper::<TrackBreadth>"))]
Expand Down Expand Up @@ -122,6 +123,7 @@ impl Default for TrackSize {
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(transparent))]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct TrackSizeList(pub SmallVec<[TrackSize; 1]>);

/// A [`<track-breadth>`](https://drafts.csswg.org/css-grid-2/#typedef-track-breadth) value.
Expand All @@ -135,6 +137,7 @@ pub struct TrackSizeList(pub SmallVec<[TrackSize; 1]>);
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum TrackBreadth {
/// An explicit length.
Length(LengthPercentage),
Expand Down Expand Up @@ -183,6 +186,7 @@ pub struct TrackRepeat<'i> {
serde(tag = "type", content = "value", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum RepeatCount {
/// The number of times to repeat.
Number(CSSInteger),
Expand Down Expand Up @@ -588,6 +592,7 @@ impl ToCss for TrackSizeList {
serde(tag = "type", rename_all = "kebab-case")
)]
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub enum GridTemplateAreas {
/// No named grid areas.
None,
Expand Down Expand Up @@ -985,6 +990,7 @@ bitflags! {
/// not be combined.
#[cfg_attr(feature = "visitor", derive(Visit))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(from = "SerializedGridAutoFlow", into = "SerializedGridAutoFlow"))]
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
pub struct GridAutoFlow: u8 {
/// The auto-placement algorithm places items by filling each row, adding new rows as necessary.
Expand Down Expand Up @@ -1506,7 +1512,6 @@ macro_rules! impl_grid_placement {

define_shorthand! {
/// A value for the [grid-row](https://drafts.csswg.org/css-grid-2/#propdef-grid-row) shorthand property.
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct GridRow<'i> {
/// The starting line.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand All @@ -1518,7 +1523,6 @@ define_shorthand! {

define_shorthand! {
/// A value for the [grid-row](https://drafts.csswg.org/css-grid-2/#propdef-grid-column) shorthand property.
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct GridColumn<'i> {
/// The starting line.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand All @@ -1533,7 +1537,6 @@ impl_grid_placement!(GridColumn);

define_shorthand! {
/// A value for the [grid-area](https://drafts.csswg.org/css-grid-2/#propdef-grid-area) shorthand property.
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct GridArea<'i> {
/// The grid row start placement.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand Down
1 change: 0 additions & 1 deletion src/properties/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ enum_property! {

shorthand_property! {
/// A value for the [list-style](https://www.w3.org/TR/2020/WD-css-lists-3-20201117/#list-style-property) shorthand property.
#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
pub struct ListStyle<'i> {
/// The list style type.
#[cfg_attr(feature = "serde", serde(borrow))]
Expand Down
Loading