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
This commit is contained in:
Dylan DPC 2020-04-07 14:46:59 +02:00 committed by GitHub
commit 89d661f15d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 52 additions and 68 deletions

View File

@ -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(())

View File

@ -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));
}

View File

@ -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)]);

View File

@ -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));
}

View File

@ -1,4 +1,3 @@
use std::f64;
use test::Bencher;
#[bench]

View File

@ -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;

View File

@ -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();
@ -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());

View File

@ -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)

View File

@ -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());
@ -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);

View File

@ -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]

View File

@ -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!
@ -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());

View File

@ -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]
@ -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]
@ -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]

View File

@ -1,5 +1,4 @@
use std::cmp::Ordering::{Equal, Greater, Less};
use std::f64::NAN;
#[test]
fn test_clone() {
@ -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]

View File

@ -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]

View File

@ -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,

View File

@ -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];
@ -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;
}
@ -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(

View File

@ -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,
}

View File

@ -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 =

View File

@ -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() }
}
}
@ -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);
}
}

View File

@ -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
}

View File

@ -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;

View File

@ -53,7 +53,7 @@ fn test_unit() {
#[test]
fn test_u8() {
let mut vec = vec![];
for i in ::std::u8::MIN..::std::u8::MAX {
for i in u8::MIN..u8::MAX {
vec.push(i);
}
check_round_trip(vec);
@ -61,30 +61,30 @@ fn test_u8() {
#[test]
fn test_u16() {
for i in ::std::u16::MIN..::std::u16::MAX {
for i in u16::MIN..u16::MAX {
check_round_trip(vec![1, 2, 3, i, i, i]);
}
}
#[test]
fn test_u32() {
check_round_trip(vec![1, 2, 3, ::std::u32::MIN, 0, 1, ::std::u32::MAX, 2, 1]);
check_round_trip(vec![1, 2, 3, u32::MIN, 0, 1, u32::MAX, 2, 1]);
}
#[test]
fn test_u64() {
check_round_trip(vec![1, 2, 3, ::std::u64::MIN, 0, 1, ::std::u64::MAX, 2, 1]);
check_round_trip(vec![1, 2, 3, u64::MIN, 0, 1, u64::MAX, 2, 1]);
}
#[test]
fn test_usize() {
check_round_trip(vec![1, 2, 3, ::std::usize::MIN, 0, 1, ::std::usize::MAX, 2, 1]);
check_round_trip(vec![1, 2, 3, usize::MIN, 0, 1, usize::MAX, 2, 1]);
}
#[test]
fn test_i8() {
let mut vec = vec![];
for i in ::std::i8::MIN..::std::i8::MAX {
for i in i8::MIN..i8::MAX {
vec.push(i);
}
check_round_trip(vec);
@ -92,24 +92,24 @@ fn test_i8() {
#[test]
fn test_i16() {
for i in ::std::i16::MIN..::std::i16::MAX {
for i in i16::MIN..i16::MAX {
check_round_trip(vec![-1, 2, -3, i, i, i, 2]);
}
}
#[test]
fn test_i32() {
check_round_trip(vec![-1, 2, -3, ::std::i32::MIN, 0, 1, ::std::i32::MAX, 2, 1]);
check_round_trip(vec![-1, 2, -3, i32::MIN, 0, 1, i32::MAX, 2, 1]);
}
#[test]
fn test_i64() {
check_round_trip(vec![-1, 2, -3, ::std::i64::MIN, 0, 1, ::std::i64::MAX, 2, 1]);
check_round_trip(vec![-1, 2, -3, i64::MIN, 0, 1, i64::MAX, 2, 1]);
}
#[test]
fn test_isize() {
check_round_trip(vec![-1, 2, -3, ::std::isize::MIN, 0, 1, ::std::isize::MAX, 2, 1]);
check_round_trip(vec![-1, 2, -3, isize::MIN, 0, 1, isize::MAX, 2, 1]);
}
#[test]

View File

@ -2617,7 +2617,6 @@ mod test_map {
use crate::cell::RefCell;
use rand::{thread_rng, Rng};
use realstd::collections::TryReserveError::*;
use realstd::usize;
// https://github.com/rust-lang/rust/issues/62301
fn _assert_hashmap_is_unwind_safe() {

View File

@ -2,7 +2,6 @@ use super::*;
extern crate test;
use self::test::test::Bencher;
use std::f64;
use std::io;
use std::io::prelude::*;

View File

@ -12,7 +12,7 @@ error: ordinal value in `link_ordinal` is too large: `18446744073709551616`
LL | #[link_ordinal(18446744073709551616)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the value may not exceed `std::usize::MAX`
= note: the value may not exceed `usize::MAX`
error: aborting due to previous error