Skip to content

Commit

Permalink
Merge #184
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and martin-t authored Aug 24, 2020
2 parents 76cfbd1 + 652e420 commit 3196236
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,25 +752,16 @@ impl<T: NumCast> NumCast for Wrapping<T> {
///
/// # Safety
///
/// Currently, some uses of the `as` operator are not entirely safe.
/// In particular, it is 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 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 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<T>: 'static + Copy
where
T: 'static + Copy,
Expand Down

0 comments on commit 3196236

Please sign in to comment.