From 7d26cecdabf96c871314ff49b54593a57032f4b1 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Thu, 30 Jul 2020 23:42:53 +0200 Subject: [PATCH 1/2] update AsPrimitive Safety docs for rust 1.45 --- src/cast.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cast.rs b/src/cast.rs index 103c5d4d..bd30e9a5 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -752,8 +752,8 @@ impl NumCast for Wrapping { /// /// # Safety /// -/// Currently, some uses of the `as` operator are not entirely safe. -/// In particular, it is undefined behavior if: +/// **In Rust versions before 1.45.0**, some uses of the `as` operator were not entirely safe. +/// In particular, it was undefined behavior if: /// /// - A truncated floating point value cannot fit in the target integer /// type ([#10184](https://github.com/rust-lang/rust/issues/10184)); From 652e4204c95df50c0aeb36c102046cbf3254d03f Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Fri, 21 Aug 2020 04:59:29 +0200 Subject: [PATCH 2/2] remove example which was never UB from AsPrimitive docs --- src/cast.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/cast.rs b/src/cast.rs index bd30e9a5..38b99bcb 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -753,24 +753,15 @@ impl NumCast for Wrapping { /// # Safety /// /// **In Rust versions before 1.45.0**, some uses of the `as` operator were not entirely safe. -/// In particular, it was undefined behavior if: -/// -/// - A truncated floating point value cannot fit in the target integer -/// type ([#10184](https://github.com/rust-lang/rust/issues/10184)); +/// In particular, it was undefined behavior if +/// a truncated floating point value could not fit in the target integer +/// type ([#10184](https://github.com/rust-lang/rust/issues/10184)). /// /// ```ignore /// # use num_traits::AsPrimitive; /// let x: u8 = (1.04E+17).as_(); // UB /// ``` /// -/// - Or a floating point value does not fit in another floating -/// point type ([#15536](https://github.com/rust-lang/rust/issues/15536)). -/// -/// ```ignore -/// # use num_traits::AsPrimitive; -/// let x: f32 = (1e300f64).as_(); // UB -/// ``` -/// pub trait AsPrimitive: 'static + Copy where T: 'static + Copy,