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

This commit is contained in:
Xidorn Quan 2017-09-14 18:48:12 +10:00
parent 097cea240f
commit 53a786cea6
9 changed files with 11 additions and 21 deletions

View file

@ -467,6 +467,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};
@ -480,6 +481,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>
@ -2818,7 +2829,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) {