Skip to content

Commit 17c5a81

Browse files
authored
Rollup merge of #70857 - faern:use-assoc-int-float-consts, r=dtolnay
Don't import integer and float modules, use assoc consts 2 Follow up to #70777. I missed quite a lot of places. Partially because I wanted to keep the size of the last PR down, and partially because my regexes were not good enough :) r? @dtolnay
2 parents 61cd420 + f7778d3 commit 17c5a81

File tree

25 files changed

+52
-68
lines changed

25 files changed

+52
-68
lines changed

src/liballoc/raw_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ unsafe impl<#[may_dangle] T, A: AllocRef> Drop for RawVec<T, A> {
608608

609609
#[inline]
610610
fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> {
611-
if mem::size_of::<usize>() < 8 && alloc_size > core::isize::MAX as usize {
611+
if mem::size_of::<usize>() < 8 && alloc_size > isize::MAX as usize {
612612
Err(CapacityOverflow)
613613
} else {
614614
Ok(())

src/liballoc/tests/arc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn trait_object() {
5050

5151
#[test]
5252
fn float_nan_ne() {
53-
let x = Arc::new(std::f32::NAN);
53+
let x = Arc::new(f32::NAN);
5454
assert!(x != x);
5555
assert!(!(x == x));
5656
}

src/liballoc/tests/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn test_range_large() {
475475

476476
#[test]
477477
fn test_range_inclusive_max_value() {
478-
let max = std::usize::MAX;
478+
let max = usize::MAX;
479479
let map: BTreeMap<_, _> = vec![(max, 0)].into_iter().collect();
480480

481481
assert_eq!(map.range(max..=max).collect::<Vec<_>>(), &[(&max, &0)]);

src/liballoc/tests/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn trait_object() {
5050

5151
#[test]
5252
fn float_nan_ne() {
53-
let x = Rc::new(std::f32::NAN);
53+
let x = Rc::new(f32::NAN);
5454
assert!(x != x);
5555
assert!(!(x == x));
5656
}

src/libcore/benches/num/dec2flt/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::f64;
21
use test::Bencher;
32

43
#[bench]

src/libcore/benches/num/flt2dec/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod strategy {
55

66
use core::num::flt2dec::MAX_SIG_DIGITS;
77
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
8-
use std::f64;
98
use std::io::Write;
109
use std::vec::Vec;
1110
use test::Bencher;

src/libcore/tests/iter.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ fn test_cmp_by() {
7676
#[test]
7777
fn test_partial_cmp_by() {
7878
use core::cmp::Ordering;
79-
use core::f64;
8079

8180
let f = |x: i32, y: i32| (x * x).partial_cmp(&y);
8281
let xs = || [1, 2, 3, 4].iter().copied();
@@ -2894,7 +2893,7 @@ fn test_is_sorted() {
28942893
assert!(![1, 3, 2].iter().is_sorted());
28952894
assert!([0].iter().is_sorted());
28962895
assert!(std::iter::empty::<i32>().is_sorted());
2897-
assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
2896+
assert!(![0.0, 1.0, f32::NAN].iter().is_sorted());
28982897
assert!([-2, -1, 0, 3].iter().is_sorted());
28992898
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
29002899
assert!(!["c", "bb", "aaa"].iter().is_sorted());

src/libcore/tests/num/dec2flt/rawfp.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use core::num::dec2flt::rawfp::RawFloat;
22
use core::num::dec2flt::rawfp::{fp_to_float, next_float, prev_float, round_normal};
33
use core::num::diy_float::Fp;
4-
use std::f32;
5-
use std::f64;
64

75
fn integer_decode(f: f64) -> (u64, i16, i8) {
86
RawFloat::integer_decode(f)

src/libcore/tests/num/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ test_impl_from! { test_u32f64, u32, f64 }
205205
// Float -> Float
206206
#[test]
207207
fn test_f32f64() {
208-
use core::f32;
209-
210208
let max: f64 = f32::MAX.into();
211209
assert_eq!(max as f32, f32::MAX);
212210
assert!(max.is_normal());
@@ -704,5 +702,5 @@ macro_rules! test_float {
704702
};
705703
}
706704

707-
test_float!(f32, f32, ::core::f32::INFINITY, ::core::f32::NEG_INFINITY, ::core::f32::NAN);
708-
test_float!(f64, f64, ::core::f64::INFINITY, ::core::f64::NEG_INFINITY, ::core::f64::NAN);
705+
test_float!(f32, f32, f32::INFINITY, f32::NEG_INFINITY, f32::NAN);
706+
test_float!(f64, f64, f64::INFINITY, f64::NEG_INFINITY, f64::NAN);

src/libcore/tests/ops.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,23 @@ fn test_range_inclusive() {
6161

6262
#[test]
6363
fn test_range_is_empty() {
64-
use core::f32::*;
65-
6664
assert!(!(0.0..10.0).is_empty());
6765
assert!((-0.0..0.0).is_empty());
6866
assert!((10.0..0.0).is_empty());
6967

70-
assert!(!(NEG_INFINITY..INFINITY).is_empty());
71-
assert!((EPSILON..NAN).is_empty());
72-
assert!((NAN..EPSILON).is_empty());
73-
assert!((NAN..NAN).is_empty());
68+
assert!(!(f32::NEG_INFINITY..f32::INFINITY).is_empty());
69+
assert!((f32::EPSILON..f32::NAN).is_empty());
70+
assert!((f32::NAN..f32::EPSILON).is_empty());
71+
assert!((f32::NAN..f32::NAN).is_empty());
7472

7573
assert!(!(0.0..=10.0).is_empty());
7674
assert!(!(-0.0..=0.0).is_empty());
7775
assert!((10.0..=0.0).is_empty());
7876

79-
assert!(!(NEG_INFINITY..=INFINITY).is_empty());
80-
assert!((EPSILON..=NAN).is_empty());
81-
assert!((NAN..=EPSILON).is_empty());
82-
assert!((NAN..=NAN).is_empty());
77+
assert!(!(f32::NEG_INFINITY..=f32::INFINITY).is_empty());
78+
assert!((f32::EPSILON..=f32::NAN).is_empty());
79+
assert!((f32::NAN..=f32::EPSILON).is_empty());
80+
assert!((f32::NAN..=f32::NAN).is_empty());
8381
}
8482

8583
#[test]

src/libcore/tests/slice.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1108,14 +1108,14 @@ mod slice_index {
11081108

11091109
// note: using 0 specifically ensures that the result of overflowing is 0..0,
11101110
// so that `get` doesn't simply return None for the wrong reason.
1111-
bad: data[0 ..= ::std::usize::MAX];
1111+
bad: data[0 ..= usize::MAX];
11121112
message: "maximum usize";
11131113
}
11141114

11151115
in mod rangetoinclusive_overflow {
11161116
data: [0, 1];
11171117

1118-
bad: data[..= ::std::usize::MAX];
1118+
bad: data[..= usize::MAX];
11191119
message: "maximum usize";
11201120
}
11211121
} // panic_cases!
@@ -1709,7 +1709,7 @@ fn test_is_sorted() {
17091709
assert!(![1, 3, 2].is_sorted());
17101710
assert!([0].is_sorted());
17111711
assert!(empty.is_sorted());
1712-
assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
1712+
assert!(![0.0, 1.0, f32::NAN].is_sorted());
17131713
assert!([-2, -1, 0, 3].is_sorted());
17141714
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
17151715
assert!(!["c", "bb", "aaa"].is_sorted());

src/libcore/tests/time.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn creation() {
1414
#[test]
1515
#[should_panic]
1616
fn new_overflow() {
17-
let _ = Duration::new(::core::u64::MAX, 1_000_000_000);
17+
let _ = Duration::new(u64::MAX, 1_000_000_000);
1818
}
1919

2020
#[test]
@@ -86,7 +86,7 @@ fn checked_add() {
8686
Duration::new(0, 500_000_000).checked_add(Duration::new(0, 500_000_001)),
8787
Some(Duration::new(1, 1))
8888
);
89-
assert_eq!(Duration::new(1, 0).checked_add(Duration::new(::core::u64::MAX, 0)), None);
89+
assert_eq!(Duration::new(1, 0).checked_add(Duration::new(u64::MAX, 0)), None);
9090
}
9191

9292
#[test]
@@ -133,7 +133,7 @@ fn checked_mul() {
133133
assert_eq!(Duration::new(1, 1).checked_mul(3), Some(Duration::new(3, 3)));
134134
assert_eq!(Duration::new(0, 500_000_001).checked_mul(4), Some(Duration::new(2, 4)));
135135
assert_eq!(Duration::new(0, 500_000_001).checked_mul(4000), Some(Duration::new(2000, 4000)));
136-
assert_eq!(Duration::new(::core::u64::MAX - 1, 0).checked_mul(2), None);
136+
assert_eq!(Duration::new(u64::MAX - 1, 0).checked_mul(2), None);
137137
}
138138

139139
#[test]

src/libcore/tests/tuple.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::cmp::Ordering::{Equal, Greater, Less};
2-
use std::f64::NAN;
32

43
#[test]
54
fn test_clone() {
@@ -34,12 +33,12 @@ fn test_partial_ord() {
3433
assert!(big >= small);
3534
assert!(big >= big);
3635

37-
assert!(!((1.0f64, 2.0f64) < (NAN, 3.0)));
38-
assert!(!((1.0f64, 2.0f64) <= (NAN, 3.0)));
39-
assert!(!((1.0f64, 2.0f64) > (NAN, 3.0)));
40-
assert!(!((1.0f64, 2.0f64) >= (NAN, 3.0)));
41-
assert!(((1.0f64, 2.0f64) < (2.0, NAN)));
42-
assert!(!((2.0f64, 2.0f64) < (2.0, NAN)));
36+
assert!(!((1.0f64, 2.0f64) < (f64::NAN, 3.0)));
37+
assert!(!((1.0f64, 2.0f64) <= (f64::NAN, 3.0)));
38+
assert!(!((1.0f64, 2.0f64) > (f64::NAN, 3.0)));
39+
assert!(!((1.0f64, 2.0f64) >= (f64::NAN, 3.0)));
40+
assert!(((1.0f64, 2.0f64) < (2.0, f64::NAN)));
41+
assert!(!((2.0f64, 2.0f64) < (2.0, f64::NAN)));
4342
}
4443

4544
#[test]

src/librustc_codegen_ssa/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
15281528
}
15291529
}
15301530

1531-
pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
1531+
pub const CODEGEN_WORKER_ID: usize = usize::MAX;
15321532

15331533
/// `FatalError` is explicitly not `Send`.
15341534
#[must_use]

src/librustc_codegen_ssa/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
507507
}
508508
}
509509

510-
pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
510+
pub const CODEGEN_WORKER_ID: usize = usize::MAX;
511511

512512
pub fn codegen_crate<B: ExtraBackendMethods>(
513513
backend: B,

src/librustc_errors/emitter.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ impl EmitterWriter {
13611361
let mut multilines = FxHashMap::default();
13621362

13631363
// Get the left-side margin to remove it
1364-
let mut whitespace_margin = std::usize::MAX;
1364+
let mut whitespace_margin = usize::MAX;
13651365
for line_idx in 0..annotated_file.lines.len() {
13661366
let file = annotated_file.file.clone();
13671367
let line = &annotated_file.lines[line_idx];
@@ -1373,19 +1373,19 @@ impl EmitterWriter {
13731373
}
13741374
}
13751375
}
1376-
if whitespace_margin == std::usize::MAX {
1376+
if whitespace_margin == usize::MAX {
13771377
whitespace_margin = 0;
13781378
}
13791379

13801380
// Left-most column any visible span points at.
1381-
let mut span_left_margin = std::usize::MAX;
1381+
let mut span_left_margin = usize::MAX;
13821382
for line in &annotated_file.lines {
13831383
for ann in &line.annotations {
13841384
span_left_margin = min(span_left_margin, ann.start_col);
13851385
span_left_margin = min(span_left_margin, ann.end_col);
13861386
}
13871387
}
1388-
if span_left_margin == std::usize::MAX {
1388+
if span_left_margin == usize::MAX {
13891389
span_left_margin = 0;
13901390
}
13911391

@@ -1421,7 +1421,7 @@ impl EmitterWriter {
14211421
} else {
14221422
termize::dimensions()
14231423
.map(|(w, _)| w.saturating_sub(code_offset))
1424-
.unwrap_or(std::usize::MAX)
1424+
.unwrap_or(usize::MAX)
14251425
};
14261426

14271427
let margin = Margin::new(

src/librustc_index/bit_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<'a, T: Idx> BitIter<'a, T> {
307307
// additional state about whether we have started.
308308
BitIter {
309309
word: 0,
310-
offset: std::usize::MAX - (WORD_BITS - 1),
310+
offset: usize::MAX - (WORD_BITS - 1),
311311
iter: words.iter(),
312312
marker: PhantomData,
313313
}

src/librustc_trait_selection/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ fn receiver_is_dispatchable<'tcx>(
612612
// FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can
613613
// replace this with `dyn Trait`
614614
let unsized_self_ty: Ty<'tcx> =
615-
tcx.mk_ty_param(::std::u32::MAX, Symbol::intern("RustaceansAreAwesome"));
615+
tcx.mk_ty_param(u32::MAX, Symbol::intern("RustaceansAreAwesome"));
616616

617617
// `Receiver[Self => U]`
618618
let unsized_receiver_ty =

src/librustc_trait_selection/traits/select.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3650,11 +3650,7 @@ struct ProvisionalEvaluation {
36503650

36513651
impl<'tcx> Default for ProvisionalEvaluationCache<'tcx> {
36523652
fn default() -> Self {
3653-
Self {
3654-
dfn: Cell::new(0),
3655-
reached_depth: Cell::new(std::usize::MAX),
3656-
map: Default::default(),
3657-
}
3653+
Self { dfn: Cell::new(0), reached_depth: Cell::new(usize::MAX), map: Default::default() }
36583654
}
36593655
}
36603656

@@ -3753,7 +3749,7 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
37533749
op(fresh_trait_ref, eval.result);
37543750
}
37553751

3756-
self.reached_depth.set(std::usize::MAX);
3752+
self.reached_depth.set(usize::MAX);
37573753
}
37583754
}
37593755

src/librustc_typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2620,13 +2620,13 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
26202620
_ => None,
26212621
};
26222622
if let Some(Lit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) = sole_meta_list {
2623-
if *ordinal <= std::usize::MAX as u128 {
2623+
if *ordinal <= usize::MAX as u128 {
26242624
Some(*ordinal as usize)
26252625
} else {
26262626
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
26272627
tcx.sess
26282628
.struct_span_err(attr.span, &msg)
2629-
.note("the value may not exceed `std::usize::MAX`")
2629+
.note("the value may not exceed `usize::MAX`")
26302630
.emit();
26312631
None
26322632
}

src/libserialize/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ use std::num::FpCategory as Fp;
198198
use std::ops::Index;
199199
use std::str::FromStr;
200200
use std::string;
201-
use std::{char, f64, fmt, str};
201+
use std::{char, fmt, str};
202202

203203
use crate::Encodable;
204204

0 commit comments

Comments
 (0)