@@ -594,8 +594,22 @@ impl<T> NotNan<T> {
594
594
/// # Safety
595
595
///
596
596
/// Behaviour is undefined if `val` is NaN
597
+ #[ deprecated(
598
+ since = "2.5.0" ,
599
+ note = "Please use the new_unchecked function instead."
600
+ ) ]
597
601
#[ inline]
598
602
pub const unsafe fn unchecked_new ( val : T ) -> Self {
603
+ Self :: new_unchecked ( val)
604
+ }
605
+
606
+ /// Create a `NotNan` value from a value that is guaranteed to not be NaN
607
+ ///
608
+ /// # Safety
609
+ ///
610
+ /// Behaviour is undefined if `val` is NaN
611
+ #[ inline]
612
+ pub const unsafe fn new_unchecked ( val : T ) -> Self {
599
613
NotNan ( val)
600
614
}
601
615
}
@@ -666,7 +680,7 @@ impl From<NotNan<f32>> for NotNan<f64> {
666
680
#[ inline]
667
681
fn from ( v : NotNan < f32 > ) -> NotNan < f64 > {
668
682
unsafe {
669
- NotNan :: unchecked_new ( v. 0 as f64 )
683
+ NotNan :: new_unchecked ( v. 0 as f64 )
670
684
}
671
685
}
672
686
}
@@ -1246,9 +1260,9 @@ mod impl_rand {
1246
1260
impl Distribution <NotNan <$f>> for $dist {
1247
1261
fn sample<R : Rng + ?Sized >( & self , rng: & mut R ) -> NotNan <$f> {
1248
1262
// 'rand' never generates NaN values in the Standard, Open01, or
1249
- // OpenClosed01 distributions. Using 'unchecked_new ' is therefore
1263
+ // OpenClosed01 distributions. Using 'new_unchecked ' is therefore
1250
1264
// safe.
1251
- unsafe { NotNan :: unchecked_new ( self . sample( rng) ) }
1265
+ unsafe { NotNan :: new_unchecked ( self . sample( rng) ) }
1252
1266
}
1253
1267
}
1254
1268
@@ -1299,7 +1313,7 @@ mod impl_rand {
1299
1313
}
1300
1314
fn sample<R : Rng + ?Sized >( & self , rng: & mut R ) -> Self :: X {
1301
1315
// UniformFloat.sample() will never return NaN.
1302
- unsafe { NotNan :: unchecked_new ( self . 0 . sample( rng) ) }
1316
+ unsafe { NotNan :: new_unchecked ( self . 0 . sample( rng) ) }
1303
1317
}
1304
1318
}
1305
1319
0 commit comments