diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2017-05-24 11:59:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-24 11:59:33 -0700 |
commit | 8a133ab9a1e94336d05db352ef33cecc8a09cbf5 (patch) | |
tree | 1ae97bc31f660935db93a1e311ecc89ce01c12cc | |
parent | d24613dc834ba526b0cf541578cbf7e4b39c92e7 (diff) | |
parent | f867d6b66d93b143cb4c5fb7478f7f3cfa10db00 (diff) | |
download | servo-8a133ab9a1e94336d05db352ef33cecc8a09cbf5.tar.gz servo-8a133ab9a1e94336d05db352ef33cecc8a09cbf5.zip |
Rollup merge of #17020 - MaloJaffre:no_transmute, r=nox
Don't use mem::transmute in from_gecko-weight
Fixes #16966.
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because it's a minor refactor
<!-- 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/17020)
<!-- Reviewable:end -->
-rw-r--r-- | components/style/properties/longhand/font.mako.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index cd60b303436..d9990d9dfdc 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -464,12 +464,13 @@ ${helpers.single_keyword_system("font-variant-caps", } /// Obtain a Servo computed value from a Gecko computed font-weight - pub unsafe fn from_gecko_weight(weight: u16) -> Self { - use std::mem::transmute; - debug_assert!(weight >= 100); - debug_assert!(weight <= 900); - debug_assert!(weight % 10 == 0); - transmute(weight) + pub fn from_gecko_weight(weight: u16) -> Self { + match weight { + % for weight in range(100, 901, 100): + ${weight} => T::Weight${weight}, + % endfor + _ => panic!("from_gecko_weight: called with invalid weight") + } } } } @@ -2362,9 +2363,7 @@ ${helpers.single_keyword("-moz-math-variant", quoted: true }) }).collect::<Vec<_>>(); - let weight = unsafe { - longhands::font_weight::computed_value::T::from_gecko_weight(system.weight) - }; + let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight); let ret = ComputedSystemFont { font_family: longhands::font_family::computed_value::T(family), font_size: Au(system.size), |