Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 269eeea

Browse files
authoredApr 5, 2020
Rollup merge of #70782 - faern:use-assoc-float-consts, r=dtolnay
Stop importing the float modules in documentation Follow up to #69860. I realized I had not searched for and fixed this for the float values. So with this PR they also use the associated constants instead of the module level constants. For the documentation where it also was using the `consts` submodule I opted to change it to import that directly. This becomes more in line with how other docs that use the `consts` submodule looks. And it also makes it so there are not two `f32` or `f64` things in the current namespace (both the module and the primitive type) and then hopefully confusing documentation readers less. r? @dtolnay
2 parents 618ba73 + 28c9231 commit 269eeea

File tree

5 files changed

+34
-150
lines changed

5 files changed

+34
-150
lines changed
 

‎src/libcore/num/f32.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,7 @@ impl f32 {
394394
/// Converts radians to degrees.
395395
///
396396
/// ```
397-
/// use std::f32::consts;
398-
///
399-
/// let angle = consts::PI;
397+
/// let angle = std::f32::consts::PI;
400398
///
401399
/// let abs_difference = (angle.to_degrees() - 180.0).abs();
402400
///
@@ -413,11 +411,9 @@ impl f32 {
413411
/// Converts degrees to radians.
414412
///
415413
/// ```
416-
/// use std::f32::consts;
417-
///
418414
/// let angle = 180.0f32;
419415
///
420-
/// let abs_difference = (angle.to_radians() - consts::PI).abs();
416+
/// let abs_difference = (angle.to_radians() - std::f32::consts::PI).abs();
421417
///
422418
/// assert!(abs_difference <= f32::EPSILON);
423419
/// ```

‎src/libcore/num/f64.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,7 @@ impl f64 {
407407
/// Converts radians to degrees.
408408
///
409409
/// ```
410-
/// use std::f64::consts;
411-
///
412-
/// let angle = consts::PI;
410+
/// let angle = std::f64::consts::PI;
413411
///
414412
/// let abs_difference = (angle.to_degrees() - 180.0).abs();
415413
///
@@ -427,11 +425,9 @@ impl f64 {
427425
/// Converts degrees to radians.
428426
///
429427
/// ```
430-
/// use std::f64::consts;
431-
///
432428
/// let angle = 180.0_f64;
433429
///
434-
/// let abs_difference = (angle.to_radians() - consts::PI).abs();
430+
/// let abs_difference = (angle.to_radians() - std::f64::consts::PI).abs();
435431
///
436432
/// assert!(abs_difference < 1e-10);
437433
/// ```

‎src/libcore/ops/range.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
9898
/// # Examples
9999
///
100100
/// ```
101-
/// use std::f32;
102-
///
103101
/// assert!(!(3..5).contains(&2));
104102
/// assert!( (3..5).contains(&3));
105103
/// assert!( (3..5).contains(&4));
@@ -198,8 +196,6 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
198196
/// # Examples
199197
///
200198
/// ```
201-
/// use std::f32;
202-
///
203199
/// assert!(!(3..).contains(&2));
204200
/// assert!( (3..).contains(&3));
205201
/// assert!( (3..).contains(&1_000_000_000));
@@ -282,8 +278,6 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
282278
/// # Examples
283279
///
284280
/// ```
285-
/// use std::f32;
286-
///
287281
/// assert!( (..5).contains(&-1_000_000_000));
288282
/// assert!( (..5).contains(&4));
289283
/// assert!(!(..5).contains(&5));
@@ -453,8 +447,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
453447
/// # Examples
454448
///
455449
/// ```
456-
/// use std::f32;
457-
///
458450
/// assert!(!(3..=5).contains(&2));
459451
/// assert!( (3..=5).contains(&3));
460452
/// assert!( (3..=5).contains(&4));
@@ -581,8 +573,6 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
581573
/// # Examples
582574
///
583575
/// ```
584-
/// use std::f32;
585-
///
586576
/// assert!( (..=5).contains(&-1_000_000_000));
587577
/// assert!( (..=5).contains(&5));
588578
/// assert!(!(..=5).contains(&6));
@@ -721,8 +711,6 @@ pub trait RangeBounds<T: ?Sized> {
721711
/// # Examples
722712
///
723713
/// ```
724-
/// use std::f32;
725-
///
726714
/// assert!( (3..5).contains(&4));
727715
/// assert!(!(3..5).contains(&2));
728716
///

‎src/libstd/f32.rs

Lines changed: 15 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ impl f32 {
112112
/// # Examples
113113
///
114114
/// ```
115-
/// use std::f32;
116-
///
117115
/// let x = 3.6_f32;
118116
/// let y = -3.6_f32;
119117
/// let abs_difference_x = (x.fract() - 0.6).abs();
@@ -135,8 +133,6 @@ impl f32 {
135133
/// # Examples
136134
///
137135
/// ```
138-
/// use std::f32;
139-
///
140136
/// let x = 3.5_f32;
141137
/// let y = -3.5_f32;
142138
///
@@ -164,8 +160,6 @@ impl f32 {
164160
/// # Examples
165161
///
166162
/// ```
167-
/// use std::f32;
168-
///
169163
/// let f = 3.5_f32;
170164
///
171165
/// assert_eq!(f.signum(), 1.0);
@@ -190,8 +184,6 @@ impl f32 {
190184
/// # Examples
191185
///
192186
/// ```
193-
/// use std::f32;
194-
///
195187
/// let f = 3.5_f32;
196188
///
197189
/// assert_eq!(f.copysign(0.42), 3.5_f32);
@@ -217,8 +209,6 @@ impl f32 {
217209
/// # Examples
218210
///
219211
/// ```
220-
/// use std::f32;
221-
///
222212
/// let m = 10.0_f32;
223213
/// let x = 4.0_f32;
224214
/// let b = 60.0_f32;
@@ -301,8 +291,6 @@ impl f32 {
301291
/// # Examples
302292
///
303293
/// ```
304-
/// use std::f32;
305-
///
306294
/// let x = 2.0_f32;
307295
/// let abs_difference = (x.powi(2) - (x * x)).abs();
308296
///
@@ -320,8 +308,6 @@ impl f32 {
320308
/// # Examples
321309
///
322310
/// ```
323-
/// use std::f32;
324-
///
325311
/// let x = 2.0_f32;
326312
/// let abs_difference = (x.powf(2.0) - (x * x)).abs();
327313
///
@@ -341,8 +327,6 @@ impl f32 {
341327
/// # Examples
342328
///
343329
/// ```
344-
/// use std::f32;
345-
///
346330
/// let positive = 4.0_f32;
347331
/// let negative = -4.0_f32;
348332
///
@@ -363,8 +347,6 @@ impl f32 {
363347
/// # Examples
364348
///
365349
/// ```
366-
/// use std::f32;
367-
///
368350
/// let one = 1.0f32;
369351
/// // e^1
370352
/// let e = one.exp();
@@ -386,8 +368,6 @@ impl f32 {
386368
/// # Examples
387369
///
388370
/// ```
389-
/// use std::f32;
390-
///
391371
/// let f = 2.0f32;
392372
///
393373
/// // 2^2 - 4 == 0
@@ -407,8 +387,6 @@ impl f32 {
407387
/// # Examples
408388
///
409389
/// ```
410-
/// use std::f32;
411-
///
412390
/// let one = 1.0f32;
413391
/// // e^1
414392
/// let e = one.exp();
@@ -434,8 +412,6 @@ impl f32 {
434412
/// # Examples
435413
///
436414
/// ```
437-
/// use std::f32;
438-
///
439415
/// let five = 5.0f32;
440416
///
441417
/// // log5(5) - 1 == 0
@@ -455,8 +431,6 @@ impl f32 {
455431
/// # Examples
456432
///
457433
/// ```
458-
/// use std::f32;
459-
///
460434
/// let two = 2.0f32;
461435
///
462436
/// // log2(2) - 1 == 0
@@ -479,8 +453,6 @@ impl f32 {
479453
/// # Examples
480454
///
481455
/// ```
482-
/// use std::f32;
483-
///
484456
/// let ten = 10.0f32;
485457
///
486458
/// // log10(10) - 1 == 0
@@ -503,8 +475,6 @@ impl f32 {
503475
/// # Examples
504476
///
505477
/// ```
506-
/// use std::f32;
507-
///
508478
/// let x = 3.0f32;
509479
/// let y = -3.0f32;
510480
///
@@ -536,8 +506,6 @@ impl f32 {
536506
/// # Examples
537507
///
538508
/// ```
539-
/// use std::f32;
540-
///
541509
/// let x = 8.0f32;
542510
///
543511
/// // x^(1/3) - 2 == 0
@@ -558,8 +526,6 @@ impl f32 {
558526
/// # Examples
559527
///
560528
/// ```
561-
/// use std::f32;
562-
///
563529
/// let x = 2.0f32;
564530
/// let y = 3.0f32;
565531
///
@@ -580,9 +546,7 @@ impl f32 {
580546
/// # Examples
581547
///
582548
/// ```
583-
/// use std::f32;
584-
///
585-
/// let x = f32::consts::FRAC_PI_2;
549+
/// let x = std::f32::consts::FRAC_PI_2;
586550
///
587551
/// let abs_difference = (x.sin() - 1.0).abs();
588552
///
@@ -600,9 +564,7 @@ impl f32 {
600564
/// # Examples
601565
///
602566
/// ```
603-
/// use std::f32;
604-
///
605-
/// let x = 2.0 * f32::consts::PI;
567+
/// let x = 2.0 * std::f32::consts::PI;
606568
///
607569
/// let abs_difference = (x.cos() - 1.0).abs();
608570
///
@@ -620,9 +582,7 @@ impl f32 {
620582
/// # Examples
621583
///
622584
/// ```
623-
/// use std::f32;
624-
///
625-
/// let x = f32::consts::FRAC_PI_4;
585+
/// let x = std::f32::consts::FRAC_PI_4;
626586
/// let abs_difference = (x.tan() - 1.0).abs();
627587
///
628588
/// assert!(abs_difference <= f32::EPSILON);
@@ -641,12 +601,10 @@ impl f32 {
641601
/// # Examples
642602
///
643603
/// ```
644-
/// use std::f32;
645-
///
646-
/// let f = f32::consts::FRAC_PI_2;
604+
/// let f = std::f32::consts::FRAC_PI_2;
647605
///
648606
/// // asin(sin(pi/2))
649-
/// let abs_difference = (f.sin().asin() - f32::consts::FRAC_PI_2).abs();
607+
/// let abs_difference = (f.sin().asin() - std::f32::consts::FRAC_PI_2).abs();
650608
///
651609
/// assert!(abs_difference <= f32::EPSILON);
652610
/// ```
@@ -664,12 +622,10 @@ impl f32 {
664622
/// # Examples
665623
///
666624
/// ```
667-
/// use std::f32;
668-
///
669-
/// let f = f32::consts::FRAC_PI_4;
625+
/// let f = std::f32::consts::FRAC_PI_4;
670626
///
671627
/// // acos(cos(pi/4))
672-
/// let abs_difference = (f.cos().acos() - f32::consts::FRAC_PI_4).abs();
628+
/// let abs_difference = (f.cos().acos() - std::f32::consts::FRAC_PI_4).abs();
673629
///
674630
/// assert!(abs_difference <= f32::EPSILON);
675631
/// ```
@@ -686,8 +642,6 @@ impl f32 {
686642
/// # Examples
687643
///
688644
/// ```
689-
/// use std::f32;
690-
///
691645
/// let f = 1.0f32;
692646
///
693647
/// // atan(tan(1))
@@ -712,8 +666,6 @@ impl f32 {
712666
/// # Examples
713667
///
714668
/// ```
715-
/// use std::f32;
716-
///
717669
/// // Positive angles measured counter-clockwise
718670
/// // from positive x axis
719671
/// // -pi/4 radians (45 deg clockwise)
@@ -724,8 +676,8 @@ impl f32 {
724676
/// let x2 = -3.0f32;
725677
/// let y2 = 3.0f32;
726678
///
727-
/// let abs_difference_1 = (y1.atan2(x1) - (-f32::consts::FRAC_PI_4)).abs();
728-
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f32::consts::FRAC_PI_4)).abs();
679+
/// let abs_difference_1 = (y1.atan2(x1) - (-std::f32::consts::FRAC_PI_4)).abs();
680+
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f32::consts::FRAC_PI_4)).abs();
729681
///
730682
/// assert!(abs_difference_1 <= f32::EPSILON);
731683
/// assert!(abs_difference_2 <= f32::EPSILON);
@@ -743,9 +695,7 @@ impl f32 {
743695
/// # Examples
744696
///
745697
/// ```
746-
/// use std::f32;
747-
///
748-
/// let x = f32::consts::FRAC_PI_4;
698+
/// let x = std::f32::consts::FRAC_PI_4;
749699
/// let f = x.sin_cos();
750700
///
751701
/// let abs_difference_0 = (f.0 - x.sin()).abs();
@@ -766,8 +716,6 @@ impl f32 {
766716
/// # Examples
767717
///
768718
/// ```
769-
/// use std::f32;
770-
///
771719
/// let x = 6.0f32;
772720
///
773721
/// // e^(ln(6)) - 1
@@ -788,9 +736,7 @@ impl f32 {
788736
/// # Examples
789737
///
790738
/// ```
791-
/// use std::f32;
792-
///
793-
/// let x = f32::consts::E - 1.0;
739+
/// let x = std::f32::consts::E - 1.0;
794740
///
795741
/// // ln(1 + (e - 1)) == ln(e) == 1
796742
/// let abs_difference = (x.ln_1p() - 1.0).abs();
@@ -809,9 +755,7 @@ impl f32 {
809755
/// # Examples
810756
///
811757
/// ```
812-
/// use std::f32;
813-
///
814-
/// let e = f32::consts::E;
758+
/// let e = std::f32::consts::E;
815759
/// let x = 1.0f32;
816760
///
817761
/// let f = x.sinh();
@@ -833,9 +777,7 @@ impl f32 {
833777
/// # Examples
834778
///
835779
/// ```
836-
/// use std::f32;
837-
///
838-
/// let e = f32::consts::E;
780+
/// let e = std::f32::consts::E;
839781
/// let x = 1.0f32;
840782
/// let f = x.cosh();
841783
/// // Solving cosh() at 1 gives this result
@@ -857,9 +799,7 @@ impl f32 {
857799
/// # Examples
858800
///
859801
/// ```
860-
/// use std::f32;
861-
///
862-
/// let e = f32::consts::E;
802+
/// let e = std::f32::consts::E;
863803
/// let x = 1.0f32;
864804
///
865805
/// let f = x.tanh();
@@ -881,8 +821,6 @@ impl f32 {
881821
/// # Examples
882822
///
883823
/// ```
884-
/// use std::f32;
885-
///
886824
/// let x = 1.0f32;
887825
/// let f = x.sinh().asinh();
888826
///
@@ -906,8 +844,6 @@ impl f32 {
906844
/// # Examples
907845
///
908846
/// ```
909-
/// use std::f32;
910-
///
911847
/// let x = 1.0f32;
912848
/// let f = x.cosh().acosh();
913849
///
@@ -927,9 +863,7 @@ impl f32 {
927863
/// # Examples
928864
///
929865
/// ```
930-
/// use std::f32;
931-
///
932-
/// let e = f32::consts::E;
866+
/// let e = std::f32::consts::E;
933867
/// let f = e.tanh().atanh();
934868
///
935869
/// let abs_difference = (f - e).abs();

‎src/libstd/f64.rs

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ impl f64 {
133133
/// # Examples
134134
///
135135
/// ```
136-
/// use std::f64;
137-
///
138136
/// let x = 3.5_f64;
139137
/// let y = -3.5_f64;
140138
///
@@ -162,8 +160,6 @@ impl f64 {
162160
/// # Examples
163161
///
164162
/// ```
165-
/// use std::f64;
166-
///
167163
/// let f = 3.5_f64;
168164
///
169165
/// assert_eq!(f.signum(), 1.0);
@@ -188,8 +184,6 @@ impl f64 {
188184
/// # Examples
189185
///
190186
/// ```
191-
/// use std::f64;
192-
///
193187
/// let f = 3.5_f64;
194188
///
195189
/// assert_eq!(f.copysign(0.42), 3.5_f64);
@@ -554,9 +548,7 @@ impl f64 {
554548
/// # Examples
555549
///
556550
/// ```
557-
/// use std::f64;
558-
///
559-
/// let x = f64::consts::FRAC_PI_2;
551+
/// let x = std::f64::consts::FRAC_PI_2;
560552
///
561553
/// let abs_difference = (x.sin() - 1.0).abs();
562554
///
@@ -574,9 +566,7 @@ impl f64 {
574566
/// # Examples
575567
///
576568
/// ```
577-
/// use std::f64;
578-
///
579-
/// let x = 2.0 * f64::consts::PI;
569+
/// let x = 2.0 * std::f64::consts::PI;
580570
///
581571
/// let abs_difference = (x.cos() - 1.0).abs();
582572
///
@@ -594,9 +584,7 @@ impl f64 {
594584
/// # Examples
595585
///
596586
/// ```
597-
/// use std::f64;
598-
///
599-
/// let x = f64::consts::FRAC_PI_4;
587+
/// let x = std::f64::consts::FRAC_PI_4;
600588
/// let abs_difference = (x.tan() - 1.0).abs();
601589
///
602590
/// assert!(abs_difference < 1e-14);
@@ -615,12 +603,10 @@ impl f64 {
615603
/// # Examples
616604
///
617605
/// ```
618-
/// use std::f64;
619-
///
620-
/// let f = f64::consts::FRAC_PI_2;
606+
/// let f = std::f64::consts::FRAC_PI_2;
621607
///
622608
/// // asin(sin(pi/2))
623-
/// let abs_difference = (f.sin().asin() - f64::consts::FRAC_PI_2).abs();
609+
/// let abs_difference = (f.sin().asin() - std::f64::consts::FRAC_PI_2).abs();
624610
///
625611
/// assert!(abs_difference < 1e-10);
626612
/// ```
@@ -638,12 +624,10 @@ impl f64 {
638624
/// # Examples
639625
///
640626
/// ```
641-
/// use std::f64;
642-
///
643-
/// let f = f64::consts::FRAC_PI_4;
627+
/// let f = std::f64::consts::FRAC_PI_4;
644628
///
645629
/// // acos(cos(pi/4))
646-
/// let abs_difference = (f.cos().acos() - f64::consts::FRAC_PI_4).abs();
630+
/// let abs_difference = (f.cos().acos() - std::f64::consts::FRAC_PI_4).abs();
647631
///
648632
/// assert!(abs_difference < 1e-10);
649633
/// ```
@@ -684,8 +668,6 @@ impl f64 {
684668
/// # Examples
685669
///
686670
/// ```
687-
/// use std::f64;
688-
///
689671
/// // Positive angles measured counter-clockwise
690672
/// // from positive x axis
691673
/// // -pi/4 radians (45 deg clockwise)
@@ -696,8 +678,8 @@ impl f64 {
696678
/// let x2 = -3.0_f64;
697679
/// let y2 = 3.0_f64;
698680
///
699-
/// let abs_difference_1 = (y1.atan2(x1) - (-f64::consts::FRAC_PI_4)).abs();
700-
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f64::consts::FRAC_PI_4)).abs();
681+
/// let abs_difference_1 = (y1.atan2(x1) - (-std::f64::consts::FRAC_PI_4)).abs();
682+
/// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f64::consts::FRAC_PI_4)).abs();
701683
///
702684
/// assert!(abs_difference_1 < 1e-10);
703685
/// assert!(abs_difference_2 < 1e-10);
@@ -715,9 +697,7 @@ impl f64 {
715697
/// # Examples
716698
///
717699
/// ```
718-
/// use std::f64;
719-
///
720-
/// let x = f64::consts::FRAC_PI_4;
700+
/// let x = std::f64::consts::FRAC_PI_4;
721701
/// let f = x.sin_cos();
722702
///
723703
/// let abs_difference_0 = (f.0 - x.sin()).abs();
@@ -758,9 +738,7 @@ impl f64 {
758738
/// # Examples
759739
///
760740
/// ```
761-
/// use std::f64;
762-
///
763-
/// let x = f64::consts::E - 1.0;
741+
/// let x = std::f64::consts::E - 1.0;
764742
///
765743
/// // ln(1 + (e - 1)) == ln(e) == 1
766744
/// let abs_difference = (x.ln_1p() - 1.0).abs();
@@ -779,9 +757,7 @@ impl f64 {
779757
/// # Examples
780758
///
781759
/// ```
782-
/// use std::f64;
783-
///
784-
/// let e = f64::consts::E;
760+
/// let e = std::f64::consts::E;
785761
/// let x = 1.0_f64;
786762
///
787763
/// let f = x.sinh();
@@ -803,9 +779,7 @@ impl f64 {
803779
/// # Examples
804780
///
805781
/// ```
806-
/// use std::f64;
807-
///
808-
/// let e = f64::consts::E;
782+
/// let e = std::f64::consts::E;
809783
/// let x = 1.0_f64;
810784
/// let f = x.cosh();
811785
/// // Solving cosh() at 1 gives this result
@@ -827,9 +801,7 @@ impl f64 {
827801
/// # Examples
828802
///
829803
/// ```
830-
/// use std::f64;
831-
///
832-
/// let e = f64::consts::E;
804+
/// let e = std::f64::consts::E;
833805
/// let x = 1.0_f64;
834806
///
835807
/// let f = x.tanh();
@@ -893,9 +865,7 @@ impl f64 {
893865
/// # Examples
894866
///
895867
/// ```
896-
/// use std::f64;
897-
///
898-
/// let e = f64::consts::E;
868+
/// let e = std::f64::consts::E;
899869
/// let f = e.tanh().atanh();
900870
///
901871
/// let abs_difference = (f - e).abs();

0 commit comments

Comments
 (0)
Please sign in to comment.