diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-11-15 11:00:29 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-15 11:00:29 -0600 |
commit | 9863d514512aabbcfaeabba7e530b87f61a8d489 (patch) | |
tree | 34a8e61834087a826d34494d7c2bb6d2382e4a13 | |
parent | 85fa6409bb699647b4f5e22952538365e87418d7 (diff) | |
parent | aca0015930295b034da6e3cae4118fd5dfbb81f4 (diff) | |
download | servo-9863d514512aabbcfaeabba7e530b87f61a8d489.tar.gz servo-9863d514512aabbcfaeabba7e530b87f61a8d489.zip |
Auto merge of #19227 - servo:array-warn, r=emilio
Work around "this expression will panic at run-time" warnings
CC https://github.com/rust-lang/rust/issues/45850
<!-- 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/19227)
<!-- Reviewable:end -->
-rw-r--r-- | components/style/properties/gecko.mako.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index b18b615bcc0..da74f191e5e 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1331,13 +1331,11 @@ pub fn clone_transform_from_list( self.gecko.${gecko_ffi_name}[1].set(v.vertical); // transform-origin supports the third value for depth, while // -moz-window-transform-origin doesn't. The following code is - // for handling this difference. Rust (incorrectly) generates - // an unsuppressible warning, but we know it's safe here. - // See rust-lang/rust#45850. Also if we can have more knowledge + // for handling this difference. If we can have more knowledge // about the type here, we may want to check that the length is // exactly either 2 or 3 in compile time. - if self.gecko.${gecko_ffi_name}.len() == 3 { - self.gecko.${gecko_ffi_name}[2].set(v.depth); + if let Some(third) = self.gecko.${gecko_ffi_name}.get_mut(2) { + third.set(v.depth); } } @@ -1345,8 +1343,10 @@ pub fn clone_transform_from_list( pub fn copy_${ident}_from(&mut self, other: &Self) { self.gecko.${gecko_ffi_name}[0].copy_from(&other.gecko.${gecko_ffi_name}[0]); self.gecko.${gecko_ffi_name}[1].copy_from(&other.gecko.${gecko_ffi_name}[1]); - if self.gecko.${gecko_ffi_name}.len() == 3 { - self.gecko.${gecko_ffi_name}[2].copy_from(&other.gecko.${gecko_ffi_name}[2]); + if let (Some(self_third), Some(other_third)) = + (self.gecko.${gecko_ffi_name}.get_mut(2), other.gecko.${gecko_ffi_name}.get(2)) + { + self_third.copy_from(other_third) } } @@ -1363,8 +1363,8 @@ pub fn clone_transform_from_list( .expect("clone for LengthOrPercentage failed"), vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1]) .expect("clone for LengthOrPercentage failed"), - depth: if self.gecko.${gecko_ffi_name}.len() == 3 { - Length::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[2]) + depth: if let Some(third) = self.gecko.${gecko_ffi_name}.get(2) { + Length::from_gecko_style_coord(third) .expect("clone for Length failed") } else { Length::new(0.) |