Skip to content

Commit 3196236

Browse files
bors[bot]martin-t
andauthored
Merge #184
184: Update AsPrimitive Safety docs for rust 1.45 r=cuviper a=martin-t Fixes #174 The safety section should not be removed entirely since people might be using older compilers (as was pointed out to me in a [related issue](yoanlcq/vek#59) in the vek crate). However, [this](rust-lang/rust#15536 (comment)) and followup comments indicate that the second case (float to float) was never UB in the first place - should the second example be removed? Co-authored-by: Martin Taibr <[email protected]>
2 parents 76cfbd1 + 652e420 commit 3196236

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/cast.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -752,25 +752,16 @@ impl<T: NumCast> NumCast for Wrapping<T> {
752752
///
753753
/// # Safety
754754
///
755-
/// Currently, some uses of the `as` operator are not entirely safe.
756-
/// In particular, it is undefined behavior if:
757-
///
758-
/// - A truncated floating point value cannot fit in the target integer
759-
/// type ([#10184](https://github.com/rust-lang/rust/issues/10184));
755+
/// **In Rust versions before 1.45.0**, some uses of the `as` operator were not entirely safe.
756+
/// In particular, it was undefined behavior if
757+
/// a truncated floating point value could not fit in the target integer
758+
/// type ([#10184](https://github.com/rust-lang/rust/issues/10184)).
760759
///
761760
/// ```ignore
762761
/// # use num_traits::AsPrimitive;
763762
/// let x: u8 = (1.04E+17).as_(); // UB
764763
/// ```
765764
///
766-
/// - Or a floating point value does not fit in another floating
767-
/// point type ([#15536](https://github.com/rust-lang/rust/issues/15536)).
768-
///
769-
/// ```ignore
770-
/// # use num_traits::AsPrimitive;
771-
/// let x: f32 = (1e300f64).as_(); // UB
772-
/// ```
773-
///
774765
pub trait AsPrimitive<T>: 'static + Copy
775766
where
776767
T: 'static + Copy,

0 commit comments

Comments
 (0)