From d956b91e3993ced86b5e46d71aee4ff8170b17c7 Mon Sep 17 00:00:00 2001 From: Marcus Griep Date: Wed, 21 Feb 2018 10:45:30 -0500 Subject: [PATCH] Revert lossy conversions to use `as` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The conversions in this changeset cannot use the `From` trait implementation because the conversion is lossy, either because they involve converting a signed value to an unsigned value (`i32`⇒`u64`) or because the convert from a larger data type to a smaller one (`u64`⇒`i32`). In this case, the `as` type cast is necessary to perform a bitwise conversion. This coercion can cause negative values to become very large unsigned values. This is intentional on line 90. --- juniper/src/integrations/serde.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/juniper/src/integrations/serde.rs b/juniper/src/integrations/serde.rs index 30805d929..364c3353b 100644 --- a/juniper/src/integrations/serde.rs +++ b/juniper/src/integrations/serde.rs @@ -77,7 +77,7 @@ impl<'de> de::Deserialize<'de> for InputValue { E: de::Error, { if value >= i64::from(i32::min_value()) && value <= i64::from(i32::max_value()) { - Ok(InputValue::int(i32::from(value))) + Ok(InputValue::int(value as i32)) } else { Err(E::custom(format!("integer out of range"))) } @@ -87,8 +87,8 @@ impl<'de> de::Deserialize<'de> for InputValue { where E: de::Error, { - if value <= u64::from(i32::max_value()) { - self.visit_i64(i64::from(value)) + if value <= i32::max_value() as u64 { + self.visit_i64(value as i64) } else { Err(E::custom(format!("integer out of range"))) }