Auto merge of #18498 - upsuper:enum-keyword-exhaustive, r=emilio

Use exhaustive match for cloning keyword value by default for property using enum class

rather than casting them to `u8` then do inexhaustive match.

I don't see why we couldn't do this.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18498)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-09-14 06:28:16 -05:00 committed by GitHub
commit 9dd0513647
9 changed files with 11 additions and 21 deletions

View file

@ -472,6 +472,7 @@ def set_gecko_property(ffi_name, expr):
// as signed type when we have both signed/unsigned integer in order to use them
// as match's arms.
// Also, to use same implementation here we use casted constant if we have only singed values.
% if keyword.gecko_enum_prefix is None:
% for value in keyword.values_for('gecko'):
const ${keyword.casted_constant_name(value, cast_type)} : ${cast_type} =
structs::${keyword.gecko_constant(value)} as ${cast_type};
@ -485,6 +486,16 @@ def set_gecko_property(ffi_name, expr):
x => panic!("Found unexpected value in style struct for ${ident} property: {:?}", x),
% endif
}
% else:
match ${get_gecko_property(gecko_ffi_name)} {
% for value in keyword.values_for('gecko'):
structs::${keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)},
% endfor
% if keyword.gecko_inexhaustive:
x => panic!("Found unexpected value in style struct for ${ident} property: {:?}", x),
% endif
}
% endif
}
</%def>
@ -2823,7 +2834,6 @@ fn static_assert() {
"-moz-grid-group -moz-grid-line -moz-stack -moz-inline-stack -moz-deck " +
"-moz-popup -moz-groupbox",
gecko_enum_prefix="StyleDisplay",
gecko_inexhaustive="True",
gecko_strip_moz_prefix=False) %>
pub fn set_display(&mut self, v: longhands::display::computed_value::T) {

View file

@ -195,14 +195,12 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
${helpers.single_keyword("box-decoration-break", "slice clone",
gecko_enum_prefix="StyleBoxDecorationBreak",
gecko_inexhaustive=True,
spec="https://drafts.csswg.org/css-break/#propdef-box-decoration-break",
products="gecko", animation_value_type="discrete")}
${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
gecko_ffi_name="mFloatEdge",
gecko_enum_prefix="StyleFloatEdge",
gecko_inexhaustive=True,
products="gecko",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-float-edge)",
animation_value_type="discrete")}

View file

@ -1793,7 +1793,6 @@ ${helpers.single_keyword("-moz-orient",
gecko_ffi_name="mOrient",
gecko_enum_prefix="StyleOrient",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-orient)",
gecko_inexhaustive="True",
animation_value_type="discrete")}
<%helpers:longhand name="will-change" products="gecko" animation_value_type="discrete"

View file

@ -45,7 +45,6 @@ ${helpers.predefined_type("fill-opacity", "SVGOpacity", "Default::default()",
${helpers.single_keyword("fill-rule", "nonzero evenodd",
gecko_enum_prefix="StyleFillRule",
gecko_inexhaustive=True,
products="gecko", animation_value_type="discrete",
spec="https://www.w3.org/TR/SVG11/painting.html#FillRuleProperty")}
@ -110,7 +109,6 @@ ${helpers.predefined_type(
${helpers.single_keyword("clip-rule", "nonzero evenodd",
products="gecko",
gecko_enum_prefix="StyleFillRule",
gecko_inexhaustive=True,
animation_value_type="discrete",
spec="https://www.w3.org/TR/SVG11/masking.html#ClipRuleProperty")}

View file

@ -25,7 +25,6 @@ ${helpers.single_keyword("text-transform",
${helpers.single_keyword("hyphens", "manual none auto",
gecko_enum_prefix="StyleHyphens",
gecko_inexhaustive=True,
products="gecko", animation_value_type="discrete", extra_prefixes="moz",
spec="https://drafts.csswg.org/css-text/#propdef-hyphens")}
@ -66,7 +65,6 @@ ${helpers.single_keyword("word-break",
extra_gecko_values="inter-character"
extra_specified="${'distribute' if product == 'gecko' else ''}"
gecko_enum_prefix="StyleTextJustify"
gecko_inexhaustive="True"
animation_value_type="discrete"
flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-text/#propdef-text-justify">
@ -368,7 +366,6 @@ ${helpers.predefined_type("word-spacing",
extra_gecko_values="-moz-pre-space"
gecko_enum_prefix="StyleWhiteSpace"
needs_conversion="True"
gecko_inexhaustive="True"
animation_value_type="discrete"
// Only allowed for UA sheets, which set it
// !important.

View file

@ -155,7 +155,6 @@ ${helpers.single_keyword("pointer-events", "auto none", animation_value_type="di
${helpers.single_keyword("-moz-user-input", "auto none enabled disabled",
products="gecko", gecko_ffi_name="mUserInput",
gecko_enum_prefix="StyleUserInput",
gecko_inexhaustive=True,
animation_value_type="discrete",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-user-input)")}
@ -163,7 +162,6 @@ ${helpers.single_keyword("-moz-user-modify", "read-only read-write write-only",
products="gecko", gecko_ffi_name="mUserModify",
gecko_enum_prefix="StyleUserModify",
needs_conversion=True,
gecko_inexhaustive=True,
animation_value_type="discrete",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-user-modify)")}
@ -171,7 +169,6 @@ ${helpers.single_keyword("-moz-user-focus",
"none ignore normal select-after select-before select-menu select-same select-all",
products="gecko", gecko_ffi_name="mUserFocus",
gecko_enum_prefix="StyleUserFocus",
gecko_inexhaustive=True,
animation_value_type="discrete",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-user-focus)")}

View file

@ -232,7 +232,6 @@ ${helpers.single_keyword("box-sizing",
spec="https://drafts.csswg.org/css-ui/#propdef-box-sizing",
gecko_enum_prefix="StyleBoxSizing",
custom_consts={ "content-box": "Content", "border-box": "Border" },
gecko_inexhaustive=True,
animation_value_type="discrete")}
${helpers.single_keyword("object-fit", "fill contain cover none scale-down",

View file

@ -22,7 +22,6 @@ ${helpers.single_keyword("-moz-user-select", "auto text none all element element
alias="-webkit-user-select",
gecko_ffi_name="mUserSelect",
gecko_enum_prefix="StyleUserSelect",
gecko_inexhaustive=True,
gecko_strip_moz_prefix=False,
aliases="-moz-none=none",
animation_value_type="discrete",
@ -31,14 +30,12 @@ ${helpers.single_keyword("-moz-user-select", "auto text none all element element
${helpers.single_keyword("-moz-window-dragging", "default drag no-drag", products="gecko",
gecko_ffi_name="mWindowDragging",
gecko_enum_prefix="StyleWindowDragging",
gecko_inexhaustive=True,
animation_value_type="discrete",
spec="None (Nonstandard Firefox-only property)")}
${helpers.single_keyword("-moz-window-shadow", "none default menu tooltip sheet", products="gecko",
gecko_ffi_name="mWindowShadow",
gecko_constant_prefix="NS_STYLE_WINDOW_SHADOW",
gecko_inexhaustive=True,
animation_value_type="discrete",
internal=True,
spec="None (Nonstandard internal property)")}

View file

@ -11,7 +11,6 @@
${helpers.single_keyword("-moz-box-align", "stretch start center baseline end",
products="gecko", gecko_ffi_name="mBoxAlign",
gecko_enum_prefix="StyleBoxAlign",
gecko_inexhaustive=True,
animation_value_type="discrete",
alias="-webkit-box-align",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/box-align)")}
@ -19,7 +18,6 @@ ${helpers.single_keyword("-moz-box-align", "stretch start center baseline end",
${helpers.single_keyword("-moz-box-direction", "normal reverse",
products="gecko", gecko_ffi_name="mBoxDirection",
gecko_enum_prefix="StyleBoxDirection",
gecko_inexhaustive=True,
animation_value_type="discrete",
alias="-webkit-box-direction",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/box-direction)")}
@ -34,7 +32,6 @@ ${helpers.single_keyword("-moz-box-orient", "horizontal vertical",
products="gecko", gecko_ffi_name="mBoxOrient",
extra_gecko_aliases="inline-axis=horizontal block-axis=vertical",
gecko_enum_prefix="StyleBoxOrient",
gecko_inexhaustive=True,
animation_value_type="discrete",
alias="-webkit-box-orient",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/box-orient)")}
@ -42,7 +39,6 @@ ${helpers.single_keyword("-moz-box-orient", "horizontal vertical",
${helpers.single_keyword("-moz-box-pack", "start center end justify",
products="gecko", gecko_ffi_name="mBoxPack",
gecko_enum_prefix="StyleBoxPack",
gecko_inexhaustive=True,
animation_value_type="discrete",
alias="-webkit-box-pack",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/box-pack)")}
@ -50,7 +46,6 @@ ${helpers.single_keyword("-moz-box-pack", "start center end justify",
${helpers.single_keyword("-moz-stack-sizing", "stretch-to-fit ignore ignore-horizontal ignore-vertical",
products="gecko", gecko_ffi_name="mStackSizing",
gecko_enum_prefix="StyleStackSizing",
gecko_inexhaustive=True,
animation_value_type="discrete",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-stack-sizing)")}