diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-04-03 00:32:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-03 00:32:00 +0200 |
| commit | 1eabbd024c0e49d8ca66c804f502c65cbad90ced (patch) | |
| tree | 04acfbfa5c0af0d21c6742ee7019398c57c211c6 /src/libcore/convert | |
| parent | 537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae (diff) | |
| parent | 56147219a552b8383e66f9e3e8f0c92ea332aaf4 (diff) | |
| download | rust-1eabbd024c0e49d8ca66c804f502c65cbad90ced.tar.gz rust-1eabbd024c0e49d8ca66c804f502c65cbad90ced.zip | |
Rollup merge of #70487 - Mark-Simulacrum:float-unchecked-casts, r=SimonSapin
Stabilize float::to_int_unchecked This renames and stabilizes unsafe floating point to integer casts, which are intended to be the substitute for the currently unsound `as` behavior, once that changes to safe-but-slower saturating casts. As such, I believe this also likely unblocks #10184 (our oldest I-unsound issue!), as once this rolls out to stable it would be far easier IMO to change the behavior of `as` to be safe by default. This does not stabilize the trait or the associated method, as they are deemed internal implementation details (and consumers should not, generally, want to expose them, as in practice all callers likely know statically/without generics what the return type is). Closes #67058
Diffstat (limited to 'src/libcore/convert')
| -rw-r--r-- | src/libcore/convert/num.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libcore/convert/num.rs b/src/libcore/convert/num.rs index 752199c94b8..66ae760fc1f 100644 --- a/src/libcore/convert/num.rs +++ b/src/libcore/convert/num.rs @@ -13,9 +13,9 @@ mod private { /// Typically doesn’t need to be used directly. #[unstable(feature = "convert_float_to_int", issue = "67057")] pub trait FloatToInt<Int>: private::Sealed + Sized { - #[unstable(feature = "float_approx_unchecked_to", issue = "67058")] + #[unstable(feature = "convert_float_to_int", issue = "67057")] #[doc(hidden)] - unsafe fn approx_unchecked(self) -> Int; + unsafe fn to_int_unchecked(self) -> Int; } macro_rules! impl_float_to_int { @@ -27,8 +27,15 @@ macro_rules! impl_float_to_int { impl FloatToInt<$Int> for $Float { #[doc(hidden)] #[inline] - unsafe fn approx_unchecked(self) -> $Int { - crate::intrinsics::float_to_int_approx_unchecked(self) + unsafe fn to_int_unchecked(self) -> $Int { + #[cfg(bootstrap)] + { + crate::intrinsics::float_to_int_approx_unchecked(self) + } + #[cfg(not(bootstrap))] + { + crate::intrinsics::float_to_int_unchecked(self) + } } } )+ |
