Skip to content

Commit

Permalink
Rollup merge of #70857 - faern:use-assoc-int-float-consts, r=dtolnay
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Dylan-DPC authored Apr 7, 2020
2 parents 78c64d0 + f7778d3 commit 89d661f
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ unsafe impl<#[may_dangle] T, A: AllocRef> Drop for RawVec<T, A> {

#[inline]
fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> {
if mem::size_of::<usize>() < 8 && alloc_size > core::isize::MAX as usize {
if mem::size_of::<usize>() < 8 && alloc_size > isize::MAX as usize {
Err(CapacityOverflow)
} else {
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/tests/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn trait_object() {

#[test]
fn float_nan_ne() {
let x = Arc::new(std::f32::NAN);
let x = Arc::new(f32::NAN);
assert!(x != x);
assert!(!(x == x));
}
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/tests/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn test_range_large() {

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

assert_eq!(map.range(max..=max).collect::<Vec<_>>(), &[(&max, &0)]);
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/tests/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn trait_object() {

#[test]
fn float_nan_ne() {
let x = Rc::new(std::f32::NAN);
let x = Rc::new(f32::NAN);
assert!(x != x);
assert!(!(x == x));
}
Expand Down
1 change: 0 additions & 1 deletion src/libcore/benches/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::f64;
use test::Bencher;

#[bench]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/benches/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod strategy {

use core::num::flt2dec::MAX_SIG_DIGITS;
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
use std::f64;
use std::io::Write;
use std::vec::Vec;
use test::Bencher;
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ fn test_cmp_by() {
#[test]
fn test_partial_cmp_by() {
use core::cmp::Ordering;
use core::f64;

let f = |x: i32, y: i32| (x * x).partial_cmp(&y);
let xs = || [1, 2, 3, 4].iter().copied();
Expand Down Expand Up @@ -2894,7 +2893,7 @@ fn test_is_sorted() {
assert!(![1, 3, 2].iter().is_sorted());
assert!([0].iter().is_sorted());
assert!(std::iter::empty::<i32>().is_sorted());
assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
assert!(![0.0, 1.0, f32::NAN].iter().is_sorted());
assert!([-2, -1, 0, 3].iter().is_sorted());
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
assert!(!["c", "bb", "aaa"].iter().is_sorted());
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/tests/num/dec2flt/rawfp.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use core::num::dec2flt::rawfp::RawFloat;
use core::num::dec2flt::rawfp::{fp_to_float, next_float, prev_float, round_normal};
use core::num::diy_float::Fp;
use std::f32;
use std::f64;

fn integer_decode(f: f64) -> (u64, i16, i8) {
RawFloat::integer_decode(f)
Expand Down
6 changes: 2 additions & 4 deletions src/libcore/tests/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ test_impl_from! { test_u32f64, u32, f64 }
// Float -> Float
#[test]
fn test_f32f64() {
use core::f32;

let max: f64 = f32::MAX.into();
assert_eq!(max as f32, f32::MAX);
assert!(max.is_normal());
Expand Down Expand Up @@ -704,5 +702,5 @@ macro_rules! test_float {
};
}

test_float!(f32, f32, ::core::f32::INFINITY, ::core::f32::NEG_INFINITY, ::core::f32::NAN);
test_float!(f64, f64, ::core::f64::INFINITY, ::core::f64::NEG_INFINITY, ::core::f64::NAN);
test_float!(f32, f32, f32::INFINITY, f32::NEG_INFINITY, f32::NAN);
test_float!(f64, f64, f64::INFINITY, f64::NEG_INFINITY, f64::NAN);
18 changes: 8 additions & 10 deletions src/libcore/tests/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,23 @@ fn test_range_inclusive() {

#[test]
fn test_range_is_empty() {
use core::f32::*;

assert!(!(0.0..10.0).is_empty());
assert!((-0.0..0.0).is_empty());
assert!((10.0..0.0).is_empty());

assert!(!(NEG_INFINITY..INFINITY).is_empty());
assert!((EPSILON..NAN).is_empty());
assert!((NAN..EPSILON).is_empty());
assert!((NAN..NAN).is_empty());
assert!(!(f32::NEG_INFINITY..f32::INFINITY).is_empty());
assert!((f32::EPSILON..f32::NAN).is_empty());
assert!((f32::NAN..f32::EPSILON).is_empty());
assert!((f32::NAN..f32::NAN).is_empty());

assert!(!(0.0..=10.0).is_empty());
assert!(!(-0.0..=0.0).is_empty());
assert!((10.0..=0.0).is_empty());

assert!(!(NEG_INFINITY..=INFINITY).is_empty());
assert!((EPSILON..=NAN).is_empty());
assert!((NAN..=EPSILON).is_empty());
assert!((NAN..=NAN).is_empty());
assert!(!(f32::NEG_INFINITY..=f32::INFINITY).is_empty());
assert!((f32::EPSILON..=f32::NAN).is_empty());
assert!((f32::NAN..=f32::EPSILON).is_empty());
assert!((f32::NAN..=f32::NAN).is_empty());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,14 +1108,14 @@ mod slice_index {

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

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

bad: data[..= ::std::usize::MAX];
bad: data[..= usize::MAX];
message: "maximum usize";
}
} // panic_cases!
Expand Down Expand Up @@ -1709,7 +1709,7 @@ fn test_is_sorted() {
assert!(![1, 3, 2].is_sorted());
assert!([0].is_sorted());
assert!(empty.is_sorted());
assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
assert!(![0.0, 1.0, f32::NAN].is_sorted());
assert!([-2, -1, 0, 3].is_sorted());
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
assert!(!["c", "bb", "aaa"].is_sorted());
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/tests/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn creation() {
#[test]
#[should_panic]
fn new_overflow() {
let _ = Duration::new(::core::u64::MAX, 1_000_000_000);
let _ = Duration::new(u64::MAX, 1_000_000_000);
}

#[test]
Expand Down Expand Up @@ -86,7 +86,7 @@ fn checked_add() {
Duration::new(0, 500_000_000).checked_add(Duration::new(0, 500_000_001)),
Some(Duration::new(1, 1))
);
assert_eq!(Duration::new(1, 0).checked_add(Duration::new(::core::u64::MAX, 0)), None);
assert_eq!(Duration::new(1, 0).checked_add(Duration::new(u64::MAX, 0)), None);
}

#[test]
Expand Down Expand Up @@ -133,7 +133,7 @@ fn checked_mul() {
assert_eq!(Duration::new(1, 1).checked_mul(3), Some(Duration::new(3, 3)));
assert_eq!(Duration::new(0, 500_000_001).checked_mul(4), Some(Duration::new(2, 4)));
assert_eq!(Duration::new(0, 500_000_001).checked_mul(4000), Some(Duration::new(2000, 4000)));
assert_eq!(Duration::new(::core::u64::MAX - 1, 0).checked_mul(2), None);
assert_eq!(Duration::new(u64::MAX - 1, 0).checked_mul(2), None);
}

#[test]
Expand Down
13 changes: 6 additions & 7 deletions src/libcore/tests/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cmp::Ordering::{Equal, Greater, Less};
use std::f64::NAN;

#[test]
fn test_clone() {
Expand Down Expand Up @@ -34,12 +33,12 @@ fn test_partial_ord() {
assert!(big >= small);
assert!(big >= big);

assert!(!((1.0f64, 2.0f64) < (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) <= (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) > (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) >= (NAN, 3.0)));
assert!(((1.0f64, 2.0f64) < (2.0, NAN)));
assert!(!((2.0f64, 2.0f64) < (2.0, NAN)));
assert!(!((1.0f64, 2.0f64) < (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) <= (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) > (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) >= (f64::NAN, 3.0)));
assert!(((1.0f64, 2.0f64) < (2.0, f64::NAN)));
assert!(!((2.0f64, 2.0f64) < (2.0, f64::NAN)));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
}
}

pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
pub const CODEGEN_WORKER_ID: usize = usize::MAX;

/// `FatalError` is explicitly not `Send`.
#[must_use]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
}
}

pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
pub const CODEGEN_WORKER_ID: usize = usize::MAX;

pub fn codegen_crate<B: ExtraBackendMethods>(
backend: B,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ impl EmitterWriter {
let mut multilines = FxHashMap::default();

// Get the left-side margin to remove it
let mut whitespace_margin = std::usize::MAX;
let mut whitespace_margin = usize::MAX;
for line_idx in 0..annotated_file.lines.len() {
let file = annotated_file.file.clone();
let line = &annotated_file.lines[line_idx];
Expand All @@ -1373,19 +1373,19 @@ impl EmitterWriter {
}
}
}
if whitespace_margin == std::usize::MAX {
if whitespace_margin == usize::MAX {
whitespace_margin = 0;
}

// Left-most column any visible span points at.
let mut span_left_margin = std::usize::MAX;
let mut span_left_margin = usize::MAX;
for line in &annotated_file.lines {
for ann in &line.annotations {
span_left_margin = min(span_left_margin, ann.start_col);
span_left_margin = min(span_left_margin, ann.end_col);
}
}
if span_left_margin == std::usize::MAX {
if span_left_margin == usize::MAX {
span_left_margin = 0;
}

Expand Down Expand Up @@ -1421,7 +1421,7 @@ impl EmitterWriter {
} else {
termize::dimensions()
.map(|(w, _)| w.saturating_sub(code_offset))
.unwrap_or(std::usize::MAX)
.unwrap_or(usize::MAX)
};

let margin = Margin::new(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_index/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a, T: Idx> BitIter<'a, T> {
// additional state about whether we have started.
BitIter {
word: 0,
offset: std::usize::MAX - (WORD_BITS - 1),
offset: usize::MAX - (WORD_BITS - 1),
iter: words.iter(),
marker: PhantomData,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ fn receiver_is_dispatchable<'tcx>(
// FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can
// replace this with `dyn Trait`
let unsized_self_ty: Ty<'tcx> =
tcx.mk_ty_param(::std::u32::MAX, Symbol::intern("RustaceansAreAwesome"));
tcx.mk_ty_param(u32::MAX, Symbol::intern("RustaceansAreAwesome"));

// `Receiver[Self => U]`
let unsized_receiver_ty =
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_trait_selection/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3650,11 +3650,7 @@ struct ProvisionalEvaluation {

impl<'tcx> Default for ProvisionalEvaluationCache<'tcx> {
fn default() -> Self {
Self {
dfn: Cell::new(0),
reached_depth: Cell::new(std::usize::MAX),
map: Default::default(),
}
Self { dfn: Cell::new(0), reached_depth: Cell::new(usize::MAX), map: Default::default() }
}
}

Expand Down Expand Up @@ -3753,7 +3749,7 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
op(fresh_trait_ref, eval.result);
}

self.reached_depth.set(std::usize::MAX);
self.reached_depth.set(usize::MAX);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,13 +2620,13 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
_ => None,
};
if let Some(Lit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) = sole_meta_list {
if *ordinal <= std::usize::MAX as u128 {
if *ordinal <= usize::MAX as u128 {
Some(*ordinal as usize)
} else {
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
tcx.sess
.struct_span_err(attr.span, &msg)
.note("the value may not exceed `std::usize::MAX`")
.note("the value may not exceed `usize::MAX`")
.emit();
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ use std::num::FpCategory as Fp;
use std::ops::Index;
use std::str::FromStr;
use std::string;
use std::{char, f64, fmt, str};
use std::{char, fmt, str};

use crate::Encodable;

Expand Down
Loading

0 comments on commit 89d661f

Please sign in to comment.